@jayfong/x-server 2.72.2 → 2.73.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.
@@ -31,6 +31,9 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
31
31
  describe: '渠道',
32
32
  type: 'string'
33
33
  }), async argv => {
34
+ if (argv.channel === '') {
35
+ argv.channel = await _env_util.EnvUtil.chooseChannel(process.cwd());
36
+ }
34
37
  process.env.NODE_ENV = 'development';
35
38
  let lastRun;
36
39
  const run = () => {
@@ -102,6 +105,9 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
102
105
  describe: '渠道',
103
106
  type: 'string'
104
107
  }), async argv => {
108
+ if (argv.channel === '') {
109
+ argv.channel = await _env_util.EnvUtil.chooseChannel(process.cwd());
110
+ }
105
111
  process.env.NODE_ENV = 'production';
106
112
  const externals = (0, _vtils.castArray)(argv.external || []).flatMap(item => item.split(',')).filter(Boolean);
107
113
  const envFiles = _env_util.EnvUtil.getFile(process.env.NODE_ENV, argv.channel);
@@ -133,6 +139,9 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
133
139
  describe: '渠道',
134
140
  type: 'string'
135
141
  }), async argv => {
142
+ if (argv.channel === '') {
143
+ argv.channel = await _env_util.EnvUtil.chooseChannel(process.cwd());
144
+ }
136
145
  process.env.NODE_ENV = 'production';
137
146
  const envFiles = _env_util.EnvUtil.getFile(process.env.NODE_ENV, argv.channel);
138
147
  await _env_util.EnvUtil.importFile({
@@ -150,6 +159,9 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
150
159
  describe: '渠道',
151
160
  type: 'string'
152
161
  }), async argv => {
162
+ if (argv.channel === '') {
163
+ argv.channel = await _env_util.EnvUtil.chooseChannel(process.cwd());
164
+ }
153
165
  process.env.NODE_ENV = argv.production ? 'production' : 'development';
154
166
  const envFiles = _env_util.EnvUtil.getFile(process.env.NODE_ENV, argv.channel);
155
167
  await _env_util.EnvUtil.importFile({
@@ -188,6 +200,9 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
188
200
  describe: '使用 tsx 运行',
189
201
  type: 'boolean'
190
202
  }), async argv => {
203
+ if (argv.channel === '') {
204
+ argv.channel = await _env_util.EnvUtil.chooseChannel(process.cwd());
205
+ }
191
206
  process.env.NODE_ENV = argv.production ? 'production' : 'development';
192
207
  const envFiles = _env_util.EnvUtil.getFile(process.env.NODE_ENV, argv.channel);
193
208
  await _env_util.EnvUtil.importFile({
@@ -216,6 +231,9 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
216
231
  describe: '渠道',
217
232
  type: 'string'
218
233
  }), async argv => {
234
+ if (argv.channel === '') {
235
+ argv.channel = await _env_util.EnvUtil.chooseChannel(process.cwd());
236
+ }
219
237
  const deployEnvFiles = _env_util.EnvUtil.getFile('deploy', argv.channel, true);
220
238
  const deployEnv = await _env_util.EnvUtil.parseFileAsMap({
221
239
  cwd: process.cwd(),
@@ -5,9 +5,30 @@ exports.__esModule = true;
5
5
  exports.EnvUtil = void 0;
6
6
  var _nodePath = _interopRequireDefault(require("node:path"));
7
7
  var _fsExtra = _interopRequireDefault(require("fs-extra"));
8
+ var _globby = _interopRequireDefault(require("globby"));
9
+ var _inquirer = _interopRequireDefault(require("inquirer"));
8
10
  var _vtils = require("vtils");
9
11
  var _yaml = require("yaml");
10
12
  class EnvUtil {
13
+ static async chooseChannel(cwd) {
14
+ const channelFiles = await (0, _globby.default)(['.env@*.{yml,yaml}'], {
15
+ cwd: cwd,
16
+ onlyFiles: true,
17
+ absolute: false
18
+ });
19
+ if (channelFiles.length === 0) {
20
+ return undefined;
21
+ }
22
+ const channels = channelFiles.map(channel => channel.split('@').pop().split('.')[0]);
23
+ if (channels.length === 1) return channels[0];
24
+ const res = await _inquirer.default.prompt([{
25
+ name: 'channel',
26
+ type: 'select',
27
+ message: '请选择渠道',
28
+ choices: channels
29
+ }]);
30
+ return res.channel || undefined;
31
+ }
11
32
  static getFile(env, channel, noBase) {
12
33
  const file = noBase ? [] : ['.env'];
13
34
  if (!noBase && channel) {
package/lib/cli/cli.js CHANGED
@@ -28,6 +28,9 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
28
28
  describe: '渠道',
29
29
  type: 'string'
30
30
  }), async argv => {
31
+ if (argv.channel === '') {
32
+ argv.channel = await EnvUtil.chooseChannel(process.cwd());
33
+ }
31
34
  process.env.NODE_ENV = 'development';
32
35
  let lastRun;
33
36
  const run = () => {
@@ -99,6 +102,9 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
99
102
  describe: '渠道',
100
103
  type: 'string'
101
104
  }), async argv => {
105
+ if (argv.channel === '') {
106
+ argv.channel = await EnvUtil.chooseChannel(process.cwd());
107
+ }
102
108
  process.env.NODE_ENV = 'production';
103
109
  const externals = castArray(argv.external || []).flatMap(item => item.split(',')).filter(Boolean);
104
110
  const envFiles = EnvUtil.getFile(process.env.NODE_ENV, argv.channel);
@@ -130,6 +136,9 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
130
136
  describe: '渠道',
131
137
  type: 'string'
132
138
  }), async argv => {
139
+ if (argv.channel === '') {
140
+ argv.channel = await EnvUtil.chooseChannel(process.cwd());
141
+ }
133
142
  process.env.NODE_ENV = 'production';
134
143
  const envFiles = EnvUtil.getFile(process.env.NODE_ENV, argv.channel);
135
144
  await EnvUtil.importFile({
@@ -147,6 +156,9 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
147
156
  describe: '渠道',
148
157
  type: 'string'
149
158
  }), async argv => {
159
+ if (argv.channel === '') {
160
+ argv.channel = await EnvUtil.chooseChannel(process.cwd());
161
+ }
150
162
  process.env.NODE_ENV = argv.production ? 'production' : 'development';
151
163
  const envFiles = EnvUtil.getFile(process.env.NODE_ENV, argv.channel);
152
164
  await EnvUtil.importFile({
@@ -185,6 +197,9 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
185
197
  describe: '使用 tsx 运行',
186
198
  type: 'boolean'
187
199
  }), async argv => {
200
+ if (argv.channel === '') {
201
+ argv.channel = await EnvUtil.chooseChannel(process.cwd());
202
+ }
188
203
  process.env.NODE_ENV = argv.production ? 'production' : 'development';
189
204
  const envFiles = EnvUtil.getFile(process.env.NODE_ENV, argv.channel);
190
205
  await EnvUtil.importFile({
@@ -213,6 +228,9 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
213
228
  describe: '渠道',
214
229
  type: 'string'
215
230
  }), async argv => {
231
+ if (argv.channel === '') {
232
+ argv.channel = await EnvUtil.chooseChannel(process.cwd());
233
+ }
216
234
  const deployEnvFiles = EnvUtil.getFile('deploy', argv.channel, true);
217
235
  const deployEnv = await EnvUtil.parseFileAsMap({
218
236
  cwd: process.cwd(),
@@ -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 chooseChannel(cwd: string): Promise<string | undefined>;
12
13
  static getFile(env?: string, channel?: string, noBase?: boolean): string[];
13
14
  static parseContent(src: string): ParsedEnv[];
14
15
  static parseFile(options: {
@@ -1,8 +1,29 @@
1
1
  import path from 'node:path';
2
2
  import fs from 'fs-extra';
3
+ import globby from 'globby';
4
+ import inquirer from 'inquirer';
3
5
  import { dedent, escapeRegExp, isPlainObject } from 'vtils';
4
6
  import { parse as yamlParse } from 'yaml';
5
7
  export class EnvUtil {
8
+ static async chooseChannel(cwd) {
9
+ const channelFiles = await globby(['.env@*.{yml,yaml}'], {
10
+ cwd: cwd,
11
+ onlyFiles: true,
12
+ absolute: false
13
+ });
14
+ if (channelFiles.length === 0) {
15
+ return undefined;
16
+ }
17
+ const channels = channelFiles.map(channel => channel.split('@').pop().split('.')[0]);
18
+ if (channels.length === 1) return channels[0];
19
+ const res = await inquirer.prompt([{
20
+ name: 'channel',
21
+ type: 'select',
22
+ message: '请选择渠道',
23
+ choices: channels
24
+ }]);
25
+ return res.channel || undefined;
26
+ }
6
27
  static getFile(env, channel, noBase) {
7
28
  const file = noBase ? [] : ['.env'];
8
29
  if (!noBase && channel) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jayfong/x-server",
3
- "version": "2.72.2",
3
+ "version": "2.73.0",
4
4
  "license": "ISC",
5
5
  "sideEffects": false,
6
6
  "main": "lib/_cjs/index.js",
@@ -51,6 +51,7 @@
51
51
  "globby": "^11",
52
52
  "got": "^11.8.2",
53
53
  "http-errors": "^2.0.0",
54
+ "inquirer": "^12.5.0",
54
55
  "ioredis": "^5.3.2",
55
56
  "jsonwebtoken": "^8.5.1",
56
57
  "lru-cache": "^10.0.0",