General source code refactoring

This commit is contained in:
2026-09-17 12:07:01 -03:00
parent 4421b28efe
commit ac817a69d4
92 changed files with 18211 additions and 19394 deletions

29
scripts/compose.cjs Normal file
View File

@@ -0,0 +1,29 @@
const fs = require("node:fs");
const path = require("node:path");
const vm = require("node:vm");
const sources = require("./sources.cjs");
const root = path.resolve(__dirname, "..");
/** Compose classic scripts at build time; never load or evaluate code at runtime. */
function composeScript(target, { bootstrap = true } = {}) {
const files = sources[target];
if (!files) throw new Error(`Unknown script target: ${target}`);
if (new Set(files).size !== files.length) throw new Error(`Duplicate source in ${target}`);
const parts = files.map(file => {
const source = fs.readFileSync(path.join(root, file), "utf8");
new vm.Script(source, { filename: file });
return `// Source: ${file}\n${source}`;
});
if (target === "content") {
const css = fs.readFileSync(path.join(root, "src/content/styles/redwood.css"), "utf8");
parts.unshift(`const redwoodStyles = ${JSON.stringify(css)};`);
}
const factory = target === "content" ? "createContentApplication" : "createBackgroundApplication";
const ending = bootstrap ? `${factory}().start();` : `return ${factory};`;
const output = `(function () {\n "use strict";\n${parts.join("\n")}\n${ending}\n})();\n`;
new vm.Script(output, { filename: `${target}.js` });
return output;
}
module.exports = { composeScript, sources };