ai #1
@@ -63,11 +63,12 @@ export class Config {
|
|||||||
/**
|
/**
|
||||||
* Updates the template JSON by adding/updating params from the given environment.
|
* Updates the template JSON by adding/updating params from the given environment.
|
||||||
* Params are added as "!!! paramName": "@paramName@" placeholder pairs.
|
* Params are added as "!!! paramName": "@paramName@" placeholder pairs.
|
||||||
|
* If a param's @placeholder@ already exists in template, it won't be added.
|
||||||
* Existing template content is preserved.
|
* Existing template content is preserved.
|
||||||
*/
|
*/
|
||||||
updateTemplateFromEnv(env: Env) {
|
updateTemplateFromEnv(env: Env) {
|
||||||
let templateObj: Record<string, any> = {};
|
let templateObj: Record<string, any> = {};
|
||||||
|
|
||||||
// Try to parse existing template as JSON
|
// Try to parse existing template as JSON
|
||||||
try {
|
try {
|
||||||
if (this.template.content.trim()) {
|
if (this.template.content.trim()) {
|
||||||
@@ -81,9 +82,15 @@ export class Config {
|
|||||||
// Add/update params from the environment as placeholders
|
// Add/update params from the environment as placeholders
|
||||||
for (const param of env.params) {
|
for (const param of env.params) {
|
||||||
if (param.name && param.name.trim() !== "") {
|
if (param.name && param.name.trim() !== "") {
|
||||||
const placeholderKey = `!!! ${param.name}`;
|
|
||||||
const placeholderValue = `@${param.name}@`;
|
const placeholderValue = `@${param.name}@`;
|
||||||
templateObj[placeholderKey] = placeholderValue;
|
|
||||||
|
// Check if this placeholder already exists anywhere in the template
|
||||||
|
const placeholderAlreadyExists = this.template.content.includes(placeholderValue);
|
||||||
|
|
||||||
|
if (!placeholderAlreadyExists) {
|
||||||
|
const placeholderKey = `!!! ${param.name}`;
|
||||||
|
templateObj[placeholderKey] = placeholderValue;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user