@jayfong/x-server 2.68.0 → 2.70.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.
@@ -26,10 +26,10 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
26
26
  }).positional('tsx', {
27
27
  describe: '使用 tsx 运行',
28
28
  type: 'boolean'
29
- }).positional('env', {
30
- describe: '环境变量文件',
31
- type: 'string',
32
- default: 'development'
29
+ }).positional('channel', {
30
+ alias: 'h',
31
+ describe: '渠道',
32
+ type: 'string'
33
33
  }), async argv => {
34
34
  process.env.NODE_ENV = 'development';
35
35
  let lastRun;
@@ -55,13 +55,14 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
55
55
  ignored: ['**/*.test.*', ...xsignoreContent]
56
56
  });
57
57
  watcher.on('all', (0, _vtils.debounce)(async () => {
58
+ const envFiles = _env_util.EnvUtil.getFile(process.env.NODE_ENV, argv.channel);
58
59
  await _env_util.EnvUtil.importFile({
59
60
  cwd: process.cwd(),
60
- file: ['.env', `.env.${argv.env}`]
61
+ file: envFiles
61
62
  });
62
63
  _env_util.EnvUtil.outputTypes({
63
64
  cwd: process.cwd(),
64
- file: ['.env'],
65
+ file: envFiles,
65
66
  outFile: 'env.d.ts'
66
67
  });
67
68
  (0, _vscodeGenerateIndexStandalone.generateManyIndex)({
@@ -96,16 +97,17 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
96
97
  describe: '是否不本地安装外部依赖',
97
98
  type: 'boolean',
98
99
  default: false
99
- }).positional('env', {
100
- describe: '环境变量文件',
101
- type: 'string',
102
- default: 'production'
100
+ }).positional('channel', {
101
+ alias: 'h',
102
+ describe: '渠道',
103
+ type: 'string'
103
104
  }), async argv => {
104
105
  process.env.NODE_ENV = 'production';
105
106
  const externals = (0, _vtils.castArray)(argv.external || []).flatMap(item => item.split(',')).filter(Boolean);
107
+ const envFiles = _env_util.EnvUtil.getFile(process.env.NODE_ENV, argv.channel);
106
108
  const envMap = await _env_util.EnvUtil.parseFileAsMap({
107
109
  cwd: process.cwd(),
108
- file: ['.env', `.env.${argv.env}`]
110
+ file: envFiles
109
111
  });
110
112
  envMap.NODE_ENV = 'production';
111
113
  await _template_util.TemplateUtil.init(process.cwd());
@@ -125,11 +127,16 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
125
127
  noInstall: argv['no-install']
126
128
  });
127
129
  console.log('构建成功');
128
- }).command('api', '生成 API', async () => {
130
+ }).command('api', '生成 API', _ => _.positional('channel', {
131
+ alias: 'h',
132
+ describe: '渠道',
133
+ type: 'string'
134
+ }), async argv => {
129
135
  process.env.NODE_ENV = 'production';
136
+ const envFiles = _env_util.EnvUtil.getFile(process.env.NODE_ENV, argv.channel);
130
137
  await _env_util.EnvUtil.importFile({
131
138
  cwd: process.cwd(),
132
- file: ['.env', `.env.${process.env.NODE_ENV}`]
139
+ file: envFiles
133
140
  });
134
141
  await new _api_generator.ApiGenerator().start();
135
142
  }).command('prisma', 'prisma 代理,主要为了注入环境变量', _ => _.positional('production', {
@@ -137,11 +144,16 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
137
144
  describe: '是否生产模式',
138
145
  type: 'boolean',
139
146
  default: false
147
+ }).positional('channel', {
148
+ alias: 'h',
149
+ describe: '渠道',
150
+ type: 'string'
140
151
  }), async argv => {
141
152
  process.env.NODE_ENV = argv.production ? 'production' : 'development';
153
+ const envFiles = _env_util.EnvUtil.getFile(process.env.NODE_ENV, argv.channel);
142
154
  await _env_util.EnvUtil.importFile({
143
155
  cwd: process.cwd(),
144
- file: ['.env', `.env.${process.env.NODE_ENV}`]
156
+ file: envFiles
145
157
  });
146
158
  // 之所以能成功是因为 Prisma 用的 dotenv 默认不会覆盖已经设置的环境变量
147
159
  // https://github.com/motdotla/dotenv#override
@@ -167,14 +179,19 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
167
179
  describe: '是否生产模式',
168
180
  type: 'boolean',
169
181
  default: false
182
+ }).positional('channel', {
183
+ alias: 'h',
184
+ describe: '渠道',
185
+ type: 'string'
170
186
  }).positional('tsx', {
171
187
  describe: '使用 tsx 运行',
172
188
  type: 'boolean'
173
189
  }), async argv => {
174
190
  process.env.NODE_ENV = argv.production ? 'production' : 'development';
191
+ const envFiles = _env_util.EnvUtil.getFile(process.env.NODE_ENV, argv.channel);
175
192
  await _env_util.EnvUtil.importFile({
176
193
  cwd: process.cwd(),
177
- file: ['.env', `.env.${process.env.NODE_ENV}`]
194
+ file: envFiles
178
195
  });
179
196
  process.env.DATABASE_URL = process.env.DATABASE_ACTION_URL || process.env.DATABASE_URL;
180
197
  if (!argv.script) {
@@ -193,15 +210,21 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
193
210
  describe: '类型',
194
211
  type: 'string',
195
212
  choices: ['env']
213
+ }).positional('channel', {
214
+ alias: 'h',
215
+ describe: '渠道',
216
+ type: 'string'
196
217
  }), async argv => {
218
+ const deployEnvFiles = _env_util.EnvUtil.getFile('deploy', argv.channel, true);
197
219
  const deployEnv = await _env_util.EnvUtil.parseFileAsMap({
198
220
  cwd: process.cwd(),
199
- file: ['.env.deploy']
221
+ file: deployEnvFiles
200
222
  });
201
223
  if (argv.type === 'env') {
224
+ const appEnvFiles = _env_util.EnvUtil.getFile('production', argv.channel);
202
225
  const appEnv = await _env_util.EnvUtil.parseFileAsMap({
203
226
  cwd: process.cwd(),
204
- file: ['.env', '.env.production']
227
+ file: appEnvFiles
205
228
  });
206
229
  await _deploy_util.DeployUtil.deployEnv({
207
230
  host: deployEnv.HOST,
@@ -8,6 +8,19 @@ var _fsExtra = _interopRequireDefault(require("fs-extra"));
8
8
  var _vtils = require("vtils");
9
9
  var _yaml = require("yaml");
10
10
  class EnvUtil {
11
+ static getFile(env, channel, noBase) {
12
+ const file = noBase ? [] : ['.env'];
13
+ if (!noBase && channel) {
14
+ file.push(`.env@${channel}`);
15
+ }
16
+ if (env) {
17
+ file.push(`.env.${env}`);
18
+ if (channel) {
19
+ file.push(`.env@${channel}.${env}`);
20
+ }
21
+ }
22
+ return file;
23
+ }
11
24
  static parseContent(src) {
12
25
  const envs = [];
13
26
  const envObj = (0, _yaml.parse)(src);
package/lib/cli/cli.js CHANGED
@@ -23,10 +23,10 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
23
23
  }).positional('tsx', {
24
24
  describe: '使用 tsx 运行',
25
25
  type: 'boolean'
26
- }).positional('env', {
27
- describe: '环境变量文件',
28
- type: 'string',
29
- default: 'development'
26
+ }).positional('channel', {
27
+ alias: 'h',
28
+ describe: '渠道',
29
+ type: 'string'
30
30
  }), async argv => {
31
31
  process.env.NODE_ENV = 'development';
32
32
  let lastRun;
@@ -52,13 +52,14 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
52
52
  ignored: ['**/*.test.*', ...xsignoreContent]
53
53
  });
54
54
  watcher.on('all', debounce(async () => {
55
+ const envFiles = EnvUtil.getFile(process.env.NODE_ENV, argv.channel);
55
56
  await EnvUtil.importFile({
56
57
  cwd: process.cwd(),
57
- file: ['.env', `.env.${argv.env}`]
58
+ file: envFiles
58
59
  });
59
60
  EnvUtil.outputTypes({
60
61
  cwd: process.cwd(),
61
- file: ['.env'],
62
+ file: envFiles,
62
63
  outFile: 'env.d.ts'
63
64
  });
64
65
  generateManyIndex({
@@ -93,16 +94,17 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
93
94
  describe: '是否不本地安装外部依赖',
94
95
  type: 'boolean',
95
96
  default: false
96
- }).positional('env', {
97
- describe: '环境变量文件',
98
- type: 'string',
99
- default: 'production'
97
+ }).positional('channel', {
98
+ alias: 'h',
99
+ describe: '渠道',
100
+ type: 'string'
100
101
  }), async argv => {
101
102
  process.env.NODE_ENV = 'production';
102
103
  const externals = castArray(argv.external || []).flatMap(item => item.split(',')).filter(Boolean);
104
+ const envFiles = EnvUtil.getFile(process.env.NODE_ENV, argv.channel);
103
105
  const envMap = await EnvUtil.parseFileAsMap({
104
106
  cwd: process.cwd(),
105
- file: ['.env', `.env.${argv.env}`]
107
+ file: envFiles
106
108
  });
107
109
  envMap.NODE_ENV = 'production';
108
110
  await TemplateUtil.init(process.cwd());
@@ -122,11 +124,16 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
122
124
  noInstall: argv['no-install']
123
125
  });
124
126
  console.log('构建成功');
125
- }).command('api', '生成 API', async () => {
127
+ }).command('api', '生成 API', _ => _.positional('channel', {
128
+ alias: 'h',
129
+ describe: '渠道',
130
+ type: 'string'
131
+ }), async argv => {
126
132
  process.env.NODE_ENV = 'production';
133
+ const envFiles = EnvUtil.getFile(process.env.NODE_ENV, argv.channel);
127
134
  await EnvUtil.importFile({
128
135
  cwd: process.cwd(),
129
- file: ['.env', `.env.${process.env.NODE_ENV}`]
136
+ file: envFiles
130
137
  });
131
138
  await new ApiGenerator().start();
132
139
  }).command('prisma', 'prisma 代理,主要为了注入环境变量', _ => _.positional('production', {
@@ -134,11 +141,16 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
134
141
  describe: '是否生产模式',
135
142
  type: 'boolean',
136
143
  default: false
144
+ }).positional('channel', {
145
+ alias: 'h',
146
+ describe: '渠道',
147
+ type: 'string'
137
148
  }), async argv => {
138
149
  process.env.NODE_ENV = argv.production ? 'production' : 'development';
150
+ const envFiles = EnvUtil.getFile(process.env.NODE_ENV, argv.channel);
139
151
  await EnvUtil.importFile({
140
152
  cwd: process.cwd(),
141
- file: ['.env', `.env.${process.env.NODE_ENV}`]
153
+ file: envFiles
142
154
  });
143
155
  // 之所以能成功是因为 Prisma 用的 dotenv 默认不会覆盖已经设置的环境变量
144
156
  // https://github.com/motdotla/dotenv#override
@@ -164,14 +176,19 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
164
176
  describe: '是否生产模式',
165
177
  type: 'boolean',
166
178
  default: false
179
+ }).positional('channel', {
180
+ alias: 'h',
181
+ describe: '渠道',
182
+ type: 'string'
167
183
  }).positional('tsx', {
168
184
  describe: '使用 tsx 运行',
169
185
  type: 'boolean'
170
186
  }), async argv => {
171
187
  process.env.NODE_ENV = argv.production ? 'production' : 'development';
188
+ const envFiles = EnvUtil.getFile(process.env.NODE_ENV, argv.channel);
172
189
  await EnvUtil.importFile({
173
190
  cwd: process.cwd(),
174
- file: ['.env', `.env.${process.env.NODE_ENV}`]
191
+ file: envFiles
175
192
  });
176
193
  process.env.DATABASE_URL = process.env.DATABASE_ACTION_URL || process.env.DATABASE_URL;
177
194
  if (!argv.script) {
@@ -190,15 +207,21 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
190
207
  describe: '类型',
191
208
  type: 'string',
192
209
  choices: ['env']
210
+ }).positional('channel', {
211
+ alias: 'h',
212
+ describe: '渠道',
213
+ type: 'string'
193
214
  }), async argv => {
215
+ const deployEnvFiles = EnvUtil.getFile('deploy', argv.channel, true);
194
216
  const deployEnv = await EnvUtil.parseFileAsMap({
195
217
  cwd: process.cwd(),
196
- file: ['.env.deploy']
218
+ file: deployEnvFiles
197
219
  });
198
220
  if (argv.type === 'env') {
221
+ const appEnvFiles = EnvUtil.getFile('production', argv.channel);
199
222
  const appEnv = await EnvUtil.parseFileAsMap({
200
223
  cwd: process.cwd(),
201
- file: ['.env', '.env.production']
224
+ file: appEnvFiles
202
225
  });
203
226
  await DeployUtil.deployEnv({
204
227
  host: deployEnv.HOST,
@@ -9,6 +9,7 @@ export declare class EnvUtil {
9
9
  static RE_NEWLINES: RegExp;
10
10
  static NEWLINES_MATCH: RegExp;
11
11
  static COMMENT_MATCH: RegExp;
12
+ static getFile(env?: string, channel?: string, noBase?: boolean): string[];
12
13
  static parseContent(src: string): ParsedEnv[];
13
14
  static parseFile(options: {
14
15
  cwd: string;
@@ -3,6 +3,19 @@ import fs from 'fs-extra';
3
3
  import { dedent, escapeRegExp, isPlainObject } from 'vtils';
4
4
  import { parse as yamlParse } from 'yaml';
5
5
  export class EnvUtil {
6
+ static getFile(env, channel, noBase) {
7
+ const file = noBase ? [] : ['.env'];
8
+ if (!noBase && channel) {
9
+ file.push(`.env@${channel}`);
10
+ }
11
+ if (env) {
12
+ file.push(`.env.${env}`);
13
+ if (channel) {
14
+ file.push(`.env@${channel}.${env}`);
15
+ }
16
+ }
17
+ return file;
18
+ }
6
19
  static parseContent(src) {
7
20
  const envs = [];
8
21
  const envObj = yamlParse(src);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "2.68.0",
3
+ "version": "2.70.0",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",