feat: add scripts/build.sh, test.sh, check.sh

This commit is contained in:
2026-06-16 12:11:59 +08:00
parent 2f02db00f5
commit 2f1b822e20
1156 changed files with 814523 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
FAILED=0
report() {
if [ "$2" -eq 0 ]; then
echo "$1"
else
echo "$1"
FAILED=1
fi
}
echo "=== verstak-sdk build ==="
# Install dependencies if needed
if [ ! -d "$ROOT/node_modules" ]; then
if [ -f "$ROOT/package-lock.json" ]; then
(cd "$ROOT" && npm ci --no-audit --no-fund)
report "npm ci" $?
else
(cd "$ROOT" && npm install --no-audit --no-fund)
report "npm install" $?
fi
fi
# Build TypeScript
(cd "$ROOT" && npm run build)
report "tsc build" $?
echo ""
if [ "$FAILED" -eq 0 ]; then
echo "✅ build passed"
else
echo "❌ build failed"
fi
exit "$FAILED"
+69
View File
@@ -0,0 +1,69 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
FAILED=0
report() {
if [ "$2" -eq 0 ]; then
echo "$1"
else
echo "$1"
FAILED=1
fi
}
echo "=== verstak-sdk check ==="
# Validate that all JSON schemas are valid JSON
echo "[schema validation]"
if command -v python3 &>/dev/null; then
SCHEMA_DIR="$ROOT/schemas"
python3 -c "
import json, glob, sys
schemas = glob.glob('$SCHEMA_DIR/**/*.json', recursive=True) + glob.glob('$SCHEMA_DIR/*.json', recursive=False)
errors = []
for path in schemas:
try:
with open(path) as f:
data = json.load(f)
if '\$schema' not in data:
errors.append(path + ': missing \$schema')
if 'type' not in data:
errors.append(path + ': missing type')
except json.JSONDecodeError as e:
errors.append(path + ': ' + str(e))
except Exception as e:
errors.append(path + ': ' + str(e))
if errors:
for e in errors:
print(' \u274c ' + e)
sys.exit(1)
else:
print(' \u2705', len(schemas), 'schemas: valid JSON with \$schema and type')
"
report "JSON schemas valid" $?
else
echo " ️ python3 not available — skipping schema validation"
fi
# TypeScript check (noEmit)
if [ ! -d "$ROOT/node_modules" ]; then
if [ -f "$ROOT/package-lock.json" ]; then
(cd "$ROOT" && npm ci --no-audit --no-fund)
report "npm ci" $?
else
(cd "$ROOT" && npm install --no-audit --no-fund)
report "npm install" $?
fi
fi
(cd "$ROOT" && npx tsc --noEmit)
report "tsc --noEmit" $?
echo ""
if [ "$FAILED" -eq 0 ]; then
echo "✅ all checks passed"
else
echo "❌ some checks failed"
fi
exit "$FAILED"
+48
View File
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
FAILED=0
report() {
if [ "$2" -eq 0 ]; then
echo "$1"
else
echo "$1"
FAILED=1
fi
}
echo "=== verstak-sdk test ==="
# Install deps if missing
if [ ! -d "$ROOT/node_modules" ]; then
if [ -f "$ROOT/package-lock.json" ]; then
(cd "$ROOT" && npm ci --no-audit --no-fund)
report "npm ci" $?
else
(cd "$ROOT" && npm install --no-audit --no-fund)
report "npm install" $?
fi
fi
# Run vitest tests
if grep -q '"test"' "$ROOT/package.json" 2>/dev/null; then
OUTPUT=$(cd "$ROOT" && npm test 2>&1) || true
if echo "$OUTPUT" | grep -q "No test files found"; then
echo " ️ vitest: no test files yet"
else
echo "$OUTPUT"
report "vitest" ${PIPESTATUS[0]}
fi
else
echo " ️ no test script in package.json"
fi
echo ""
if [ "$FAILED" -eq 0 ]; then
echo "✅ all tests passed"
else
echo "❌ some tests failed"
fi
exit "$FAILED"