mirror of
https://github.com/remko/waforth
synced 2025-01-18 22:26:39 +01:00
build: Clean up build
This commit is contained in:
parent
01fcb9e2a8
commit
59b56e5491
1 changed files with 16 additions and 28 deletions
44
build-web.js
44
build-web.js
|
@ -113,35 +113,23 @@ const INDEX_TEMPLATE = `<!doctype html>
|
|||
</html>
|
||||
`;
|
||||
async function handleBuildFinished(result) {
|
||||
let index = INDEX_TEMPLATE.replace(/\$BASE/g, "shell");
|
||||
let testIndex = INDEX_TEMPLATE.replace(/\$BASE/g, "tests");
|
||||
let benchmarksIndex = INDEX_TEMPLATE.replace(/\$BASE/g, "benchmarks");
|
||||
let promptIndex = INDEX_TEMPLATE.replace(/\$BASE/g, "prompt");
|
||||
// console.log(JSON.stringify(result.metafile.outputs, undefined, 2));
|
||||
for (const [out] of Object.entries(result.metafile.outputs)) {
|
||||
const outfile = path.basename(out);
|
||||
const sourcefile = outfile.replace(/-c\$[^.]+\./, ".");
|
||||
// console.log("%s -> %s", sourcefile, outfile);
|
||||
index = index.replace(`/${sourcefile}`, `/${outfile}`);
|
||||
testIndex = testIndex.replace(`/${sourcefile}`, `/${outfile}`);
|
||||
benchmarksIndex = benchmarksIndex.replace(`/${sourcefile}`, `/${outfile}`);
|
||||
promptIndex = promptIndex.replace(`/${sourcefile}`, `/${outfile}`);
|
||||
const indexes = [
|
||||
["shell", "public/waforth"],
|
||||
["tests", "public/waforth/tests"],
|
||||
["benchmarks", "public/waforth/benchmarks"],
|
||||
["prompt", "public/waforth/examples/prompt"],
|
||||
];
|
||||
for (const [base, outpath] of indexes) {
|
||||
let index = INDEX_TEMPLATE.replace(/\$BASE/g, base);
|
||||
for (const [out] of Object.entries(result.metafile.outputs)) {
|
||||
const outfile = path.basename(out);
|
||||
const sourcefile = outfile.replace(/-c\$[^.]+\./, ".");
|
||||
// console.log("%s -> %s", sourcefile, outfile);
|
||||
index = index.replace(`/${sourcefile}`, `/${outfile}`);
|
||||
}
|
||||
await fs.promises.mkdir(outpath, { recursive: true });
|
||||
await fs.promises.writeFile(path.join(outpath, "index.html"), index);
|
||||
}
|
||||
await fs.promises.writeFile("public/waforth/index.html", index);
|
||||
await fs.promises.mkdir("public/waforth/tests", { recursive: true });
|
||||
await fs.promises.writeFile("public/waforth/tests/index.html", testIndex);
|
||||
await fs.promises.mkdir("public/waforth/benchmarks", { recursive: true });
|
||||
await fs.promises.writeFile(
|
||||
"public/waforth/benchmarks/index.html",
|
||||
benchmarksIndex
|
||||
);
|
||||
await fs.promises.mkdir("public/waforth/examples/prompt", {
|
||||
recursive: true,
|
||||
});
|
||||
await fs.promises.writeFile(
|
||||
"public/waforth/examples/prompt/index.html",
|
||||
promptIndex
|
||||
);
|
||||
}
|
||||
|
||||
if (watch) {
|
||||
|
|
Loading…
Reference in a new issue