mihomo-kit/tools/render.js
Sam Latsin 2557a9aa49 mihomo-kit: config kit for mihomo on nikki and FlClash
Templates + router script + browser constructor that build mihomo
profiles (router home/street, mobile) with optional OpenVPN (TOTP)
and Tailscale, one-command installer and maintenance commands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-08 00:57:28 +03:00

23 lines
839 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 of Object.keys(DEFAULTS)) if (k in process.env) vars[k] = process.env[k];
try {
process.stdout.write(render(templates, vars));
} catch (e) {
console.error("error: " + e.message);
process.exit(1);
}