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

@@ -4,23 +4,42 @@ import (
"os"
"os/exec"
"path/filepath"
socketio "github.com/googollee/go-socket.io"
)
// ---- Run npm build ----
func runNpmV2Build() error {
cmd := exec.Command("npm", "run", "newBuild")
if os.Getenv("RUNNING_IN_DOCKER") == "true" {
cmd.Dir = "/app"
}else {
// Go three directories up from the current working directory
cwd, err := os.Getwd()
if err != nil {
return err
}
dir := filepath.Join(cwd, "..", "..", "lstV2")
cmd.Dir = dir
}
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
return cmd.Run()
}
func runNpmV2Build(server *socketio.Server) error {
cmd := exec.Command("npm", "run", "newBuild")
if os.Getenv("RUNNING_IN_DOCKER") == "true" {
cmd.Dir = "/app"
} else {
// Go three directories up from the current working directory
cwd, err := os.Getwd()
if err != nil {
return err
}
dir := filepath.Join(cwd, "..", "..", "lstV2")
cmd.Dir = dir
}
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
}