refactor(controller): converted to socket.io

This commit is contained in:
2025-09-06 17:01:19 -05:00
parent d3120c828d
commit 750e6948b6
4 changed files with 170 additions and 57 deletions

View File

@@ -3,15 +3,33 @@ package main
import (
"os"
"os/exec"
socketio "github.com/googollee/go-socket.io"
)
// ---- Run npm build ----
func runNpmBuild() error {
cmd := exec.Command("npm", "run", "build")
if os.Getenv("RUNNING_IN_DOCKER") == "true" {
cmd.Dir = "/app"
}
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
// runNpmBuild runs npm build and streams logs into the "build" room
func runNpmBuild(server *socketio.Server) error {
cmd := exec.Command("npm", "run", "build")
if os.Getenv("RUNNING_IN_DOCKER") == "true" {
cmd.Dir = "/app"
}
stdout, err := cmd.StdoutPipe()
if err != nil {
return err
}
stderr, err := cmd.StderrPipe()
if err != nil {
return err
}
if err := cmd.Start(); err != nil {
return err
}
// Launch goroutines to forward output
go streamOutput(stdout, server, "build")
go streamOutput(stderr, server, "build")
return cmd.Wait() // Wait until process finishes
}