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