Подготовить HY2XS к production-сборке
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
export async function exists(path: string): Promise<boolean> {
|
||||
return await Bun.file(path).exists();
|
||||
}
|
||||
|
||||
export async function readText(path: string): Promise<string> {
|
||||
return await Bun.file(path).text();
|
||||
}
|
||||
|
||||
export async function writeText(path: string, data: string, mode?: number): Promise<void> {
|
||||
await Bun.write(path, data);
|
||||
if (mode !== undefined) {
|
||||
const result = Bun.spawnSync(["chmod", mode.toString(8), path], {
|
||||
stdout: "pipe",
|
||||
stderr: "pipe"
|
||||
});
|
||||
if (!result.success) {
|
||||
throw new Error(`chmod failed for ${path}: ${result.stderr.toString()}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function renderTemplate(template: string, values: Record<string, string | number>): string {
|
||||
let rendered = template;
|
||||
for (const [key, value] of Object.entries(values)) {
|
||||
rendered = rendered.replaceAll(`{{${key}}}`, String(value));
|
||||
}
|
||||
return rendered;
|
||||
}
|
||||
Reference in New Issue
Block a user