@jayfong/x-server 2.98.0 → 2.98.1
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/env_util.js +15 -10
- package/lib/cli/env_util.d.ts +1 -1
- package/lib/cli/env_util.js +15 -10
- package/package.json +1 -1
package/lib/_cjs/cli/env_util.js
CHANGED
|
@@ -120,7 +120,7 @@ class EnvUtil {
|
|
|
120
120
|
}
|
|
121
121
|
return file;
|
|
122
122
|
}
|
|
123
|
-
static parseContent(src) {
|
|
123
|
+
static parseContent(src, _envItemMap, _envValueMap) {
|
|
124
124
|
const envs = [];
|
|
125
125
|
const envObj = (0, _yaml.parse)(src);
|
|
126
126
|
const inlineVars = value => {
|
|
@@ -134,35 +134,40 @@ class EnvUtil {
|
|
|
134
134
|
}, {});
|
|
135
135
|
}
|
|
136
136
|
if (typeof value === 'string') {
|
|
137
|
-
return value.replace(/\{\{\s*(.+?)\s*\}\}/g, (_, key) => (0, _vtils.get)(envObj, key) || process.env[key] || '');
|
|
137
|
+
return value.replace(/\{\{\s*(.+?)\s*\}\}/g, (_, key) => (0, _vtils.get)(_envValueMap || envObj, key) || process.env[key] || '');
|
|
138
138
|
}
|
|
139
139
|
return value;
|
|
140
140
|
};
|
|
141
141
|
Object.keys(envObj).forEach(key => {
|
|
142
142
|
const value = inlineVars(envObj[key]);
|
|
143
|
-
|
|
143
|
+
const envItem = {
|
|
144
144
|
key: key,
|
|
145
145
|
value: value,
|
|
146
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() || ''
|
|
147
|
-
}
|
|
147
|
+
};
|
|
148
|
+
if (_envItemMap) {
|
|
149
|
+
_envItemMap[key] = envItem;
|
|
150
|
+
}
|
|
151
|
+
if (_envValueMap) {
|
|
152
|
+
_envValueMap[key] = value;
|
|
153
|
+
}
|
|
154
|
+
envs.push(envItem);
|
|
148
155
|
});
|
|
149
156
|
return envs;
|
|
150
157
|
}
|
|
151
158
|
static async parseFile(options) {
|
|
152
|
-
const
|
|
159
|
+
const envItemMap = {};
|
|
160
|
+
const envValueMap = {};
|
|
153
161
|
for (const file of options.file) {
|
|
154
162
|
const envYmlFile = _nodePath.default.join(options.cwd, `${file}.yml`);
|
|
155
163
|
const envYamlFile = _nodePath.default.join(options.cwd, `${file}.yaml`);
|
|
156
164
|
const envFile = (await _fsExtra.default.pathExists(envYmlFile)) ? envYmlFile : (await _fsExtra.default.pathExists(envYamlFile)) ? envYamlFile : '';
|
|
157
165
|
if (envFile) {
|
|
158
166
|
const envContent = await _fsExtra.default.readFile(envFile, 'utf-8');
|
|
159
|
-
|
|
160
|
-
envs.forEach(env => {
|
|
161
|
-
envMap[env.key] = env;
|
|
162
|
-
});
|
|
167
|
+
EnvUtil.parseContent(envContent, envItemMap, envValueMap);
|
|
163
168
|
}
|
|
164
169
|
}
|
|
165
|
-
return Object.values(
|
|
170
|
+
return Object.values(envItemMap);
|
|
166
171
|
}
|
|
167
172
|
static async parseFileAsMap(options) {
|
|
168
173
|
const envsObj = {
|
package/lib/cli/env_util.d.ts
CHANGED
|
@@ -18,7 +18,7 @@ export declare class EnvUtil {
|
|
|
18
18
|
cb: (channel: string | undefined) => any;
|
|
19
19
|
}): Promise<void>;
|
|
20
20
|
static getFile(env?: string, channel?: string, noBase?: boolean): string[];
|
|
21
|
-
static parseContent(src: string): ParsedEnv[];
|
|
21
|
+
static parseContent(src: string, _envItemMap?: Record<string, ParsedEnv>, _envValueMap?: Record<string, any>): ParsedEnv[];
|
|
22
22
|
static parseFile(options: {
|
|
23
23
|
cwd: string;
|
|
24
24
|
file: string[];
|
package/lib/cli/env_util.js
CHANGED
|
@@ -115,7 +115,7 @@ export class EnvUtil {
|
|
|
115
115
|
}
|
|
116
116
|
return file;
|
|
117
117
|
}
|
|
118
|
-
static parseContent(src) {
|
|
118
|
+
static parseContent(src, _envItemMap, _envValueMap) {
|
|
119
119
|
const envs = [];
|
|
120
120
|
const envObj = yamlParse(src);
|
|
121
121
|
const inlineVars = value => {
|
|
@@ -129,35 +129,40 @@ export class EnvUtil {
|
|
|
129
129
|
}, {});
|
|
130
130
|
}
|
|
131
131
|
if (typeof value === 'string') {
|
|
132
|
-
return value.replace(/\{\{\s*(.+?)\s*\}\}/g, (_, key) => get(envObj, key) || process.env[key] || '');
|
|
132
|
+
return value.replace(/\{\{\s*(.+?)\s*\}\}/g, (_, key) => get(_envValueMap || envObj, key) || process.env[key] || '');
|
|
133
133
|
}
|
|
134
134
|
return value;
|
|
135
135
|
};
|
|
136
136
|
Object.keys(envObj).forEach(key => {
|
|
137
137
|
const value = inlineVars(envObj[key]);
|
|
138
|
-
|
|
138
|
+
const envItem = {
|
|
139
139
|
key: key,
|
|
140
140
|
value: value,
|
|
141
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() || ''
|
|
142
|
-
}
|
|
142
|
+
};
|
|
143
|
+
if (_envItemMap) {
|
|
144
|
+
_envItemMap[key] = envItem;
|
|
145
|
+
}
|
|
146
|
+
if (_envValueMap) {
|
|
147
|
+
_envValueMap[key] = value;
|
|
148
|
+
}
|
|
149
|
+
envs.push(envItem);
|
|
143
150
|
});
|
|
144
151
|
return envs;
|
|
145
152
|
}
|
|
146
153
|
static async parseFile(options) {
|
|
147
|
-
const
|
|
154
|
+
const envItemMap = {};
|
|
155
|
+
const envValueMap = {};
|
|
148
156
|
for (const file of options.file) {
|
|
149
157
|
const envYmlFile = path.join(options.cwd, `${file}.yml`);
|
|
150
158
|
const envYamlFile = path.join(options.cwd, `${file}.yaml`);
|
|
151
159
|
const envFile = (await fs.pathExists(envYmlFile)) ? envYmlFile : (await fs.pathExists(envYamlFile)) ? envYamlFile : '';
|
|
152
160
|
if (envFile) {
|
|
153
161
|
const envContent = await fs.readFile(envFile, 'utf-8');
|
|
154
|
-
|
|
155
|
-
envs.forEach(env => {
|
|
156
|
-
envMap[env.key] = env;
|
|
157
|
-
});
|
|
162
|
+
EnvUtil.parseContent(envContent, envItemMap, envValueMap);
|
|
158
163
|
}
|
|
159
164
|
}
|
|
160
|
-
return Object.values(
|
|
165
|
+
return Object.values(envItemMap);
|
|
161
166
|
}
|
|
162
167
|
static async parseFileAsMap(options) {
|
|
163
168
|
const envsObj = {
|