60c66fd731
- sg (the browser's console): the project, tool, hint, open window, selection, errors and bodies in one look; pick things by name; list and run what's offered; read and set the open window's rows (slots, numbers, choices, toggles); give a waiting slot a face or edge; Done / Cancel; wait for the engine; each body's health; open a project. sg.help() lists it. - npm run check <project>: rebuilds it step by step and says what each step made, changed or took away, its error, and how sound each body is. - npm run render <project> <out.png>: a shaded picture with edges from any side, drawn without a browser. - tests/kit.ts: the engine started once, check / done, and quick sketches, shapes and steps (wrap.test.ts uses it). - version.json on the site: the commit it was built from; npm run live says whether main is live (--wait until it is). - The engine measures each body's health on request (valid, closed, solids, faces, volume, box). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
87 lines
3.1 KiB
TypeScript
87 lines
3.1 KiB
TypeScript
import { execSync } from "node:child_process";
|
|
import { readFileSync, readdirSync, statSync, writeFileSync } from "node:fs";
|
|
import { join, relative } from "node:path";
|
|
import { defineConfig, type Plugin } from "vite";
|
|
|
|
const pkg = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8")) as { version: string };
|
|
|
|
/**
|
|
* Offline mode's download list: every file the app needs, and the build it
|
|
* belongs to (the main script's name), written into dist/offline-files.json.
|
|
*/
|
|
function offlineFiles(): Plugin {
|
|
let outDir = "dist";
|
|
return {
|
|
name: "offline-files",
|
|
apply: "build",
|
|
configResolved(c) {
|
|
outDir = c.build.outDir;
|
|
},
|
|
closeBundle() {
|
|
const skip = new Set(["_headers", "robots.txt", "sitemap.xml", "og-image.png", "sw.js", "offline-files.json", "version.json"]);
|
|
const files: string[] = [];
|
|
const walk = (dir: string) => {
|
|
for (const n of readdirSync(dir)) {
|
|
const p = join(dir, n);
|
|
if (statSync(p).isDirectory()) walk(p);
|
|
else {
|
|
const rel = relative(outDir, p).replace(/\\/g, "/");
|
|
if (!skip.has(rel)) files.push(rel);
|
|
}
|
|
}
|
|
};
|
|
walk(outDir);
|
|
const html = readFileSync(join(outDir, "index.html"), "utf8");
|
|
const build = html.match(/index-[\w-]+\.js/)?.[0] ?? String(Date.now());
|
|
// The page under its address too (that's what the browser asks for).
|
|
writeFileSync(join(outDir, "offline-files.json"), JSON.stringify({ build, files: ["./", ...files.sort()] }));
|
|
},
|
|
};
|
|
}
|
|
|
|
/**
|
|
* What is live: dist/version.json names the commit it was built from and the
|
|
* main script, so `npm run live` (or a glance at /version.json) tells whether
|
|
* a push has reached the site.
|
|
*/
|
|
function versionFile(): Plugin {
|
|
let outDir = "dist";
|
|
return {
|
|
name: "version-file",
|
|
apply: "build",
|
|
configResolved(c) {
|
|
outDir = c.build.outDir;
|
|
},
|
|
closeBundle() {
|
|
const git = (cmd: string) => {
|
|
try {
|
|
return execSync(`git ${cmd}`, { stdio: ["ignore", "pipe", "ignore"] }).toString().trim();
|
|
} catch {
|
|
return "";
|
|
}
|
|
};
|
|
// The build server's own name for the commit when it has no git folder.
|
|
const commit = git("rev-parse HEAD") || process.env.WORKERS_CI_COMMIT_SHA || process.env.CF_PAGES_COMMIT_SHA || "";
|
|
const html = readFileSync(join(outDir, "index.html"), "utf8");
|
|
const info = {
|
|
version: pkg.version,
|
|
commit,
|
|
subject: commit ? git(`log -1 --format=%s ${commit}`) : "",
|
|
script: html.match(/index-[\w-]+\.js/)?.[0] ?? "",
|
|
built: new Date().toISOString(),
|
|
};
|
|
writeFileSync(join(outDir, "version.json"), JSON.stringify(info, null, 2));
|
|
},
|
|
};
|
|
}
|
|
|
|
export default defineConfig({
|
|
// Relative base so the build works from any static host sub-path (GitHub Pages etc.).
|
|
base: "./",
|
|
define: { __APP_VERSION__: JSON.stringify(pkg.version) },
|
|
worker: { format: "es" },
|
|
optimizeDeps: { exclude: ["replicad-opencascadejs"] },
|
|
build: { target: "es2022", chunkSizeWarningLimit: 4000 },
|
|
plugins: [offlineFiles(), versionFile()],
|
|
});
|