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> </html>
`; `;
async function handleBuildFinished(result) { async function handleBuildFinished(result) {
let index = INDEX_TEMPLATE.replace(/\$BASE/g, "shell"); const indexes = [
let testIndex = INDEX_TEMPLATE.replace(/\$BASE/g, "tests"); ["shell", "public/waforth"],
let benchmarksIndex = INDEX_TEMPLATE.replace(/\$BASE/g, "benchmarks"); ["tests", "public/waforth/tests"],
let promptIndex = INDEX_TEMPLATE.replace(/\$BASE/g, "prompt"); ["benchmarks", "public/waforth/benchmarks"],
// console.log(JSON.stringify(result.metafile.outputs, undefined, 2)); ["prompt", "public/waforth/examples/prompt"],
for (const [out] of Object.entries(result.metafile.outputs)) { ];
const outfile = path.basename(out); for (const [base, outpath] of indexes) {
const sourcefile = outfile.replace(/-c\$[^.]+\./, "."); let index = INDEX_TEMPLATE.replace(/\$BASE/g, base);
// console.log("%s -> %s", sourcefile, outfile); for (const [out] of Object.entries(result.metafile.outputs)) {
index = index.replace(`/${sourcefile}`, `/${outfile}`); const outfile = path.basename(out);
testIndex = testIndex.replace(`/${sourcefile}`, `/${outfile}`); const sourcefile = outfile.replace(/-c\$[^.]+\./, ".");
benchmarksIndex = benchmarksIndex.replace(`/${sourcefile}`, `/${outfile}`); // console.log("%s -> %s", sourcefile, outfile);
promptIndex = promptIndex.replace(`/${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) { if (watch) {