@jayfong/x-server 2.96.2 → 2.98.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.
- package/lib/_cjs/cli/cli.js +0 -0
- package/lib/_cjs/cli/env_util.js +17 -1
- package/lib/cli/env_util.js +18 -2
- package/package.json +1 -1
package/lib/_cjs/cli/cli.js
CHANGED
|
File without changes
|
package/lib/_cjs/cli/env_util.js
CHANGED
|
@@ -123,10 +123,26 @@ class EnvUtil {
|
|
|
123
123
|
static parseContent(src) {
|
|
124
124
|
const envs = [];
|
|
125
125
|
const envObj = (0, _yaml.parse)(src);
|
|
126
|
+
const inlineVars = value => {
|
|
127
|
+
if (Array.isArray(value)) {
|
|
128
|
+
return value.map(inlineVars);
|
|
129
|
+
}
|
|
130
|
+
if ((0, _vtils.isPlainObject)(value)) {
|
|
131
|
+
return Object.keys(value).reduce((acc, key) => {
|
|
132
|
+
acc[key] = inlineVars(value[key]);
|
|
133
|
+
return acc;
|
|
134
|
+
}, {});
|
|
135
|
+
}
|
|
136
|
+
if (typeof value === 'string') {
|
|
137
|
+
return value.replace(/\{\{\s*(.+?)\s*\}\}/g, (_, key) => (0, _vtils.get)(envObj, key) || process.env[key] || '');
|
|
138
|
+
}
|
|
139
|
+
return value;
|
|
140
|
+
};
|
|
126
141
|
Object.keys(envObj).forEach(key => {
|
|
142
|
+
const value = inlineVars(envObj[key]);
|
|
127
143
|
envs.push({
|
|
128
144
|
key: key,
|
|
129
|
-
value:
|
|
145
|
+
value: value,
|
|
130
146
|
comment: src.match(new RegExp(`((#\\s*(.+?)\\s*[\\r\\n]+)+)\\s*${(0, _vtils.escapeRegExp)(key)}:`))?.[1].split(/(\r\n){2,}|\r{2,}|\n{2,}/g).pop()?.replace(/^#/gm, '').trim() || ''
|
|
131
147
|
});
|
|
132
148
|
});
|
package/lib/cli/env_util.js
CHANGED
|
@@ -2,7 +2,7 @@ import path from 'node:path';
|
|
|
2
2
|
import fs from 'fs-extra';
|
|
3
3
|
import globby from 'globby';
|
|
4
4
|
import { pinyin } from 'pinyin-pro';
|
|
5
|
-
import { asyncLimit, dedent, difference, escapeRegExp, isPlainObject, uniq } from 'vtils';
|
|
5
|
+
import { asyncLimit, dedent, difference, escapeRegExp, get, isPlainObject, uniq } from 'vtils';
|
|
6
6
|
import { parse as yamlParse } from 'yaml';
|
|
7
7
|
export class EnvUtil {
|
|
8
8
|
static async getAllChannel(cwd, excludeChannels) {
|
|
@@ -118,10 +118,26 @@ export class EnvUtil {
|
|
|
118
118
|
static parseContent(src) {
|
|
119
119
|
const envs = [];
|
|
120
120
|
const envObj = yamlParse(src);
|
|
121
|
+
const inlineVars = value => {
|
|
122
|
+
if (Array.isArray(value)) {
|
|
123
|
+
return value.map(inlineVars);
|
|
124
|
+
}
|
|
125
|
+
if (isPlainObject(value)) {
|
|
126
|
+
return Object.keys(value).reduce((acc, key) => {
|
|
127
|
+
acc[key] = inlineVars(value[key]);
|
|
128
|
+
return acc;
|
|
129
|
+
}, {});
|
|
130
|
+
}
|
|
131
|
+
if (typeof value === 'string') {
|
|
132
|
+
return value.replace(/\{\{\s*(.+?)\s*\}\}/g, (_, key) => get(envObj, key) || process.env[key] || '');
|
|
133
|
+
}
|
|
134
|
+
return value;
|
|
135
|
+
};
|
|
121
136
|
Object.keys(envObj).forEach(key => {
|
|
137
|
+
const value = inlineVars(envObj[key]);
|
|
122
138
|
envs.push({
|
|
123
139
|
key: key,
|
|
124
|
-
value:
|
|
140
|
+
value: value,
|
|
125
141
|
comment: src.match(new RegExp(`((#\\s*(.+?)\\s*[\\r\\n]+)+)\\s*${escapeRegExp(key)}:`))?.[1].split(/(\r\n){2,}|\r{2,}|\n{2,}/g).pop()?.replace(/^#/gm, '').trim() || ''
|
|
126
142
|
});
|
|
127
143
|
});
|