Compare commits
6 Commits
945048f43e
...
5f4d9043c3
| Author | SHA1 | Date | |
|---|---|---|---|
| 5f4d9043c3 | |||
| 2d7e0ab909 | |||
| 301f0339c5 | |||
| 71dcbf814b | |||
| 750e6948b6 | |||
| d3120c828d |
@@ -34,4 +34,7 @@ MLAN1_NETWORK=192.168.193.0/24
|
||||
MLAN1_GATEWAY=192.168.193.252
|
||||
|
||||
# admin
|
||||
# used for discord alerts
|
||||
WEBHOOK_URL
|
||||
# used to keep the build folder clean
|
||||
MAX_BUILDS
|
||||
4
.include
4
.include
@@ -9,5 +9,7 @@ README.md
|
||||
CHANGELOG.md
|
||||
package.json
|
||||
package-lock.json
|
||||
controller/lst_ctl.exe
|
||||
lstV2
|
||||
lang
|
||||
drizzle.config.ts
|
||||
tsconfig.json
|
||||
@@ -3,16 +3,16 @@ import morgan from "morgan";
|
||||
import { createServer } from "http";
|
||||
import { setupRoutes } from "./internal/routerHandler/routeHandler.js";
|
||||
import { printers } from "./internal/ocp/printers/printers.js";
|
||||
import path, { dirname, join } from "path";
|
||||
import { dirname, join } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import { db } from "./pkg/db/db.js";
|
||||
import { settings, type Setting } from "./pkg/db/schema/settings.js";
|
||||
import { settings } from "./pkg/db/schema/settings.js";
|
||||
import { validateEnv } from "./pkg/utils/envValidator.js";
|
||||
import { createLogger } from "./pkg/logger/logger.js";
|
||||
import { returnFunc } from "./pkg/utils/return.js";
|
||||
import { closePool, initializeProdPool } from "./pkg/prodSql/prodSqlConnect.js";
|
||||
import { initializeProdPool } from "./pkg/prodSql/prodSqlConnect.js";
|
||||
import { tryCatch } from "./pkg/utils/tryCatch.js";
|
||||
import os, { hostname } from "os";
|
||||
import os from "os";
|
||||
import { sendNotify } from "./pkg/utils/notify.js";
|
||||
|
||||
const main = async () => {
|
||||
@@ -24,10 +24,6 @@ const main = async () => {
|
||||
// base path
|
||||
let basePath: string = "";
|
||||
|
||||
if (process.env.NODE_ENV?.trim() !== "production") {
|
||||
basePath = "/lst";
|
||||
}
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
@@ -47,14 +43,14 @@ const main = async () => {
|
||||
|
||||
if (res.data.length === 0) {
|
||||
//return
|
||||
returnFunc({
|
||||
success: false,
|
||||
module: "system",
|
||||
level: "fatal",
|
||||
message: `This seems to be the first time you have started the app please validate the settings have been intiated`,
|
||||
notify: false,
|
||||
data: [],
|
||||
});
|
||||
// returnFunc({
|
||||
// success: false,
|
||||
// module: "system",
|
||||
// level: "fatal",
|
||||
// message: `This seems to be the first time you have started the app please validate the settings have been intiated`,
|
||||
// notify: false,
|
||||
// data: [],
|
||||
// });
|
||||
}
|
||||
|
||||
// connect to the prod sql
|
||||
@@ -64,22 +60,22 @@ const main = async () => {
|
||||
const app = express();
|
||||
|
||||
// global middleware
|
||||
app.use(express.static(path.join(__dirname, "../lstDocs/build")));
|
||||
app.use(express.static(path.join(__dirname, "../frontend/dist")));
|
||||
app.use(express.json());
|
||||
|
||||
// global env that run only in dev
|
||||
if (process.env.NODE_ENV?.trim() !== "production") {
|
||||
app.use(morgan("tiny"));
|
||||
basePath = "/lst";
|
||||
}
|
||||
|
||||
// docs and api stuff
|
||||
app.use(
|
||||
basePath + "/d",
|
||||
express.static(join(__dirname, "../lstDocs/build"))
|
||||
express.static(join(__dirname, "../../lstDocs/build"))
|
||||
);
|
||||
app.use(
|
||||
basePath + "/app",
|
||||
express.static(join(__dirname, "../frontend/dist"))
|
||||
express.static(join(__dirname, "../../frontend/dist"))
|
||||
);
|
||||
|
||||
// register app
|
||||
@@ -129,7 +125,7 @@ const main = async () => {
|
||||
});
|
||||
}
|
||||
|
||||
process.exit(1);
|
||||
//process.exit(1);
|
||||
});
|
||||
|
||||
// setInterval(() => {
|
||||
@@ -145,12 +141,3 @@ const main = async () => {
|
||||
};
|
||||
|
||||
main();
|
||||
|
||||
// .catch((err) => {
|
||||
// const log = createLogger({ module: "system", subModule: "main" });
|
||||
// log.fatal(
|
||||
// { notify: true },
|
||||
// "There was a crash that occured and caused the app to restart."
|
||||
// );
|
||||
// process.exit(1);
|
||||
// });
|
||||
|
||||
@@ -3,15 +3,33 @@ package main
|
||||
import (
|
||||
"os"
|
||||
"os/exec"
|
||||
|
||||
socketio "github.com/googollee/go-socket.io"
|
||||
)
|
||||
|
||||
// ---- Run npm build ----
|
||||
func runNpmBuild() error {
|
||||
// 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"
|
||||
}
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
return cmd.Run()
|
||||
|
||||
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
|
||||
}
|
||||
89
controller/build_channel.go
Normal file
89
controller/build_channel.go
Normal file
@@ -0,0 +1,89 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
socketio "github.com/googollee/go-socket.io"
|
||||
)
|
||||
|
||||
func registerBuildChannel(server *socketio.Server) {
|
||||
// Example: When clients join "build" namespace or room
|
||||
server.OnEvent("/", "subscribe:build", func(s socketio.Conn) {
|
||||
s.Join("build")
|
||||
s.Emit("buildlogs", "👋 Connected to build channel") // this is where all the messages are actually sent to
|
||||
|
||||
})
|
||||
|
||||
// update channel events
|
||||
server.OnEvent("/", "build", func(s socketio.Conn, target string) {
|
||||
fmt.Println("🔨 Build triggered:", target)
|
||||
|
||||
go func() {
|
||||
host, err := os.Hostname()
|
||||
if err != nil {
|
||||
server.BroadcastToRoom("/", "build", "buildlogs", "Could not retrieve hostname")
|
||||
return
|
||||
}
|
||||
|
||||
if strings.Contains(host, "VMS") || strings.Contains(host, "vms") {
|
||||
server.BroadcastToRoom("/", "build", "buildlogs", "You are not allowed to run the build on a production server")
|
||||
return
|
||||
}
|
||||
|
||||
server.BroadcastToRoom("/", "build", "buildlogs", "🔨 Starting build: Old App")
|
||||
if err := runNpmV2Build(server); err != nil {
|
||||
server.BroadcastToRoom("/", "build", "buildlogs", fmt.Sprintf("❌ Build failed: %v", err))
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
server.BroadcastToRoom("/", "build", "buildlogs", "🔨 Starting build: App")
|
||||
if err := runNpmBuild(server); err != nil {
|
||||
server.BroadcastToRoom("/", "build", "buildlogs", fmt.Sprintf("❌ Build failed: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
server.BroadcastToRoom("/", "build", "buildlogs", "Zipping the app up")
|
||||
buildNum, err := bumpBuild()
|
||||
if err != nil {
|
||||
server.BroadcastToRoom("/", "build", "buildlogs", fmt.Sprintf("failed updating build counter, details: %v", err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
// run the zip
|
||||
includes, _ := loadIncludePatterns("../.include")
|
||||
|
||||
// Name the archive after build number if available
|
||||
data, _ := os.ReadFile("../.build")
|
||||
buildNum1 := strings.TrimSpace(string(data))
|
||||
if buildNum1 == "" {
|
||||
buildNum1 = "0"
|
||||
}
|
||||
|
||||
buildDir, err := getBuildDir()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
server.BroadcastToRoom("/", "build", "buildlogs", fmt.Sprintf("Build dir error: %v", err))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
||||
server.BroadcastToRoom("/", "build", "buildlogs", fmt.Sprintf("Build dir error: %v", err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
zipPath := filepath.Join(buildDir, fmt.Sprintf("release-%d.zip", buildNum))
|
||||
|
||||
if err := zipProject(server, "..", zipPath, includes); err != nil {
|
||||
server.BroadcastToRoom("/", "build", "buildlogs", fmt.Sprintf("Build zip error: %v", err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
server.BroadcastToRoom("/", "build", "buildlogs", fmt.Sprintf("✅ Build finished successfully, current build: %v", buildNum))
|
||||
}()
|
||||
})
|
||||
}
|
||||
@@ -4,14 +4,16 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
socketio "github.com/googollee/go-socket.io"
|
||||
)
|
||||
|
||||
// ---- Run npm build ----
|
||||
func runNpmV2Build() error {
|
||||
func runNpmV2Build(server *socketio.Server) error {
|
||||
cmd := exec.Command("npm", "run", "newBuild")
|
||||
if os.Getenv("RUNNING_IN_DOCKER") == "true" {
|
||||
cmd.Dir = "/app"
|
||||
}else {
|
||||
} else {
|
||||
// Go three directories up from the current working directory
|
||||
cwd, err := os.Getwd()
|
||||
if err != nil {
|
||||
@@ -20,7 +22,24 @@ func runNpmV2Build() error {
|
||||
dir := filepath.Join(cwd, "..", "..", "lstV2")
|
||||
cmd.Dir = dir
|
||||
}
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
return cmd.Run()
|
||||
|
||||
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
|
||||
|
||||
}
|
||||
125
controller/copy_build.go
Normal file
125
controller/copy_build.go
Normal file
@@ -0,0 +1,125 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
|
||||
socketio "github.com/googollee/go-socket.io"
|
||||
)
|
||||
|
||||
func copyBuild(server *socketio.Server, plant string) {
|
||||
// Load from environment in real-life code!
|
||||
user := os.Getenv("ADM_USER")
|
||||
pass := os.Getenv("ADM_PASS")
|
||||
|
||||
// latest build
|
||||
latestbuild := lastestBuild()
|
||||
src := latestbuild
|
||||
plantServer := fmt.Sprintf("\\\\%v\\e$\\lst", plant)
|
||||
|
||||
// Build PowerShell
|
||||
psScript := fmt.Sprintf(`
|
||||
$secPass = ConvertTo-SecureString '%s' -AsPlainText -Force
|
||||
$cred = New-Object System.Management.Automation.PSCredential ('%s', $secPass)
|
||||
|
||||
# Clean up any previous mapped drive
|
||||
Get-PSDrive -Name "z" -ErrorAction SilentlyContinue | Remove-PSDrive -Force
|
||||
|
||||
try {
|
||||
# Map a temporary drive "z:" to the destination UNC with creds
|
||||
New-PSDrive -Name "z" -PSProvider FileSystem -Root '%s' -Credential $cred | Out-Null
|
||||
|
||||
# Ensure target dir exists on server
|
||||
if (-not (Test-Path -Path '%s')) {
|
||||
New-Item -ItemType Directory -Path '%s' -Force | Out-Null
|
||||
}
|
||||
|
||||
Write-Host "Starting to copy files to the server"
|
||||
Copy-Item -Path '%s' -Destination "z:\" -Force
|
||||
|
||||
#Write-Host "Copy successful completed"
|
||||
}
|
||||
catch {
|
||||
Write-Host "Error: $_"
|
||||
}
|
||||
finally {
|
||||
# Always remove the drive
|
||||
if (Get-PSDrive -Name "z" -ErrorAction SilentlyContinue) {
|
||||
Remove-PSDrive -Name "z"
|
||||
}
|
||||
}
|
||||
`, pass, user, plantServer, plantServer, plantServer, src)
|
||||
|
||||
msg := fmt.Sprintf("Getting ready to copy %s to %s", src, plantServer)
|
||||
fmt.Printf("Getting ready to copy %s to %s", src, plant)
|
||||
|
||||
server.BroadcastToRoom("/", "update", "updateLogs", msg)
|
||||
|
||||
cmd := exec.Command("powershell", "-NoProfile", "-NonInteractive", "-Command", psScript)
|
||||
|
||||
stdout, _ := cmd.StdoutPipe() // writes to the system what the powershell script is doing
|
||||
stderr, _ := cmd.StderrPipe()
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
server.BroadcastToRoom("/", "update", "updateLogs", fmt.Sprintf("❌ Failed to start copy: %v", err))
|
||||
fmt.Printf("❌ Failed to start copy: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
// Forward stdout + stderr live
|
||||
go streamOutput(stdout, server, "update")
|
||||
go streamOutput(stderr, server, "update")
|
||||
|
||||
if err := cmd.Wait(); err != nil {
|
||||
server.BroadcastToRoom("/", "update", "updateLogs", fmt.Sprintf("❌ Copy process failed: %v", err))
|
||||
return
|
||||
}
|
||||
|
||||
server.BroadcastToRoom("/", "update", "updateLogs", fmt.Sprintf("✅ Copy to %s successful", plant))
|
||||
}
|
||||
|
||||
func lastestBuild() string {
|
||||
// Path to your build folder
|
||||
buildDir := "../builds"
|
||||
|
||||
entries, err := os.ReadDir(buildDir)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
// Regex to match release-1234.zip
|
||||
re := regexp.MustCompile(`^release-(\d+)\.zip$`)
|
||||
|
||||
var builds []int
|
||||
files := make(map[int]string)
|
||||
|
||||
for _, entry := range entries {
|
||||
if entry.IsDir() {
|
||||
continue
|
||||
}
|
||||
name := entry.Name()
|
||||
match := re.FindStringSubmatch(name)
|
||||
if match != nil {
|
||||
num, _ := strconv.Atoi(match[1])
|
||||
builds = append(builds, num)
|
||||
files[num] = filepath.Join(buildDir, name)
|
||||
}
|
||||
}
|
||||
|
||||
if len(builds) == 0 {
|
||||
log.Fatal("No release zip files found")
|
||||
}
|
||||
|
||||
// Sort build numbers ascending
|
||||
sort.Ints(builds)
|
||||
latest := builds[len(builds)-1]
|
||||
latestFile := files[latest]
|
||||
|
||||
return latestFile
|
||||
}
|
||||
@@ -2,7 +2,11 @@ module lst.net
|
||||
|
||||
go 1.24.3
|
||||
|
||||
require github.com/gin-gonic/gin v1.10.1
|
||||
require (
|
||||
github.com/gin-gonic/gin v1.10.1
|
||||
github.com/googollee/go-socket.io v1.7.0
|
||||
github.com/joho/godotenv v1.5.1
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/bytedance/sonic v1.11.6 // indirect
|
||||
@@ -10,11 +14,16 @@ require (
|
||||
github.com/cloudwego/base64x v0.1.4 // indirect
|
||||
github.com/cloudwego/iasm v0.2.0 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||
github.com/geoffgarside/ber v1.1.0 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.20.0 // indirect
|
||||
github.com/goccy/go-json v0.10.2 // indirect
|
||||
github.com/gofrs/uuid v4.0.0+incompatible // indirect
|
||||
github.com/gomodule/redigo v1.8.4 // indirect
|
||||
github.com/gorilla/websocket v1.4.2 // indirect
|
||||
github.com/hirochachacha/go-smb2 v1.1.0 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
|
||||
github.com/leodido/go-urn v1.4.0 // indirect
|
||||
|
||||
@@ -10,6 +10,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
|
||||
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
|
||||
github.com/geoffgarside/ber v1.1.0 h1:qTmFG4jJbwiSzSXoNJeHcOprVzZ8Ulde2Rrrifu5U9w=
|
||||
github.com/geoffgarside/ber v1.1.0/go.mod h1:jVPKeCbj6MvQZhwLYsGwaGI52oUorHoHKNecGT85ZCc=
|
||||
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
|
||||
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
|
||||
github.com/gin-gonic/gin v1.10.1 h1:T0ujvqyCSqRopADpgPgiTT63DUQVSfojyME59Ei63pQ=
|
||||
@@ -22,7 +24,19 @@ github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBEx
|
||||
github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM=
|
||||
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
|
||||
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
|
||||
github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw=
|
||||
github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
||||
github.com/gomodule/redigo v1.8.4 h1:Z5JUg94HMTR1XpwBaSH4vq3+PNSIykBLxMdglbw10gg=
|
||||
github.com/gomodule/redigo v1.8.4/go.mod h1:P9dn9mFrCBvWhGE1wpxx6fgq7BAeLBk+UUUzlpkBYO0=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
github.com/googollee/go-socket.io v1.7.0 h1:ODcQSAvVIPvKozXtUGuJDV3pLwdpBLDs1Uoq/QHIlY8=
|
||||
github.com/googollee/go-socket.io v1.7.0/go.mod h1:0vGP8/dXR9SZUMMD4+xxaGo/lohOw3YWMh2WRiWeKxg=
|
||||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/hirochachacha/go-smb2 v1.1.0 h1:b6hs9qKIql9eVXAiN0M2wSFY5xnhbHAQoCwRKbaRTZI=
|
||||
github.com/hirochachacha/go-smb2 v1.1.0/go.mod h1:8F1A4d5EZzrGu5R7PU163UcMRDJQl4FtcxjBfsY8TZE=
|
||||
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
|
||||
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
|
||||
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
|
||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||
github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
|
||||
@@ -46,6 +60,7 @@ github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSS
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
@@ -59,19 +74,27 @@ github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZ
|
||||
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
|
||||
golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc=
|
||||
golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200728195943-123391ffb6de/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.23.0 h1:dIJU/v2J8Mdglj/8rJ6UUOM3Zc9zLZxVZwwxMooUSAI=
|
||||
golang.org/x/crypto v0.23.0/go.mod h1:CKFgDieR+mRhux2Lsu27y0fO304Db0wZe70UKqHu0v8=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.25.0 h1:d/OCCoBEUq33pjydKrGQhw7IlUPI2Oylr+8qLx49kac=
|
||||
golang.org/x/net v0.25.0/go.mod h1:JkAGAh7GEvH74S6FOH42FLoXpXbE/aqXSrIQjXgsiwM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
|
||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk=
|
||||
golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
|
||||
google.golang.org/protobuf v1.34.1 h1:9ddQBjfCyZPOHPUiPxpYESBLc+T8P3E+Vo4IbKZgFWg=
|
||||
google.golang.org/protobuf v1.34.1/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
||||
167
controller/index.html
Normal file
167
controller/index.html
Normal file
@@ -0,0 +1,167 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Go Socket.IO Logs Test</title>
|
||||
<!-- Socket.IO v2 client -->
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.3.0/socket.io.js"></script>
|
||||
<style>
|
||||
body {
|
||||
font-family: monospace;
|
||||
background: #111;
|
||||
color: #eee;
|
||||
}
|
||||
#controls {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
#logWindow {
|
||||
border: 1px solid #444;
|
||||
background: #000;
|
||||
padding: 10px;
|
||||
width: 100%;
|
||||
height: 400px;
|
||||
overflow-y: auto;
|
||||
white-space: pre-wrap;
|
||||
font-size: 14px;
|
||||
}
|
||||
.info {
|
||||
color: #0f0;
|
||||
}
|
||||
.log {
|
||||
color: #0af;
|
||||
}
|
||||
.error {
|
||||
color: #f33;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h2>Go Socket.IO Log Viewer</h2>
|
||||
|
||||
<div id="controls">
|
||||
<button id="btnLogs">Subscribe Logs</button>
|
||||
<button id="btnLeaveLogs">Leave Logs</button>
|
||||
<button id="btnErrors">Subscribe Errors</button>
|
||||
<button id="btnLeaveErrors">Leave Errors</button>
|
||||
<button id="btnSubscribeBuild">Subscribe Build</button>
|
||||
<button id="btnUnsubscribeBuild">Leave Build</button>
|
||||
<button id="btnBuildApp">Build</button>
|
||||
<!-- update buttons: copy -->
|
||||
<button id="btnSubscribeUpdate">Subscribe Update</button>
|
||||
<button id="btnUnsubscribeUpdate">Leave Update</button>
|
||||
<div>
|
||||
<form onsubmit="return false;">
|
||||
<input
|
||||
type="text"
|
||||
id="myInput"
|
||||
placeholder="Type something here"
|
||||
/>
|
||||
<button type="button" id="btnCopyLatest">Send</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="logWindow"></div>
|
||||
|
||||
<script>
|
||||
// ✅ Define socket in global scope
|
||||
const socket = io("http://localhost:8000");
|
||||
|
||||
// log window reference
|
||||
const logWindow = document.getElementById("logWindow");
|
||||
|
||||
function logMessage(type, msg) {
|
||||
const entry = document.createElement("div");
|
||||
entry.textContent = `${new Date().toLocaleTimeString()} | ${msg}`;
|
||||
entry.className = type;
|
||||
logWindow.appendChild(entry);
|
||||
logWindow.scrollTop = logWindow.scrollHeight; // auto-scroll
|
||||
}
|
||||
|
||||
// connection events
|
||||
|
||||
// wire up buttons *after* socket is defined
|
||||
document.getElementById("btnLogs").onclick = () => {
|
||||
socket.emit("subscribe:logs");
|
||||
logMessage("info", "Subscribed to logs");
|
||||
};
|
||||
|
||||
document.getElementById("btnErrors").onclick = () => {
|
||||
socket.emit("subscribe:errors");
|
||||
logMessage("info", "Subscribed to errors");
|
||||
};
|
||||
|
||||
document.getElementById("btnLeaveLogs").onclick = () => {
|
||||
socket.emit("unsubscribe:logs");
|
||||
logMessage("info", "👋 Left logs channel");
|
||||
};
|
||||
|
||||
document.getElementById("btnLeaveErrors").onclick = () => {
|
||||
socket.emit("unsubscribe:errors");
|
||||
logMessage("info", "👋 Left errors channel");
|
||||
};
|
||||
|
||||
document.getElementById("btnSubscribeBuild").onclick = () => {
|
||||
socket.emit("subscribe:build");
|
||||
logMessage("info", "📺 Subscribed to build");
|
||||
};
|
||||
|
||||
document.getElementById("btnUnsubscribeBuild").onclick = () => {
|
||||
socket.emit("unsubscribe:build");
|
||||
logMessage("info", "👋 Left build room");
|
||||
};
|
||||
|
||||
document.getElementById("btnBuildApp").onclick = () => {
|
||||
socket.emit("build", "LST App"); // "frontend" = payload target
|
||||
logMessage("info", "🚀 Build triggered");
|
||||
};
|
||||
|
||||
// update stuff
|
||||
document.getElementById("btnSubscribeUpdate").onclick = () => {
|
||||
socket.emit("subscribe:update");
|
||||
logMessage("info", "📺 Subscribed to update");
|
||||
};
|
||||
|
||||
document.getElementById("btnUnsubscribeUpdate").onclick = () => {
|
||||
socket.emit("unsubscribe:update");
|
||||
logMessage("info", "👋 Left update room");
|
||||
};
|
||||
|
||||
// document.getElementById("btnCopyLatest").onclick = () => {
|
||||
// socket.emit("update", "usmcd1vms036"); // "frontend" = payload target
|
||||
// logMessage("info", "Copying to USCMD1VMS036");
|
||||
// };
|
||||
|
||||
window.onload = () => {
|
||||
const input = document.getElementById("myInput");
|
||||
const button = document.getElementById("btnCopyLatest");
|
||||
|
||||
button.onclick = () => {
|
||||
const fromMyInput = input.value;
|
||||
if (!fromMyInput) return;
|
||||
|
||||
// Emit to backend (adjust event name as required)
|
||||
socket.emit("update", fromMyInput);
|
||||
|
||||
// You can define your own logMessage function
|
||||
logMessage("info", `Copying to ${fromMyInput}`);
|
||||
|
||||
input.value = "";
|
||||
|
||||
input.focus();
|
||||
};
|
||||
};
|
||||
|
||||
socket.on("logs", (msg) => logMessage("logs", msg));
|
||||
socket.on("errors", (msg) => logMessage("errors", msg));
|
||||
socket.on("buildlogs", (msg) => logMessage("build", msg));
|
||||
socket.on("updateLogs", (msg) => logMessage("update", msg));
|
||||
socket.on("connect", () => {
|
||||
logMessage("info", "✅ Connected to server");
|
||||
});
|
||||
|
||||
socket.on("disconnect", () => {
|
||||
logMessage("info", "❌ Disconnected");
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -3,89 +3,117 @@ package main
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
socketio "github.com/googollee/go-socket.io"
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
func main() {
|
||||
r := gin.Default()
|
||||
|
||||
// POST /build -> run npm build + increment .build
|
||||
r.POST("/build", func(c *gin.Context) {
|
||||
host, err := os.Hostname()
|
||||
err := godotenv.Load("../.env")
|
||||
if err != nil {
|
||||
c.JSON(500, gin.H{"error": "Could not retrieve hostname"})
|
||||
return
|
||||
//log := logger.New()
|
||||
//log.Info("Warning: .env file not found (ok in Docker/production)", "system", map[string]interface{}{})
|
||||
fmt.Println("Warning: .env file not found")
|
||||
}
|
||||
server := socketio.NewServer(nil)
|
||||
|
||||
log.Println(host)
|
||||
if strings.Contains(host, "VMS") || strings.Contains(host, "vms") {
|
||||
c.JSON(500, gin.H{"error": "You are not allowed to run the build on a production server"})
|
||||
return
|
||||
}
|
||||
// run the old builder first this will be removed once we switch fully over here and shut down the old version
|
||||
if err := runNpmV2Build(); err != nil {
|
||||
c.JSON(500, gin.H{"error": "npm build failed on lstV2", "details": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
// the new builder
|
||||
if err := runNpmBuild(); err != nil {
|
||||
c.JSON(500, gin.H{"error": "npm build failed", "details": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
buildNum, err := bumpBuild()
|
||||
if err != nil {
|
||||
c.JSON(500, gin.H{"error": "failed updating build counter", "details": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
// run the zip
|
||||
includes, _ := loadIncludePatterns("../.include")
|
||||
|
||||
// Name the archive after build number if available
|
||||
data, _ := os.ReadFile("../.build")
|
||||
buildNum1 := strings.TrimSpace(string(data))
|
||||
if buildNum1 == "" {
|
||||
buildNum1 = "0"
|
||||
}
|
||||
|
||||
buildDir, err := getBuildDir()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
//buildDir, err := ensureBuildDir("../builds")
|
||||
if err != nil {
|
||||
c.JSON(500, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
zipPath := filepath.Join(buildDir, fmt.Sprintf("release-%d.zip", buildNum))
|
||||
|
||||
if err := zipProject("..", zipPath, includes); err != nil {
|
||||
c.JSON(500, gin.H{"error": err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(200, gin.H{
|
||||
"message": "build successful",
|
||||
"build": buildNum,
|
||||
})
|
||||
server.OnConnect("/", func(s socketio.Conn) error {
|
||||
fmt.Println("✅ Client connected:", s.ID())
|
||||
return nil
|
||||
})
|
||||
|
||||
// GET /version -> read current build version
|
||||
r.GET("/version", func(c *gin.Context) {
|
||||
data, err := os.ReadFile("../.build")
|
||||
if err != nil {
|
||||
c.JSON(404, gin.H{"error": "no build info"})
|
||||
return
|
||||
}
|
||||
c.JSON(200, gin.H{"build": strings.TrimSpace(string(data))})
|
||||
// ROOM SUBSCRIBE
|
||||
server.OnEvent("/", "subscribe:logs", func(s socketio.Conn) {
|
||||
s.Join("logs")
|
||||
fmt.Println("📺", s.ID(), "joined logs")
|
||||
s.Emit("info", "Subscribed to logs")
|
||||
})
|
||||
|
||||
r.Run(":8080") // serve API
|
||||
server.OnEvent("/", "unsubscribe:logs", func(s socketio.Conn) {
|
||||
s.Leave("logs")
|
||||
fmt.Println("👋", s.ID(), "left logs")
|
||||
s.Emit("info", "Unsubscribed from logs")
|
||||
})
|
||||
|
||||
server.OnEvent("/", "subscribe:errors", func(s socketio.Conn) {
|
||||
s.Join("errors")
|
||||
fmt.Println("📺", s.ID(), "joined errors")
|
||||
s.Emit("info", "Subscribed to errors")
|
||||
})
|
||||
|
||||
server.OnEvent("/", "unsubscribe:errors", func(s socketio.Conn) {
|
||||
s.Leave("errors")
|
||||
fmt.Println("👋", s.ID(), "left errors")
|
||||
s.Emit("info", "Unsubscribed from errors")
|
||||
})
|
||||
|
||||
server.OnDisconnect("/", func(s socketio.Conn, reason string) {
|
||||
fmt.Println("❌ Client disconnected:", s.ID(), reason)
|
||||
})
|
||||
|
||||
// build stuff
|
||||
// Subscribe to build room
|
||||
server.OnEvent("/", "subscribe:build", func(s socketio.Conn) {
|
||||
s.Join("build")
|
||||
fmt.Println("📺", s.ID(), "joined build room")
|
||||
s.Emit("info", "Subscribed to build log room")
|
||||
})
|
||||
|
||||
server.OnEvent("/", "unsubscribe:build", func(s socketio.Conn) {
|
||||
s.Leave("build")
|
||||
fmt.Println("👋", s.ID(), "left build room")
|
||||
s.Emit("info", "Unsubscribed from build log room")
|
||||
})
|
||||
|
||||
registerBuildChannel(server)
|
||||
registerUpdateChannel(server)
|
||||
|
||||
// Broadcast logs to room
|
||||
go func() {
|
||||
for i := 0; ; i++ {
|
||||
time.Sleep(2 * time.Second)
|
||||
msg := fmt.Sprintf("Log line %d @ %s", i, time.Now().Format(time.RFC3339))
|
||||
server.BroadcastToRoom("/", "logs", "logs", msg)
|
||||
}
|
||||
}()
|
||||
|
||||
// Broadcast errors to room
|
||||
go func() {
|
||||
for i := 0; ; i++ {
|
||||
time.Sleep(5 * time.Second)
|
||||
msg := fmt.Sprintf("Error #%d @ %s", i, time.Now().Format(time.RFC3339))
|
||||
server.BroadcastToRoom("/", "errors", "errors", msg)
|
||||
}
|
||||
}()
|
||||
|
||||
go server.Serve()
|
||||
defer server.Close()
|
||||
|
||||
// Enable CORS wrapper for Socket.IO route
|
||||
http.Handle("/socket.io/", withCORS(server))
|
||||
http.Handle("/", http.FileServer(http.Dir("./static")))
|
||||
|
||||
fmt.Println("🚀 Socket.IO server running on :8000")
|
||||
log.Fatal(http.ListenAndServe(":8000", nil))
|
||||
}
|
||||
|
||||
// Reuse your proper CORS handler
|
||||
func withCORS(h http.Handler) http.Handler {
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
origin := r.Header.Get("Origin")
|
||||
if origin != "" {
|
||||
w.Header().Set("Access-Control-Allow-Origin", origin)
|
||||
w.Header().Set("Vary", "Origin")
|
||||
}
|
||||
w.Header().Set("Access-Control-Allow-Methods", "GET,POST,OPTIONS")
|
||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization")
|
||||
w.Header().Set("Access-Control-Allow-Credentials", "true")
|
||||
if r.Method == http.MethodOptions {
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
h.ServeHTTP(w, r)
|
||||
})
|
||||
}
|
||||
|
||||
21
controller/stream_output.go
Normal file
21
controller/stream_output.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
socketio "github.com/googollee/go-socket.io"
|
||||
)
|
||||
|
||||
// streamOutput reads io.Reader line by line and broadcasts
|
||||
func streamOutput(r io.Reader, server *socketio.Server, room string) {
|
||||
scanner := bufio.NewScanner(r)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
server.BroadcastToRoom("/", room, "buildlogs", line)
|
||||
}
|
||||
if err := scanner.Err(); err != nil {
|
||||
server.BroadcastToRoom("/", room, "buildlogs", fmt.Sprintf("❌ Log stream error: %v", err))
|
||||
}
|
||||
}
|
||||
35
controller/update_channel.go
Normal file
35
controller/update_channel.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
socketio "github.com/googollee/go-socket.io"
|
||||
)
|
||||
|
||||
func registerUpdateChannel(server *socketio.Server) {
|
||||
|
||||
server.OnEvent("/", "subscribe:update", func(s socketio.Conn) {
|
||||
s.Join("update")
|
||||
s.Emit("updateLogs", "👋 Subscribed to update channel")
|
||||
fmt.Println("📺", s.ID(), "joined update room")
|
||||
})
|
||||
|
||||
// copy files based on the target passed over
|
||||
server.OnEvent("/", "update", func(s socketio.Conn, target string) {
|
||||
server.BroadcastToRoom("/", "update", "updateLogs",
|
||||
fmt.Sprintf("🚀 Copying latest build to %v", target))
|
||||
copyBuild(server, target)
|
||||
})
|
||||
|
||||
// update the server
|
||||
// server.OnEvent("/", "update", func(s socketio.Conn, target string) {
|
||||
// msg := fmt.Sprintf("🔧 Running updateServer on: %s", target)
|
||||
// server.BroadcastToRoom("/update", "update", "updateLogs", msg)
|
||||
|
||||
// })
|
||||
|
||||
server.OnEvent("/", "unsubscribe:update", func(s socketio.Conn) {
|
||||
s.Leave("update")
|
||||
s.Emit("updateLogs", "👋 Unsubscribed from update logs")
|
||||
})
|
||||
}
|
||||
@@ -8,7 +8,11 @@ import (
|
||||
"io/fs"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
socketio "github.com/googollee/go-socket.io"
|
||||
)
|
||||
|
||||
// ---- Load ignore patterns ----
|
||||
@@ -53,7 +57,7 @@ func shouldInclude(path string, includes []string) bool {
|
||||
}
|
||||
|
||||
// ---- Zip the repo ----
|
||||
func zipProject(srcDir, zipFile string, includes []string) error {
|
||||
func zipProject(server *socketio.Server, srcDir, zipFile string, includes []string) error {
|
||||
outFile, err := os.Create(zipFile)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -65,6 +69,7 @@ func zipProject(srcDir, zipFile string, includes []string) error {
|
||||
|
||||
err = filepath.WalkDir(srcDir, func(path string, d fs.DirEntry, err error) error {
|
||||
if err != nil {
|
||||
server.BroadcastToRoom("/", "build", "buildlogs", fmt.Sprintf("❌ Error walking %s: %v", path, err))
|
||||
return err
|
||||
}
|
||||
if d.IsDir() {
|
||||
@@ -72,12 +77,15 @@ func zipProject(srcDir, zipFile string, includes []string) error {
|
||||
}
|
||||
|
||||
relPath, _ := filepath.Rel(srcDir, path)
|
||||
|
||||
// only include files matching your patterns
|
||||
if !shouldInclude(relPath, includes) {
|
||||
return nil // skip anything not explicitly included
|
||||
return nil
|
||||
}
|
||||
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
server.BroadcastToRoom("/", "build", "buildlogs", fmt.Sprintf("❌ Could not open: %s", relPath))
|
||||
return err
|
||||
}
|
||||
defer file.Close()
|
||||
@@ -88,12 +96,67 @@ func zipProject(srcDir, zipFile string, includes []string) error {
|
||||
|
||||
writer, err := archive.CreateHeader(header)
|
||||
if err != nil {
|
||||
server.BroadcastToRoom("/", "build", "buildlogs", fmt.Sprintf("❌ Could not add header for: %s", relPath))
|
||||
return err
|
||||
}
|
||||
_, err = io.Copy(writer, file)
|
||||
fmt.Println("Added:", relPath)
|
||||
|
||||
if _, err := io.Copy(writer, file); err != nil {
|
||||
server.BroadcastToRoom("/", "build", "buildlogs", fmt.Sprintf("❌ Error zipping: %s", relPath))
|
||||
return err
|
||||
}
|
||||
|
||||
// ✅ Send progress back to clients
|
||||
server.BroadcastToRoom("/", "build", "buildlogs", fmt.Sprintf("📦 Added: %s", relPath))
|
||||
return nil
|
||||
})
|
||||
|
||||
if err == nil {
|
||||
server.BroadcastToRoom("/", "build", "buildlogs", fmt.Sprintf("✅ Archive created: %s", zipFile))
|
||||
doCleanup(server, filepath.Dir(zipFile))
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func doCleanup(server *socketio.Server, dir string) {
|
||||
// read max builds from env
|
||||
maxStr := os.Getenv("MAX_BUILDS")
|
||||
if maxStr == "" {
|
||||
return
|
||||
}
|
||||
maxBuilds, err := strconv.Atoi(maxStr)
|
||||
if err != nil || maxBuilds <= 0 {
|
||||
return
|
||||
}
|
||||
|
||||
entries, err := os.ReadDir(dir)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
var files []os.FileInfo
|
||||
for _, e := range entries {
|
||||
if !e.IsDir() && strings.HasSuffix(e.Name(), ".zip") {
|
||||
info, err := e.Info()
|
||||
if err == nil {
|
||||
files = append(files, info)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sort by modification time newest → oldest
|
||||
sort.Slice(files, func(i, j int) bool {
|
||||
return files[i].ModTime().After(files[j].ModTime())
|
||||
})
|
||||
|
||||
// Delete extras
|
||||
if len(files) > maxBuilds {
|
||||
for _, f := range files[maxBuilds:] {
|
||||
toDelete := filepath.Join(dir, f.Name())
|
||||
if err := os.Remove(toDelete); err == nil {
|
||||
server.BroadcastToRoom("/", "build", "buildlogs",
|
||||
fmt.Sprintf("🧹 Removed old build: %s", f.Name()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,10 +31,10 @@ To correct these errors follow each error.
|
||||
|
||||
- for autoconsume items missing you will need to move materials, that are considered autoconsume to an autoconsume location.
|
||||
- for manual materials you will need to
|
||||
- [scan](/docs/ocp/materials#consuming-new-manual-material-via-scanner)
|
||||
- [lst-consume](/docs/ocp/materials#consuming-new-manual-material-via-lst)
|
||||
- [transfer-to-next](/docs/ocp/materials#tranfer-partial-estimated-quantity-to-the-next-lot)
|
||||
- [Reprint and consume](/docs/ocp/materials#manual-return-and-consume)
|
||||
- [scan](#consuming-new-manual-material-via-scanner)
|
||||
- [lst-consume](#consuming-new-manual-material-via-lst)
|
||||
- [transfer-to-next](#tranfer-partial-estimated-quantity-to-the-next-lot)
|
||||
- [Reprint and consume](#manual-return-and-consume)
|
||||
|
||||
## Consuming new manual material via scanner.
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ const config: Config = {
|
||||
},
|
||||
|
||||
// Set the production url of your site here
|
||||
url: "http://localhost:4200",
|
||||
url: "http://localhost:3000",
|
||||
// Set the /<baseUrl>/ pathname under which your site is served
|
||||
// For GitHub pages deployment, it is often '/<projectName>/'
|
||||
baseUrl: "/lst/d/",
|
||||
@@ -34,29 +34,20 @@ const config: Config = {
|
||||
i18n: {
|
||||
defaultLocale: "en",
|
||||
locales: ["en", "es"],
|
||||
// localeConfigs: {
|
||||
// en: {
|
||||
// label: "English",
|
||||
// direction: "ltr",
|
||||
// htmlLang: "en-US",
|
||||
// calendar: "gregory",
|
||||
// path: "en",
|
||||
// },
|
||||
// es: {
|
||||
// label: "Español",
|
||||
// direction: "ltr",
|
||||
// htmlLang: "es-ES",
|
||||
// calendar: "gregory",
|
||||
// path: "es",
|
||||
// },
|
||||
// de: {
|
||||
// label: "Deutsch",
|
||||
// direction: "ltr",
|
||||
// htmlLang: "de-DE",
|
||||
// calendar: "gregory",
|
||||
// path: "de",
|
||||
// },
|
||||
// },
|
||||
localeConfigs: {
|
||||
en: {
|
||||
label: "English",
|
||||
htmlLang: "en-US",
|
||||
},
|
||||
es: {
|
||||
label: "Español",
|
||||
htmlLang: "es-ES",
|
||||
},
|
||||
de: {
|
||||
label: "Deutsch",
|
||||
htmlLang: "de-DE",
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
presets: [
|
||||
@@ -109,16 +100,21 @@ const config: Config = {
|
||||
position: "left",
|
||||
label: "Docs",
|
||||
},
|
||||
// {
|
||||
// to: "/lst/app",
|
||||
// label: "App",
|
||||
// position: "right",
|
||||
// },
|
||||
// { to: "/blog", label: "Blog", position: "left" },
|
||||
// {
|
||||
// href: "https://github.com/facebook/docusaurus",
|
||||
// label: "GitHub",
|
||||
// position: "right",
|
||||
// },
|
||||
// {
|
||||
// type: "localeDropdown",
|
||||
// position: "right",
|
||||
// },
|
||||
{
|
||||
type: "localeDropdown",
|
||||
position: "right",
|
||||
},
|
||||
],
|
||||
},
|
||||
footer: {
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 9.1 KiB After Width: | Height: | Size: 9.3 KiB |
@@ -8,6 +8,8 @@
|
||||
"dev:app": "dotenvx run -f .env -- tsx watch app/src/main.ts",
|
||||
"dev:docs": "npm run translateDocs && cd lstDocs && npm start",
|
||||
"dev:front": "cd frontend && npm run dev",
|
||||
"dev:db:migrate": "npx drizzle-kit push --config=drizzle-dev.config.ts",
|
||||
"dev:db:generate": "npx drizzle-kit generate --config=drizzle-dev.config.ts",
|
||||
"dev": "npm run dev:app",
|
||||
"copy:docs": "node scripts/lstDocCopy.mjs",
|
||||
"build:app": "rimraf dist && npx tsc",
|
||||
@@ -15,7 +17,7 @@
|
||||
"build:docs": "cd lstDocs && rimraf build && npm run build",
|
||||
"build:wrapper": "cd lstWrapper && rimraf publish && dotnet publish -c Release -o ./publish",
|
||||
"build:ctl": " ",
|
||||
"build": "npm run build:docs && npm run build:front && npm run build:app",
|
||||
"build": "npm run translateDocs && npm run build:docs && npm run build:front && npm run build:app",
|
||||
"install:front": "cd frontend && npm i",
|
||||
"install:docs": "cd lstDocs && npm i",
|
||||
"install:app": "npm i",
|
||||
@@ -25,8 +27,8 @@
|
||||
"docker": "docker compose up --build --force-recreate -d",
|
||||
"commit": "cz",
|
||||
"deploy": "standard-version --conventional-commits && npm run build",
|
||||
"db:migrate": "npx drizzle-kit push --config=drizzle-dev.config.ts",
|
||||
"db:generate": "npx drizzle-kit generate --config=drizzle-dev.config.ts",
|
||||
"db:migrate": "npx drizzle-kit push",
|
||||
"db:generate": "npx drizzle-kit generate",
|
||||
"translateDocs": "cd scripts && node translateScript.js"
|
||||
},
|
||||
"repository": {
|
||||
|
||||
Reference in New Issue
Block a user