@jsnw/srv-utils 1.2.0 → 1.3.0
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.
|
@@ -37,10 +37,10 @@ class ConfigLoader {
|
|
|
37
37
|
console.error(loadError.message);
|
|
38
38
|
process.exit(1);
|
|
39
39
|
}
|
|
40
|
-
const [processedYaml,
|
|
41
|
-
if (
|
|
42
|
-
for (const err of
|
|
43
|
-
console.error(
|
|
40
|
+
const [processedYaml, directiveErrors] = loader.processDirectives((0, node_path_1.dirname)(loader.resolveFilePath(path)), yaml);
|
|
41
|
+
if (directiveErrors && directiveErrors.length > 0) {
|
|
42
|
+
for (const err of directiveErrors)
|
|
43
|
+
console.error(`directive error: ${err.message}`);
|
|
44
44
|
process.exit(1);
|
|
45
45
|
}
|
|
46
46
|
const [validatedYaml, validateError] = loader.validateYaml(processedYaml, schema);
|
|
@@ -105,7 +105,7 @@ class ConfigLoader {
|
|
|
105
105
|
* @returns {ErrorResult<any, Error[]>}
|
|
106
106
|
* @protected
|
|
107
107
|
*/
|
|
108
|
-
|
|
108
|
+
processDirectives(mainYamlDirname, yaml) {
|
|
109
109
|
if (typeof yaml !== 'object')
|
|
110
110
|
return yaml;
|
|
111
111
|
const nodesToVisit = [yaml], errors = [];
|
|
@@ -113,32 +113,35 @@ class ConfigLoader {
|
|
|
113
113
|
const node = nodesToVisit[i];
|
|
114
114
|
if (typeof node !== 'object' || Array.isArray(node))
|
|
115
115
|
continue;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (
|
|
119
|
-
$includePaths
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
for (const path of $includePaths) {
|
|
127
|
-
const [loadedYaml, loadError] = this.loadYamlFile(this.resolveIncludePath(mainYamlDirname, path));
|
|
128
|
-
if (loadError) {
|
|
129
|
-
errors.push(loadError);
|
|
116
|
+
const nodeFields = Object.keys(node);
|
|
117
|
+
for (const field of nodeFields) {
|
|
118
|
+
if (field === '$include') {
|
|
119
|
+
const $includePaths = [];
|
|
120
|
+
if (typeof node['$include'] === 'string') {
|
|
121
|
+
$includePaths.push(node['$include']);
|
|
122
|
+
}
|
|
123
|
+
else if (Array.isArray(node['$include'])) {
|
|
124
|
+
$includePaths.push(...(node['$include']
|
|
125
|
+
.filter(v => v && typeof v === 'string' && v.trim() !== '')));
|
|
130
126
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
127
|
+
delete node['$include'];
|
|
128
|
+
for (const path of $includePaths) {
|
|
129
|
+
const [loadedYaml, loadError] = this.loadYamlFile(this.resolveIncludePath(mainYamlDirname, path));
|
|
130
|
+
if (loadError) {
|
|
131
|
+
errors.push(loadError);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
for (const [k, v] of Object.entries(loadedYaml))
|
|
135
|
+
node[k] = v;
|
|
136
|
+
}
|
|
134
137
|
}
|
|
135
138
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
139
|
+
else {
|
|
140
|
+
if (typeof node[field] === 'string' && /^\s*\$[A-Z0-9_]+$/.test(node[field]))
|
|
141
|
+
node[field] = process.env?.[node[field].trim().slice(1)] ?? '';
|
|
142
|
+
if (typeof node[field] === 'object' && !Array.isArray(node[field]))
|
|
143
|
+
nodesToVisit.push(node[field]);
|
|
144
|
+
}
|
|
142
145
|
}
|
|
143
146
|
}
|
|
144
147
|
return [yaml, errors];
|
|
@@ -40,7 +40,7 @@ export declare class ConfigLoader {
|
|
|
40
40
|
* @returns {ErrorResult<any, Error[]>}
|
|
41
41
|
* @protected
|
|
42
42
|
*/
|
|
43
|
-
protected
|
|
43
|
+
protected processDirectives(mainYamlDirname: string, yaml: any): ErrorResult<any, Error[]>;
|
|
44
44
|
private resolveFilePath;
|
|
45
45
|
/**
|
|
46
46
|
* @param {string} fromDirname
|
package/package.json
CHANGED