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`;
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,14 @@ export class EnvBuilder implements IBuilder<Env> {
|
||||
this._src = v;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds XML for a single environment (static method for direct use)
|
||||
*/
|
||||
public buildEnv(env: Env): string {
|
||||
this.src = env;
|
||||
return this.build();
|
||||
}
|
||||
|
||||
build(): string {
|
||||
return this
|
||||
.open()
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
import { Env } from "../models/Env";
|
||||
import { EnvBuilder } from "./EnvBuilder";
|
||||
|
||||
|
||||
|
||||
|
||||
import { ConfigBuilder } from "./ConfigBuilder";
|
||||
|
||||
export interface IBuilder<T> {
|
||||
get src(): T;
|
||||
@@ -20,7 +17,9 @@ export class Builder {
|
||||
};
|
||||
|
||||
public static getEnvs(envs: Env[]): string {
|
||||
return envs.map(x => Builder.getEnv(x).build()).join("\r\n");
|
||||
return envs.map(x => Builder.getEnv(x).build()).join("\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
export { ConfigBuilder };
|
||||
|
||||
|
||||
Reference in New Issue
Block a user