@extrahorizon/exh-cli 1.12.0-dev-151-7544bdb → 1.12.0-dev-153-e5a1b1d
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -17,17 +17,28 @@ async function buildTemplate(name, templateFilesByName, callChain = []) {
|
|
|
17
17
|
if (callChain.includes(name)) {
|
|
18
18
|
throw new Error(`Circular extension detected. ${renderCallChain(newCallChain)}`);
|
|
19
19
|
}
|
|
20
|
-
|
|
21
|
-
if (!templateFile) {
|
|
20
|
+
if (!templateFilesByName[name]) {
|
|
22
21
|
throw new Error(`Template file dependency ${name} not found!`);
|
|
23
22
|
}
|
|
23
|
+
const { variables, ...templateFile } = templateFilesByName[name];
|
|
24
|
+
if (variables && templateFile.outputs) {
|
|
25
|
+
templateFile.outputs = replaceVariables(templateFile.outputs, variables);
|
|
26
|
+
templateFilesByName[name] = templateFile;
|
|
27
|
+
}
|
|
28
|
+
let templateConfig;
|
|
24
29
|
if (templateFile.extends_template) {
|
|
25
|
-
|
|
30
|
+
templateConfig = await extendV1Template(name, templateFilesByName, newCallChain);
|
|
31
|
+
}
|
|
32
|
+
else if (templateFile.extendsTemplate) {
|
|
33
|
+
templateConfig = await extendV2Template(name, templateFilesByName, newCallChain);
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
templateConfig = { ...templateFile, name };
|
|
26
37
|
}
|
|
27
|
-
if (
|
|
28
|
-
|
|
38
|
+
if (!(0, utils_1.isV1Template)(templateConfig) && Object.keys(templateConfig.outputs || {}).length < 1) {
|
|
39
|
+
throw new Error(`Template '${name}' must have at least one output defined!`);
|
|
29
40
|
}
|
|
30
|
-
return
|
|
41
|
+
return templateConfig;
|
|
31
42
|
}
|
|
32
43
|
async function extendV1Template(name, templateFilesByName, callChain) {
|
|
33
44
|
const { extends_template, description, schema, fields } = templateFilesByName[name];
|
|
@@ -87,6 +98,40 @@ async function extendV2Template(name, templateFilesByName, callChain) {
|
|
|
87
98
|
outputs: newOutputs,
|
|
88
99
|
};
|
|
89
100
|
}
|
|
101
|
+
function replaceVariables(outputs, variables) {
|
|
102
|
+
const replaced = {};
|
|
103
|
+
const resolvedVariables = {};
|
|
104
|
+
for (const [varName, varValue] of Object.entries(variables)) {
|
|
105
|
+
resolvedVariables[varName] = resolveVariableValue(varValue);
|
|
106
|
+
}
|
|
107
|
+
for (const [key, value] of Object.entries(outputs)) {
|
|
108
|
+
let replacedValue = value;
|
|
109
|
+
for (const [varName, varValue] of Object.entries(resolvedVariables)) {
|
|
110
|
+
replacedValue = replacedValue
|
|
111
|
+
.replaceAll(`\${${varName}}`, varValue)
|
|
112
|
+
.replaceAll(`$${varName}`, varValue);
|
|
113
|
+
}
|
|
114
|
+
replaced[key] = replacedValue;
|
|
115
|
+
}
|
|
116
|
+
return replaced;
|
|
117
|
+
}
|
|
118
|
+
function resolveVariableValue(value) {
|
|
119
|
+
if (!value.startsWith('$')) {
|
|
120
|
+
return value;
|
|
121
|
+
}
|
|
122
|
+
const envVar = value.startsWith('${') && value.endsWith('}') ?
|
|
123
|
+
value.slice(2, -1) :
|
|
124
|
+
value.slice(1);
|
|
125
|
+
const validEnvPattern = /^[A-Z][A-Z0-9_]*$/;
|
|
126
|
+
if (!validEnvPattern.test(envVar)) {
|
|
127
|
+
throw new Error(`Invalid environment variable name ${envVar}. Environment variable names must contain only uppercase letters, numbers, and underscores and must start with a letter.`);
|
|
128
|
+
}
|
|
129
|
+
const resolved = process.env[envVar];
|
|
130
|
+
if (resolved === undefined) {
|
|
131
|
+
throw new Error(`Variable ${envVar} not found in environment`);
|
|
132
|
+
}
|
|
133
|
+
return resolved;
|
|
134
|
+
}
|
|
90
135
|
function v1ExtendingV2Error(extendsTemplate, callChain) {
|
|
91
136
|
return new Error(`You cannot extend a v2 template ('${extendsTemplate}') in a v1 template!` +
|
|
92
137
|
`In ${renderCallChain(callChain)}`);
|