// Assemble the static Atlas site into dist/ (no dependencies).
// node site/build.js [outDir]
const fs = require("fs");
const path = require("path");
const root = path.resolve(__dirname, "..");
const out = path.resolve(root, process.argv[2] || "dist");
const copy = (from, to) => {
fs.mkdirSync(path.dirname(path.join(out, to)), { recursive: true });
fs.copyFileSync(path.join(root, from), path.join(out, to));
};
fs.rmSync(out, { recursive: true, force: true });
for (const f of fs.readdirSync(path.join(root, "site/atlas"))) copy(`site/atlas/${f}`, f);
// The page is written as an Artifact body (the artifact host adds the document skeleton). For GitHub Pages and
// local serving, give it its own doctype, charset and viewport.
{
const p = path.join(out, "index.html");
// links from forge.yaml (data/public/links.json, written by `python -m collection build`)
const links = JSON.parse(fs.readFileSync(path.join(root, "data/public/links.json"), "utf8"));
const html = fs.readFileSync(p, "utf8").replace(/\{\{(\w+)\}\}/g, (m, k) => (k in links ? links[k] : m));
fs.writeFileSync(p, html);
if (!/^\s*\n\n\n${html}`);
}
// The route advisor and the bot's text mapping (Ken's bot downloads these two from the published site)
copy("core/graph.js", "graph.js");
copy("core/solver.js", "solver.js");
// The numbers the page shows (all computed in Python) and the published data
for (const f of ["stats.json", "register.json", "graph.json", "policy.json", "black.json", "tree.json", "experiments.json"]) copy(`data/public/${f}`, `data/${f}`);
copy("data/public/runs_clean.csv", "data/runs_clean.csv");
for (const f of ["croissant.json", "dictionary.yaml"]) copy(`data/${f}`, `data/${f}`);
// Source files shown in the page's "view the code" panel
copy("core/atlas/coding.py", "python/coding.py");
copy("core/spec/form.yaml", "python/form.yaml");
for (const f of ["measures.yaml", "site_stats.py", "stats_core.py"]) copy(`analysis/stats/${f}`, `python/${f}`);
copy("README.md", "README.md");
fs.writeFileSync(path.join(out, ".nojekyll"), "");
console.log(`Site built in ${path.relative(root, out) || "."}`);