This commit is contained in:
sokol
2026-02-18 11:38:25 +03:00
commit 83a5bb87c1
40 changed files with 5803 additions and 0 deletions

View File

@@ -0,0 +1,62 @@
import { IBuilder } from ".";
import { Env } from "../models/Env";
export class EnvBuilder implements IBuilder<Env> {
readonly ident = " ";
readonly newLine = "\r\n";
private stack: string[] = [];
private _src!: Env;
get src(): Env {
return this._src;
}
set src(v: Env) {
this._src = v;
}
build(): string {
return this
.open()
.params()
.close()
.toString();
}
private params(): this {
const tag = `<parameter name="{name}" value="{val}" />`;
for (let p of this.src.params) {
this.stack.push(this.ident);
this.stack.push(tag
.replace("{name}", p.name ?? "!ERR!")
.replace("{val}", p.sanitize(p.value) ?? "!ERR!")
);
this.stack.push(this.newLine);
}
return this;
}
private open(): EnvBuilder {
const tag = `<environment name="${this.src.name}">`;
this.stack.push(tag);
this.stack.push(this.newLine);
return this;
}
private close(): EnvBuilder {
const tag = `</environment>`;
this.stack.push(tag);
return this;
}
toString(): string {
let res = "";
while (this.stack.length > 0) {
res = this.stack.pop() + res;
}
return res;
}
}

26
src/builders/index.ts Normal file
View File

@@ -0,0 +1,26 @@
import { Env } from "../models/Env";
import { EnvBuilder } from "./EnvBuilder";
export interface IBuilder<T> {
get src(): T;
set src(v: T);
build(): string;
}
export class Builder {
public static getEnv(env: Env): IBuilder<Env> {
let b = new EnvBuilder();
b.src = env;
return b;
};
public static getEnvs(envs: Env[]): string {
return envs.map(x => Builder.getEnv(x).build()).join("\r\n");
}
}