mihomo-kit/tools/render.js
2026-10-09 17:39:40 +03:00

23 lines
863 B
JavaScript
Executable File

#!/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]*_/.test(k)) vars[k] = val;
try {
process.stdout.write(render(templates, vars));
} catch (e) {
console.error("error: " + e.message);
process.exit(1);
}