fix: reorder build — frontend before Go (//go:embed deps), auto-install node_modules/go mod

This commit is contained in:
mirivlad 2026-06-16 12:32:31 +08:00
parent aefb9e9a9c
commit e3b0bf5f4b
3 changed files with 119 additions and 33 deletions

View File

@ -13,23 +13,76 @@ report() {
fi fi
} }
ensure_npm_deps() {
local dir="$1"
if [ ! -f "$dir/package.json" ]; then
return 1
fi
if [ ! -d "$dir/node_modules" ]; then
echo " 📦 node_modules missing — installing..."
if [ -f "$dir/package-lock.json" ]; then
(cd "$dir" && npm ci --no-audit --no-fund)
else
(cd "$dir" && npm install --no-audit --no-fund)
fi
report "npm install in $(basename "$dir")" $?
fi
return 0
}
echo "=== verstak-desktop build ===" echo "=== verstak-desktop build ==="
# ── Dependency checks ──
echo "[deps]"
if ! command -v go &>/dev/null; then
echo " ❌ go: not found. Install Go 1.24+ from https://go.dev/dl/"
FAILED=1
else
echo " ✅ go $(go version | grep -oP 'go\S+')"
fi
if ! command -v node &>/dev/null; then
echo " ❌ node: not found. Install Node.js 20+"
FAILED=1
else
echo " ✅ node $(node --version)"
fi
if ! command -v npm &>/dev/null; then
echo " ❌ npm: not found"
FAILED=1
fi
if [ "$FAILED" -ne 0 ]; then
echo ""
echo "❌ build failed — missing core dependencies"
exit 1
fi
# ── Frontend (build first — Go //go:embed needs frontend/dist/) ──
echo "[frontend]"
if [ -f "$ROOT/frontend/package.json" ]; then
ensure_npm_deps "$ROOT/frontend"
(cd "$ROOT/frontend" && npm run build)
report "frontend build" $?
else
echo " frontend/package.json not found — skipping"
fi
# ── Go backend ── # ── Go backend ──
echo "[backend]" echo "[backend]"
# Ensure Go module deps are downloaded
(cd "$ROOT" && go mod download)
report "go mod download" $?
(cd "$ROOT" && go vet ./...) (cd "$ROOT" && go vet ./...)
report "go vet" $? report "go vet" $?
(cd "$ROOT" && go build ./...) (cd "$ROOT" && go build ./...)
report "go build" $? report "go build" $?
if command -v go-test-summary &>/dev/null || go test -list . ./... &>/dev/null 2>&1; then # Go test (best-effort — some packages may have no tests)
(cd "$ROOT" && go test -count=1 ./... 2>&1 || true) (cd "$ROOT" && go test -count=1 ./... 2>&1 || true)
report "go test" $? report "go test" $?
else
echo " go test: no tests to run"
fi
# ── Wails ── # ── Wails ──
echo "[wails]" echo "[wails]"
@ -41,17 +94,6 @@ else
FAILED=1 FAILED=1
fi fi
# ── Frontend ──
echo "[frontend]"
if [ -f "$ROOT/frontend/package.json" ]; then
(cd "$ROOT/frontend" && npm ci --no-audit --no-fund)
report "npm ci" $?
(cd "$ROOT/frontend" && npm run build)
report "frontend build" $?
else
echo " frontend/package.json not found — skipping"
fi
echo "" echo ""
if [ "$FAILED" -eq 0 ]; then if [ "$FAILED" -eq 0 ]; then
echo "✅ build passed" echo "✅ build passed"

View File

@ -13,13 +13,34 @@ report() {
fi fi
} }
ensure_npm_deps() {
local dir="$1"
if [ ! -f "$dir/package.json" ]; then
return 1
fi
if [ ! -d "$dir/node_modules" ]; then
echo " 📦 node_modules missing — installing..."
if [ -f "$dir/package-lock.json" ]; then
(cd "$dir" && npm ci --no-audit --no-fund)
else
(cd "$dir" && npm install --no-audit --no-fund)
fi
report "npm install in $(basename "$dir")" $?
fi
return 0
}
echo "=== verstak-desktop check ===" echo "=== verstak-desktop check ==="
# Go vet # ── Go deps ──
(cd "$ROOT" && go mod download)
report "go mod download" $?
# ── Go vet ──
(cd "$ROOT" && go vet ./...) (cd "$ROOT" && go vet ./...)
report "go vet" $? report "go vet" $?
# Go fmt (non-destructive — only report unformatted files) # ── Go fmt (non-destructive — only report unformatted files) ──
UNFORMATTED=$(cd "$ROOT" && gofmt -l . 2>/dev/null || go fmt -n ./... 2>&1 || true) UNFORMATTED=$(cd "$ROOT" && gofmt -l . 2>/dev/null || go fmt -n ./... 2>&1 || true)
if [ -z "$UNFORMATTED" ]; then if [ -z "$UNFORMATTED" ]; then
echo " ✅ gofmt: all files formatted" echo " ✅ gofmt: all files formatted"
@ -29,22 +50,26 @@ else
FAILED=1 FAILED=1
fi fi
# Go mod tidy check (non-destructive — report only) # ── Go mod tidy check (non-destructive) ──
(cd "$ROOT" && go mod tidy -diff 2>&1 || echo " ⚠️ go mod tidy check skipped") (cd "$ROOT" && go mod tidy -diff 2>&1 || echo " ⚠️ go mod tidy check skipped")
report "go mod tidy" $? report "go mod tidy" $?
# Frontend lint # ── Frontend checks ──
if [ -f "$ROOT/frontend/package.json" ]; then echo "[frontend]"
# Check if npm ci is needed (node_modules missing) if ensure_npm_deps "$ROOT/frontend"; then
if [ ! -d "$ROOT/frontend/node_modules" ]; then
echo " frontend/node_modules missing — run build.sh first"
fi
if grep -q '"lint"' "$ROOT/frontend/package.json" 2>/dev/null; then if grep -q '"lint"' "$ROOT/frontend/package.json" 2>/dev/null; then
(cd "$ROOT/frontend" && npx tsc --noEmit 2>&1 || true) (cd "$ROOT/frontend" && npm run lint 2>&1 || true)
report "frontend tsc --noEmit" $? report "frontend lint" $?
else else
echo " no lint script in frontend/package.json" echo " no lint script in frontend/package.json"
fi fi
# Always run tsc --noEmit if typescript is available
if [ -f "$ROOT/frontend/node_modules/.bin/tsc" ]; then
(cd "$ROOT/frontend" && npx tsc --noEmit 2>&1 || true)
report "frontend tsc --noEmit" $?
fi
else
echo " no frontend/package.json"
fi fi
echo "" echo ""

View File

@ -13,15 +13,34 @@ report() {
fi fi
} }
ensure_npm_deps() {
local dir="$1"
if [ ! -f "$dir/package.json" ]; then
return 1
fi
if [ ! -d "$dir/node_modules" ]; then
echo " 📦 node_modules missing — installing..."
if [ -f "$dir/package-lock.json" ]; then
(cd "$dir" && npm ci --no-audit --no-fund)
else
(cd "$dir" && npm install --no-audit --no-fund)
fi
report "npm install in $(basename "$dir")" $?
fi
return 0
}
echo "=== verstak-desktop test ===" echo "=== verstak-desktop test ==="
# Go tests # ── Go tests ──
(cd "$ROOT" && go test -count=1 -v ./... 2>&1 || true) (cd "$ROOT" && go mod download)
OUTPUT=$(cd "$ROOT" && go test -count=1 -v ./... 2>&1) || true
echo "$OUTPUT" | grep -E '(FAIL|PASS|---)' || true
report "go test" $? report "go test" $?
# Frontend tests # ── Frontend tests ──
if [ -f "$ROOT/frontend/package.json" ]; then echo "[frontend]"
# Only run if vitest or jest is in the config if ensure_npm_deps "$ROOT/frontend"; then
if grep -q '"test"' "$ROOT/frontend/package.json" 2>/dev/null; then if grep -q '"test"' "$ROOT/frontend/package.json" 2>/dev/null; then
(cd "$ROOT/frontend" && npm test 2>&1 || true) (cd "$ROOT/frontend" && npm test 2>&1 || true)
report "frontend test" $? report "frontend test" $?