@jayfong/x-server 2.99.0 → 2.101.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(),
@@ -366,4 +367,12 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
366
367
  alias: 'h',
367
368
  describe: '渠道',
368
369
  type: 'string'
369
- }), deploy).parse();
370
+ }), deploy).command('get-channel', '获取渠道', async () => {
371
+ await _env_util.EnvUtil.withChannel({
372
+ cwd: process.cwd(),
373
+ channel: '_',
374
+ cb: async channel => {
375
+ console.log(channel);
376
+ }
377
+ });
378
+ }).parse();
@@ -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,7 +171,9 @@ 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) {
162
178
  const isEnvMeta = file === '.env_meta';
163
179
  const envYmlFile = _nodePath.default.join(options.cwd, `${file}.yml`);
@@ -165,7 +181,7 @@ class EnvUtil {
165
181
  const envFile = (await _fsExtra.default.pathExists(envYmlFile)) ? envYmlFile : (await _fsExtra.default.pathExists(envYamlFile)) ? envYamlFile : '';
166
182
  if (envFile) {
167
183
  const envContent = await _fsExtra.default.readFile(envFile, 'utf-8');
168
- EnvUtil.parseContent(envContent, isEnvMeta ? undefined : envItemMap, envValueMap);
184
+ EnvUtil.parseContent(envContent, isEnvMeta ? undefined : envItemMap, envValueMap, options.channel);
169
185
  }
170
186
  }
171
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(),
@@ -363,4 +364,12 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
363
364
  alias: 'h',
364
365
  describe: '渠道',
365
366
  type: 'string'
366
- }), deploy).parse();
367
+ }), deploy).command('get-channel', '获取渠道', async () => {
368
+ await EnvUtil.withChannel({
369
+ cwd: process.cwd(),
370
+ channel: '_',
371
+ cb: async channel => {
372
+ console.log(channel);
373
+ }
374
+ });
375
+ }).parse();
@@ -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) {
@@ -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,7 +166,9 @@ 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) {
157
173
  const isEnvMeta = file === '.env_meta';
158
174
  const envYmlFile = path.join(options.cwd, `${file}.yml`);
@@ -160,7 +176,7 @@ export class EnvUtil {
160
176
  const envFile = (await fs.pathExists(envYmlFile)) ? envYmlFile : (await fs.pathExists(envYamlFile)) ? envYamlFile : '';
161
177
  if (envFile) {
162
178
  const envContent = await fs.readFile(envFile, 'utf-8');
163
- EnvUtil.parseContent(envContent, isEnvMeta ? undefined : envItemMap, envValueMap);
179
+ EnvUtil.parseContent(envContent, isEnvMeta ? undefined : envItemMap, envValueMap, options.channel);
164
180
  }
165
181
  }
166
182
  return Object.values(envItemMap);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "2.99.0",
3
+ "version": "2.101.0",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",