#!/usr/bin/env node // Render a profile with web/engine.js. Variables come from the environment: // sh -c 'set -a; . common.env; . home.env; node tools/render.js' const fs = require("fs"); const path = require("path"); const { render, DEFAULTS } = require("../web/engine.js"); const tplDir = path.join(__dirname, "..", "templates"); const templates = {}; for (const dir of fs.readdirSync(tplDir)) { const full = path.join(tplDir, dir); if (!fs.statSync(full).isDirectory()) continue; for (const f of fs.readdirSync(full)) templates[`${dir}/${f}`] = fs.readFileSync(path.join(full, f), "utf8"); } const vars = {}; for (const [k, val] of Object.entries(process.env)) if (k in DEFAULTS || /^(SUB[0-9]*|HY2)_/.test(k)) vars[k] = val; try { process.stdout.write(render(templates, vars)); } catch (e) { console.error("error: " + e.message); process.exit(1); }