fix: add dep checks, npm install fallback, go mod download in build.sh

This commit is contained in:
mirivlad 2026-06-16 12:32:34 +08:00
parent 330adc42f2
commit e3e4385b91
3 changed files with 52 additions and 17 deletions

View File

@ -3,6 +3,9 @@ set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)" ROOT="$(cd "$(dirname "$0")/.." && pwd)"
FAILED=0 FAILED=0
BUILT=0
SKIPPED=0
FAILED_PLUGINS=""
report() { report() {
if [ "$2" -eq 0 ]; then if [ "$2" -eq 0 ]; then
@ -13,11 +16,33 @@ report() {
fi fi
} }
ensure_npm_deps() {
local dir="$1"
if [ ! -f "$dir/package.json" ]; then
return 1
fi
if [ ! -d "$dir/node_modules" ]; then
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-official-plugins build ===" echo "=== verstak-official-plugins build ==="
BUILT=0 # ── Dependency checks ──
SKIPPED=0 echo "[deps]"
FAILED_PLUGINS="" HAS_DEPS=1
if ! command -v node &>/dev/null; then echo " ❌ node: not found"; HAS_DEPS=0; else echo " ✅ node $(node --version)"; fi
if ! command -v npm &>/dev/null; then echo " ❌ npm: not found"; HAS_DEPS=0; fi
if ! command -v go &>/dev/null; then echo " ❌ go: not found"; HAS_DEPS=0; else echo " ✅ go $(go version | grep -oP 'go\S+')"; fi
if [ "$HAS_DEPS" -eq 0 ]; then
echo " ⚠️ some deps missing — will skip matching plugin parts"
fi
for plugin_dir in "$ROOT"/plugins/*/; do for plugin_dir in "$ROOT"/plugins/*/; do
[ -d "$plugin_dir" ] || continue [ -d "$plugin_dir" ] || continue
@ -47,23 +72,29 @@ for plugin_dir in "$ROOT"/plugins/*/; do
# Frontend build # Frontend build
if [ -f "$plugin_dir/frontend/package.json" ]; then if [ -f "$plugin_dir/frontend/package.json" ]; then
echo " → frontend: npm ci + build" echo " → frontend"
(cd "$plugin_dir/frontend" && npm ci --no-audit --no-fund) if command -v npm &>/dev/null; then
report "npm ci" $? ensure_npm_deps "$plugin_dir/frontend"
(cd "$plugin_dir/frontend" && npm run build) (cd "$plugin_dir/frontend" && npm run build)
report "frontend build" $? report "frontend build" $?
BUILT=1 BUILT=1
else
echo " ⚠️ npm not available — skipping frontend"
fi
else else
echo " no frontend/package.json — skipping frontend" echo " no frontend/package.json — skipping frontend"
fi fi
# Backend build (Go) # Backend build (Go)
if [ -f "$plugin_dir/backend/go.mod" ] || [ -f "$plugin_dir/backend/main.go" ]; then if [ -f "$plugin_dir/backend/go.mod" ] || [ -f "$plugin_dir/backend/main.go" ]; then
echo " → backend: go build" echo " → backend"
if [ -d "$plugin_dir/backend" ]; then if command -v go &>/dev/null; then
(cd "$plugin_dir/backend" && go mod download 2>/dev/null || true)
(cd "$plugin_dir/backend" && go build ./...) (cd "$plugin_dir/backend" && go build ./...)
report "backend go build" $? report "backend go build" $?
BUILT=1 BUILT=1
else
echo " ⚠️ go not available — skipping backend"
fi fi
else else
echo " no backend/ — skipping backend" echo " no backend/ — skipping backend"

View File

@ -15,8 +15,12 @@ report() {
echo "=== verstak-official-plugins check ===" echo "=== verstak-official-plugins check ==="
# ── Dependency checks ──
HAS_PYTHON=0
if command -v python3 &>/dev/null; then HAS_PYTHON=1; fi
# Validate all plugin manifests against the SDK schema # Validate all plugin manifests against the SDK schema
if command -v python3 &>/dev/null; then if [ "$HAS_PYTHON" -eq 1 ]; then
echo "[manifest validation]" echo "[manifest validation]"
SDK_SCHEMA="$ROOT/../verstak-sdk/schemas/manifest.json" SDK_SCHEMA="$ROOT/../verstak-sdk/schemas/manifest.json"
if [ -f "$SDK_SCHEMA" ]; then if [ -f "$SDK_SCHEMA" ]; then
@ -35,7 +39,7 @@ for plugin_dir in glob.glob('$ROOT/plugins/*/'):
skipped.append(plugin_dir.split('/')[-2]) skipped.append(plugin_dir.split('/')[-2])
continue continue
except json.JSONDecodeError as e: except json.JSONDecodeError as e:
problems.append(f'{plugin_dir.split(\"/\")[-2]}: invalid JSON — {e}') problems.append(plugin_dir.split('/')[-2] + ': invalid JSON — ' + str(e))
continue continue
checks = { checks = {
@ -47,15 +51,15 @@ for plugin_dir in glob.glob('$ROOT/plugins/*/'):
} }
for check, ok in checks.items(): for check, ok in checks.items():
if not ok: if not ok:
problems.append(f'{manifest.get(\"id\", plugin_dir.split(\"/\")[-2])}: missing/empty \"{check}\"') problems.append(manifest.get('id', plugin_dir.split('/')[-2]) + ': missing/empty \"' + check + '\"')
if skipped: if skipped:
print(f' ⚠️ skipped (no plugin.json): {\", \".join(skipped)}') print(' \u26a0\ufe0f skipped (no plugin.json): ' + ', '.join(skipped))
if problems: if problems:
for p in problems: for p in problems:
print(f' ❌ {p}') print(' \u274c ' + p)
else: else:
print(' all manifests valid') print(' \u2705 all manifests valid')
" "
report "manifests valid" $? report "manifests valid" $?
else else