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)"
FAILED=0
BUILT=0
SKIPPED=0
FAILED_PLUGINS=""
report() {
if [ "$2" -eq 0 ]; then
@ -13,11 +16,33 @@ report() {
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 ==="
BUILT=0
SKIPPED=0
FAILED_PLUGINS=""
# ── Dependency checks ──
echo "[deps]"
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
[ -d "$plugin_dir" ] || continue
@ -47,23 +72,29 @@ for plugin_dir in "$ROOT"/plugins/*/; do
# Frontend build
if [ -f "$plugin_dir/frontend/package.json" ]; then
echo " → frontend: npm ci + build"
(cd "$plugin_dir/frontend" && npm ci --no-audit --no-fund)
report "npm ci" $?
(cd "$plugin_dir/frontend" && npm run build)
report "frontend build" $?
BUILT=1
echo " → frontend"
if command -v npm &>/dev/null; then
ensure_npm_deps "$plugin_dir/frontend"
(cd "$plugin_dir/frontend" && npm run build)
report "frontend build" $?
BUILT=1
else
echo " ⚠️ npm not available — skipping frontend"
fi
else
echo " no frontend/package.json — skipping frontend"
fi
# Backend build (Go)
if [ -f "$plugin_dir/backend/go.mod" ] || [ -f "$plugin_dir/backend/main.go" ]; then
echo " → backend: go build"
if [ -d "$plugin_dir/backend" ]; then
echo " → backend"
if command -v go &>/dev/null; then
(cd "$plugin_dir/backend" && go mod download 2>/dev/null || true)
(cd "$plugin_dir/backend" && go build ./...)
report "backend go build" $?
BUILT=1
else
echo " ⚠️ go not available — skipping backend"
fi
else
echo " no backend/ — skipping backend"

View File

@ -15,8 +15,12 @@ report() {
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
if command -v python3 &>/dev/null; then
if [ "$HAS_PYTHON" -eq 1 ]; then
echo "[manifest validation]"
SDK_SCHEMA="$ROOT/../verstak-sdk/schemas/manifest.json"
if [ -f "$SDK_SCHEMA" ]; then
@ -35,7 +39,7 @@ for plugin_dir in glob.glob('$ROOT/plugins/*/'):
skipped.append(plugin_dir.split('/')[-2])
continue
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
checks = {
@ -47,15 +51,15 @@ for plugin_dir in glob.glob('$ROOT/plugins/*/'):
}
for check, ok in checks.items():
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:
print(f' ⚠️ skipped (no plugin.json): {\", \".join(skipped)}')
print(' \u26a0\ufe0f skipped (no plugin.json): ' + ', '.join(skipped))
if problems:
for p in problems:
print(f' ❌ {p}')
print(' \u274c ' + p)
else:
print(' all manifests valid')
print(' \u2705 all manifests valid')
"
report "manifests valid" $?
else