@jayfong/x-server 2.98.1 → 2.100.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.
@@ -112,7 +112,8 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
112
112
  _env_util.EnvUtil.outputTypes({
113
113
  cwd: process.cwd(),
114
114
  file: envFiles,
115
- outFile: 'env.d.ts'
115
+ outFile: 'env.d.ts',
116
+ channel: channel
116
117
  });
117
118
  (0, _vscodeGenerateIndexStandalone.generateManyIndex)({
118
119
  cwd: process.cwd(),
@@ -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,9 +120,23 @@ class EnvUtil {
120
120
  }
121
121
  return file;
122
122
  }
123
- static parseContent(src, _envItemMap, _envValueMap) {
123
+ static parseContent(src, _envItemMap, _envValueMap, channel) {
124
124
  const envs = [];
125
125
  const envObj = (0, _yaml.parse)(src);
126
+ if (channel) {
127
+ const channelEnvs = envObj.__CHANNEL__;
128
+ if (channelEnvs && Array.isArray(channelEnvs)) {
129
+ for (const channelEnv of channelEnvs) {
130
+ const channels = (0, _vtils.castArray)(channelEnv._).flatMap(item => item.split(','));
131
+ if (channels.includes(channel)) {
132
+ delete channelEnv._;
133
+ Object.assign(envObj, channelEnv);
134
+ break;
135
+ }
136
+ }
137
+ }
138
+ }
139
+ delete envObj.__CHANNEL__;
126
140
  const inlineVars = value => {
127
141
  if (Array.isArray(value)) {
128
142
  return value.map(inlineVars);
@@ -157,14 +171,17 @@ class EnvUtil {
157
171
  }
158
172
  static async parseFile(options) {
159
173
  const envItemMap = {};
160
- const envValueMap = {};
174
+ const envValueMap = {
175
+ APP_CHANNEL: options.channel
176
+ };
161
177
  for (const file of options.file) {
178
+ const isEnvMeta = file === '.env_meta';
162
179
  const envYmlFile = _nodePath.default.join(options.cwd, `${file}.yml`);
163
180
  const envYamlFile = _nodePath.default.join(options.cwd, `${file}.yaml`);
164
181
  const envFile = (await _fsExtra.default.pathExists(envYmlFile)) ? envYmlFile : (await _fsExtra.default.pathExists(envYamlFile)) ? envYamlFile : '';
165
182
  if (envFile) {
166
183
  const envContent = await _fsExtra.default.readFile(envFile, 'utf-8');
167
- EnvUtil.parseContent(envContent, envItemMap, envValueMap);
184
+ EnvUtil.parseContent(envContent, isEnvMeta ? undefined : envItemMap, envValueMap, options.channel);
168
185
  }
169
186
  }
170
187
  return Object.values(envItemMap);
package/lib/cli/cli.js CHANGED
@@ -109,7 +109,8 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
109
109
  EnvUtil.outputTypes({
110
110
  cwd: process.cwd(),
111
111
  file: envFiles,
112
- outFile: 'env.d.ts'
112
+ outFile: 'env.d.ts',
113
+ channel: channel
113
114
  });
114
115
  generateManyIndex({
115
116
  cwd: process.cwd(),
@@ -18,10 +18,11 @@ 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, _envItemMap?: Record<string, ParsedEnv>, _envValueMap?: Record<string, any>): ParsedEnv[];
21
+ static parseContent(src: string, _envItemMap?: Record<string, ParsedEnv>, _envValueMap?: Record<string, any>, channel?: string): ParsedEnv[];
22
22
  static parseFile(options: {
23
23
  cwd: string;
24
24
  file: string[];
25
+ channel?: string;
25
26
  }): Promise<ParsedEnv[]>;
26
27
  static parseFileAsMap(options: {
27
28
  cwd: string;
@@ -38,6 +39,7 @@ export declare class EnvUtil {
38
39
  cwd: string;
39
40
  file: string[];
40
41
  outFile: string;
42
+ channel?: string;
41
43
  }): Promise<void>;
42
44
  private static getTypesFromValue;
43
45
  }
@@ -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, get, isPlainObject, uniq } from 'vtils';
5
+ import { asyncLimit, castArray, 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) {
@@ -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,9 +115,23 @@ export class EnvUtil {
115
115
  }
116
116
  return file;
117
117
  }
118
- static parseContent(src, _envItemMap, _envValueMap) {
118
+ static parseContent(src, _envItemMap, _envValueMap, channel) {
119
119
  const envs = [];
120
120
  const envObj = yamlParse(src);
121
+ if (channel) {
122
+ const channelEnvs = envObj.__CHANNEL__;
123
+ if (channelEnvs && Array.isArray(channelEnvs)) {
124
+ for (const channelEnv of channelEnvs) {
125
+ const channels = castArray(channelEnv._).flatMap(item => item.split(','));
126
+ if (channels.includes(channel)) {
127
+ delete channelEnv._;
128
+ Object.assign(envObj, channelEnv);
129
+ break;
130
+ }
131
+ }
132
+ }
133
+ }
134
+ delete envObj.__CHANNEL__;
121
135
  const inlineVars = value => {
122
136
  if (Array.isArray(value)) {
123
137
  return value.map(inlineVars);
@@ -152,14 +166,17 @@ export class EnvUtil {
152
166
  }
153
167
  static async parseFile(options) {
154
168
  const envItemMap = {};
155
- const envValueMap = {};
169
+ const envValueMap = {
170
+ APP_CHANNEL: options.channel
171
+ };
156
172
  for (const file of options.file) {
173
+ const isEnvMeta = file === '.env_meta';
157
174
  const envYmlFile = path.join(options.cwd, `${file}.yml`);
158
175
  const envYamlFile = path.join(options.cwd, `${file}.yaml`);
159
176
  const envFile = (await fs.pathExists(envYmlFile)) ? envYmlFile : (await fs.pathExists(envYamlFile)) ? envYamlFile : '';
160
177
  if (envFile) {
161
178
  const envContent = await fs.readFile(envFile, 'utf-8');
162
- EnvUtil.parseContent(envContent, envItemMap, envValueMap);
179
+ EnvUtil.parseContent(envContent, isEnvMeta ? undefined : envItemMap, envValueMap, options.channel);
163
180
  }
164
181
  }
165
182
  return Object.values(envItemMap);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "2.98.1",
3
+ "version": "2.100.0",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",