@jayfong/x-server 2.98.0 → 2.99.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/env_util.js +17 -11
- package/lib/cli/env_util.d.ts +1 -1
- package/lib/cli/env_util.js +17 -11
- package/package.json +1 -1
package/lib/_cjs/cli/env_util.js
CHANGED
|
@@ -108,7 +108,7 @@ class EnvUtil {
|
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
110
|
static getFile(env, channel, noBase) {
|
|
111
|
-
const file = noBase ? [] : ['.env'];
|
|
111
|
+
const file = ['.env_meta', ...(noBase ? [] : ['.env'])];
|
|
112
112
|
if (!noBase && channel) {
|
|
113
113
|
file.push(`.env@${channel}`);
|
|
114
114
|
}
|
|
@@ -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,41 @@ 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) {
|
|
162
|
+
const isEnvMeta = file === '.env_meta';
|
|
154
163
|
const envYmlFile = _nodePath.default.join(options.cwd, `${file}.yml`);
|
|
155
164
|
const envYamlFile = _nodePath.default.join(options.cwd, `${file}.yaml`);
|
|
156
165
|
const envFile = (await _fsExtra.default.pathExists(envYmlFile)) ? envYmlFile : (await _fsExtra.default.pathExists(envYamlFile)) ? envYamlFile : '';
|
|
157
166
|
if (envFile) {
|
|
158
167
|
const envContent = await _fsExtra.default.readFile(envFile, 'utf-8');
|
|
159
|
-
|
|
160
|
-
envs.forEach(env => {
|
|
161
|
-
envMap[env.key] = env;
|
|
162
|
-
});
|
|
168
|
+
EnvUtil.parseContent(envContent, isEnvMeta ? undefined : envItemMap, envValueMap);
|
|
163
169
|
}
|
|
164
170
|
}
|
|
165
|
-
return Object.values(
|
|
171
|
+
return Object.values(envItemMap);
|
|
166
172
|
}
|
|
167
173
|
static async parseFileAsMap(options) {
|
|
168
174
|
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
|
@@ -103,7 +103,7 @@ export class EnvUtil {
|
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
105
|
static getFile(env, channel, noBase) {
|
|
106
|
-
const file = noBase ? [] : ['.env'];
|
|
106
|
+
const file = ['.env_meta', ...(noBase ? [] : ['.env'])];
|
|
107
107
|
if (!noBase && channel) {
|
|
108
108
|
file.push(`.env@${channel}`);
|
|
109
109
|
}
|
|
@@ -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,41 @@ 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) {
|
|
157
|
+
const isEnvMeta = file === '.env_meta';
|
|
149
158
|
const envYmlFile = path.join(options.cwd, `${file}.yml`);
|
|
150
159
|
const envYamlFile = path.join(options.cwd, `${file}.yaml`);
|
|
151
160
|
const envFile = (await fs.pathExists(envYmlFile)) ? envYmlFile : (await fs.pathExists(envYamlFile)) ? envYamlFile : '';
|
|
152
161
|
if (envFile) {
|
|
153
162
|
const envContent = await fs.readFile(envFile, 'utf-8');
|
|
154
|
-
|
|
155
|
-
envs.forEach(env => {
|
|
156
|
-
envMap[env.key] = env;
|
|
157
|
-
});
|
|
163
|
+
EnvUtil.parseContent(envContent, isEnvMeta ? undefined : envItemMap, envValueMap);
|
|
158
164
|
}
|
|
159
165
|
}
|
|
160
|
-
return Object.values(
|
|
166
|
+
return Object.values(envItemMap);
|
|
161
167
|
}
|
|
162
168
|
static async parseFileAsMap(options) {
|
|
163
169
|
const envsObj = {
|