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

74
src/models/Config.tsx Normal file
View File

@@ -0,0 +1,74 @@
import { Env } from "./Env";
export class ConfigTemplate {
public static Empty: ConfigTemplate = new ConfigTemplate();
constructor(text: string = "") {
this._contentText = text;
this.extractParams();
}
private _contentText: string = "";
private _params: string[] = [];
public get content(): string {
return this._contentText;
}
public get Params(): string[] {
return [...this._params];
}
private extractParams() {
let regex = /@(\w+)@/g;
let matches;
let paramsSet = new Set<string>();
while ((matches = regex.exec(this._contentText)) !== null) {
if (matches.length > 1) {
paramsSet.add(matches[1]);
}
}
this._params = Array.from(paramsSet);
}
}
export class Config {
public static get ENV_NAME_PARAM(): string { return "env_name" };
public envs: Env[] = [];
public template: ConfigTemplate = ConfigTemplate.Empty;
addEnvs(envs: Env[]) {
this.envs = envs;
}
addTemplate(text: string) {
this.template = new ConfigTemplate(text);
}
getTemplateAsJson(): string {
try {
return this.template.content ;
} catch (error) {
console.error("Error converting template content to JSON:", error);
return "{}";
}
}
validateParams(): string[] {
const envKeys = this.envs.map(env => env.params.map(param => param.name)).flat();
const missingParams = this.template.Params.filter(param => param != Config.ENV_NAME_PARAM && !envKeys.includes(param));
if (missingParams.length > 0) {
console.error("Template: missing parameters in environments:", missingParams);
}
return missingParams;
}
}