build: Clean up build

This commit is contained in:
Remko Tronçon 2022-05-08 18:44:03 +02:00
parent 01fcb9e2a8
commit 59b56e5491

View file

@ -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) {