feat: templates shell APT + rendu Mustache

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-04 21:04:51 +02:00
parent 8cce701715
commit 1153a4f7a1
5 changed files with 62 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
// server/templates/render.test.ts
import { describe, it, expect } from "vitest";
import { renderTemplate } from "./render.js";
describe("renderTemplate", () => {
it("rend check.sh.tpl sans proxy", () => {
const out = renderTemplate("apt/check.sh.tpl", { aptProxy: null });
expect(out).toContain("apt-get update -qq");
expect(out).toContain("===SU:SIMULATE===");
expect(out).not.toContain("http_proxy");
});
it("injecte le proxy quand fourni", () => {
const out = renderTemplate("apt/check.sh.tpl", { aptProxy: "http://cache:3142" });
expect(out).toContain('http_proxy="http://cache:3142"');
});
});
+16
View File
@@ -0,0 +1,16 @@
// server/templates/render.ts
import Mustache from "mustache";
import { readFileSync } from "node:fs";
import { resolve } from "node:path";
const TEMPLATES_ROOT = resolve(process.cwd(), "templates");
export interface TemplateVars {
aptProxy?: string | null;
}
export function renderTemplate(relPath: string, vars: TemplateVars): string {
const tpl = readFileSync(resolve(TEMPLATES_ROOT, relPath), "utf8");
// Mustache échappe le HTML par défaut; on désactive (ce sont des scripts shell).
return Mustache.render(tpl, vars, {}, { escape: (s) => s });
}