Files
likang 2cdf535fd1
CI / Select checks (push) Has been cancelled
CI / Format and repository checks (push) Has been cancelled
CI / Compile RISC-V (manual) (push) Has been cancelled
Docker / image (push) Has been cancelled
Generated files / Regenerate and commit (push) Has been cancelled
Lists / Design format changes merge cleanly (push) Has been cancelled
Lists / Lists are sorted one item per line (push) Has been cancelled
Packaging lint / lint (push) Has been cancelled
Pages / build (push) Has been cancelled
CI / Dependency advisories (push) Has been cancelled
CI / Quick compile (push) Has been cancelled
CI / Native Linux Clippy (push) Has been cancelled
CI / Build tests (push) Has been cancelled
CI / Native Linux tests (push) Has been cancelled
CI / GPU path tests (1/4) (push) Has been cancelled
CI / GPU path tests (2/4) (push) Has been cancelled
CI / GPU path tests (3/4) (push) Has been cancelled
CI / GPU path tests (4/4) (push) Has been cancelled
CI / Action matrix (1/16) (push) Has been cancelled
CI / Action matrix (10/16) (push) Has been cancelled
CI / Action matrix (11/16) (push) Has been cancelled
CI / Action matrix (12/16) (push) Has been cancelled
CI / Action matrix (13/16) (push) Has been cancelled
CI / Action matrix (14/16) (push) Has been cancelled
CI / Action matrix (15/16) (push) Has been cancelled
CI / Action matrix (16/16) (push) Has been cancelled
CI / Action matrix (2/16) (push) Has been cancelled
CI / Action matrix (3/16) (push) Has been cancelled
CI / Action matrix (4/16) (push) Has been cancelled
CI / Action matrix (5/16) (push) Has been cancelled
CI / Action matrix (6/16) (push) Has been cancelled
CI / Action matrix (7/16) (push) Has been cancelled
CI / Action matrix (8/16) (push) Has been cancelled
CI / Action matrix (9/16) (push) Has been cancelled
CI / Action matrix determinism (push) Has been cancelled
CI / Property tests (many cases) (push) Has been cancelled
CI / Doc tests (push) Has been cancelled
CI / Reference tests (push) Has been cancelled
CI / Windows D3D12 FXC shaders (push) Has been cancelled
CI / Windows app startup (push) Has been cancelled
CI / ci (push) Has been cancelled
CI / Compile WebAssembly (push) Has been cancelled
CI / Nightly alert (push) Has been cancelled
Pages / deploy (push) Has been cancelled
修改ai助手
2026-11-09 18:53:36 +08:00

114 lines
5.0 KiB
Bash
Executable File

#!/usr/bin/env bash
# Build a complete CAD website package and a separate engine-only update archive.
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P)"
cd "$ROOT_DIR"
for tool in node cargo rustc trunk zip unzip; do
if ! command -v "$tool" >/dev/null 2>&1; then
printf 'Error: required build tool is missing: %s\n' "$tool" >&2
exit 1
fi
done
# The platform frontend is maintained in VibeMake; publishing it never builds the main site.
SITE_ROOT="$(node -p "require('node:path').resolve(process.env.VIBEMAKE_SITE_ROOT || '../vibemake')")"
for file in scripts/build-cad.mjs cad.html cad/editor/index.html js/cad/app.js css/cad.css; do
if [[ ! -f "$SITE_ROOT/$file" ]]; then
printf 'Error: CAD frontend input is missing: %s/%s\n' "$SITE_ROOT" "$file" >&2
printf 'Set VIBEMAKE_SITE_ROOT to the VibeMake source directory.\n' >&2
exit 1
fi
done
if ! node --input-type=module - "$SITE_ROOT/scripts/lib/version-site-assets.mjs" <<'NODE'
import { pathToFileURL } from 'node:url';
await import(pathToFileURL(process.argv[2]).href);
NODE
then
printf 'Error: install the CAD frontend packaging dependencies with npm ci in %s.\n' "$SITE_ROOT" >&2
exit 1
fi
WASM_LIB_DIR="$(rustc --print target-libdir --target wasm32-unknown-unknown)"
if [[ ! -d "$WASM_LIB_DIR" ]]; then
printf 'Error: install the WebAssembly target first:\n rustup target add wasm32-unknown-unknown\n' >&2
exit 1
fi
export CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-"$ROOT_DIR/target"}"
ENGINE_DIR="$(node -p "require('node:path').resolve(process.env.VIBEMAKE_CAD_ENGINE_OUT || 'dist/vibemake-cad-engine')")"
export VIBEMAKE_CAD_ENGINE_OUT="$ENGINE_DIR"
ARCHIVE="$ROOT_DIR/dist/vibemake-cad-engine.zip"
SITE_ARCHIVE="$ROOT_DIR/dist/vibemake-cad.zip"
printf 'Building the release Web engine...\n'
if command -v nice >/dev/null 2>&1; then
nice node "$ROOT_DIR/scripts/build-vibemake-cad.mjs"
else
node "$ROOT_DIR/scripts/build-vibemake-cad.mjs"
fi
mkdir -p "$ROOT_DIR/dist"
STAGING_DIR="$(mktemp -d "$ROOT_DIR/dist/.web-package.XXXXXX")"
trap 'rm -rf -- "$STAGING_DIR"' EXIT
node --input-type=module - "$ENGINE_DIR" "$STAGING_DIR" <<'NODE'
import { createHash } from 'node:crypto';
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
import { dirname, join, resolve, sep } from 'node:path';
const output = resolve(process.argv[2]);
const stage = resolve(process.argv[3]);
const manifestBytes = readFileSync(join(output, 'engine.json'));
const manifest = JSON.parse(manifestBytes);
if (!/^[a-f0-9]{24}$/.test(manifest.buildId)
|| !Array.isArray(manifest.files) || manifest.files.length === 0) {
throw new Error('The Web engine manifest is invalid');
}
const prefix = `/cad/_assets/${manifest.buildId}/`;
const assetRoot = resolve(output, '_assets', manifest.buildId) + sep;
for (const file of manifest.files) {
if (typeof file.path !== 'string' || !file.path.startsWith(prefix)) {
throw new Error('An engine asset is outside the current build');
}
const relativePath = file.path.slice('/cad/'.length);
const source = resolve(output, relativePath);
if (!source.startsWith(assetRoot)) {
throw new Error('An engine asset has an invalid path');
}
const bytes = readFileSync(source);
const sha256 = createHash('sha256').update(bytes).digest('hex');
if (bytes.length !== file.size || sha256 !== file.sha256) {
throw new Error(`Engine asset verification failed: ${file.path}`);
}
const target = join(stage, 'cad', relativePath);
mkdirSync(dirname(target), { recursive: true });
writeFileSync(target, bytes);
}
writeFileSync(join(stage, 'cad', 'engine.json'), manifestBytes);
writeFileSync(join(stage, 'cad', 'sw.js'), readFileSync(join(output, 'sw.js')));
writeFileSync(join(stage, 'cad', 'ENGINE-ONLY.txt'), 'Engine update only: this archive contains no HTML pages. For a complete CAD deployment, use vibemake-cad.zip from the same build.\n');
console.log(`Verified ${manifest.files.length} assets for build ${manifest.buildId}`);
NODE
(cd "$STAGING_DIR" && zip -q -r vibemake-cad-engine.zip cad)
mv -f "$STAGING_DIR/vibemake-cad-engine.zip" "$ARCHIVE"
printf '\nPackaging CAD HTML, scripts, styles and the freshly built engine...\n'
VIBEMAKE_CAD_ENGINE_DIST="$ENGINE_DIR" \
VIBEMAKE_CAD_PACKAGE_DIR="$ROOT_DIR/dist/vibemake-cad" \
VIBEMAKE_CAD_PACKAGE_ZIP="$SITE_ARCHIVE" \
node "$SITE_ROOT/scripts/build-cad.mjs"
printf '\nWeb build completed successfully.\n'
printf 'Engine directory: %s\n' "$ENGINE_DIR"
printf 'Engine manifest: %s/engine.json\n' "$ENGINE_DIR"
printf 'DEPLOY THIS COMPLETE CAD ZIP: %s\n' "$SITE_ARCHIVE"
printf 'Engine-only update ZIP (no HTML): %s\n' "$ARCHIVE"
printf '\nExtract the complete CAD ZIP directly into <website-root>/cad/.\n'
printf 'Its root contains index.html, editor/, js/, css/, vendor/ and the current engine.\n'
printf 'Preserve the main site, PCB and existing CAD asset directories. Do not extract into cad/cad/.\n'
printf 'The engine-only ZIP has a different layout: merge it into the website root.\n'
printf 'No main-site build or deployment is required.\n'