feat: add config download functionality
This commit is contained in:
39
src/builders/ConfigBuilder.ts
Normal file
39
src/builders/ConfigBuilder.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { Config } from "../models/Config";
|
||||
import { EnvBuilder } from "./EnvBuilder";
|
||||
|
||||
export class ConfigBuilder {
|
||||
/**
|
||||
* Builds a full XML config file with all environments and template.
|
||||
*/
|
||||
public static buildFullXml(config: Config): string {
|
||||
const lines: string[] = [];
|
||||
lines.push("<engine>");
|
||||
|
||||
// Add all environments
|
||||
for (const env of config.envs) {
|
||||
const envXml = new EnvBuilder().buildEnv(env);
|
||||
lines.push(envXml);
|
||||
}
|
||||
|
||||
// Add template
|
||||
lines.push(" <template>");
|
||||
lines.push(config.template.content);
|
||||
lines.push(" </template>");
|
||||
|
||||
lines.push("</engine>");
|
||||
return lines.join("\r\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates filename with timestamp: config_yy-dd-MM-HHmm.json.xml
|
||||
*/
|
||||
public static generateFilename(): string {
|
||||
const now = new Date();
|
||||
const yy = now.getFullYear().toString().slice(-2);
|
||||
const dd = String(now.getDate()).padStart(2, '0');
|
||||
const MM = String(now.getMonth() + 1).padStart(2, '0');
|
||||
const HH = String(now.getHours()).padStart(2, '0');
|
||||
const mm = String(now.getMinutes()).padStart(2, '0');
|
||||
return `config_${yy}-${dd}-${MM}-${HH}${mm}.json.xml`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user