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
31 lines
3.2 KiB
JavaScript
31 lines
3.2 KiB
JavaScript
#!/usr/bin/env node
|
|
// Independent Rust/WASM artifact. No fallback or alternate geometry kernel.
|
|
import { createHash } from 'node:crypto';
|
|
import { mkdirSync, readFileSync, readdirSync, cpSync, writeFileSync, existsSync } from 'node:fs';
|
|
import { resolve, relative, join } from 'node:path';
|
|
import { fileURLToPath } from 'node:url';
|
|
import { execFileSync } from 'node:child_process';
|
|
const root = resolve(fileURLToPath(new URL('..', import.meta.url)));
|
|
const raw = join(root, 'target/vibemake-cad-raw');
|
|
const destination = resolve(process.env.VIBEMAKE_CAD_ENGINE_OUT || join(root, 'dist/vibemake-cad-engine'));
|
|
execFileSync('trunk', ['build', '--release', '--dist', raw], { cwd: join(root, 'apps/solidcraft-web'), stdio: 'inherit' });
|
|
const walk = (directory) => readdirSync(directory, { withFileTypes: true }).flatMap((entry) => entry.isDirectory() ? walk(join(directory, entry.name)) : [join(directory, entry.name)]);
|
|
const selected = walk(raw).filter((file) => /\.(js|wasm|ttf|otf|txt)$/i.test(file) && !file.endsWith('/sw.js')).sort();
|
|
const js = selected.find((file) => /solidcraft-web.*\.js$/.test(file));
|
|
const wasm = selected.find((file) => /solidcraft-web.*_bg\.wasm$/.test(file));
|
|
const font = selected.find((file) => file.endsWith('/CraftUI-SC.otf'));
|
|
if (!js || !wasm || !font) throw new Error('Engine JS, WASM or Chinese font is missing');
|
|
const digest = (file) => createHash('sha256').update(readFileSync(file)).digest('hex');
|
|
const buildId = createHash('sha256').update(selected.map((file) => `${relative(raw, file)}:${digest(file)}`).join('\n')).digest('hex').slice(0, 24);
|
|
const prefix = `/cad/_assets/${buildId}/`;
|
|
const files = selected.map((file) => ({ path: prefix + relative(raw, file).replaceAll('\\', '/'), size: readFileSync(file).length, sha256: digest(file) }));
|
|
for (const file of selected) { const out = join(destination, '_assets', buildId, relative(raw, file)); mkdirSync(resolve(out, '..'), { recursive: true }); cpSync(file, out); }
|
|
const manifest = { bridgeVersion: 1, engineKind: 'solidcraft', buildId, builtAt: new Date().toISOString(), kernel: 'smlib',
|
|
js: prefix + relative(raw, js), wasm: prefix + relative(raw, wasm), chineseFont: prefix + relative(raw, font), files };
|
|
mkdirSync(destination, { recursive: true }); writeFileSync(join(destination, 'engine.json'), JSON.stringify(manifest, null, 2) + '\n');
|
|
if (!existsSync(join(destination, '_assets', buildId))) throw new Error('Engine output failed');
|
|
const publicFiles = files.map((file) => file.path);
|
|
// Cache only this build's public assets, never API requests or signed URLs.
|
|
writeFileSync(join(destination, 'sw.js'), `const FILES=new Set(${JSON.stringify(publicFiles)});\nconst CACHE='vm.cad.static.${buildId}';\nself.addEventListener('install',()=>{});\nself.addEventListener('activate',()=>{});\nself.addEventListener('fetch',event=>{const u=new URL(event.request.url);if(event.request.method!=='GET'||u.origin!==self.location.origin||u.search||!FILES.has(u.pathname))return;event.respondWith((async()=>{const cache=await caches.open(CACHE);const hit=await cache.match(event.request);if(hit)return hit;const response=await fetch(event.request);if(response.ok)await cache.put(event.request,response.clone());return response;})());});\n`);
|
|
console.log(`Engine directory: ${destination}`);
|