@jayfong/x-server 2.78.3 → 2.79.1
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 +65 -59
- package/lib/_cjs/cli/env_util.js +13 -8
- package/lib/cli/cli.js +65 -59
- package/lib/cli/env_util.d.ts +2 -2
- package/lib/cli/env_util.js +14 -9
- package/package.json +1 -1
package/lib/_cjs/cli/cli.js
CHANGED
|
@@ -73,60 +73,63 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
73
73
|
describe: '渠道',
|
|
74
74
|
type: 'string'
|
|
75
75
|
}), async argv => {
|
|
76
|
-
|
|
77
|
-
argv.channel = await _env_util.EnvUtil.chooseChannel(process.cwd());
|
|
78
|
-
}
|
|
79
|
-
process.env.NODE_ENV = 'development';
|
|
80
|
-
let lastRun;
|
|
81
|
-
const run = () => {
|
|
82
|
-
lastRun = _dev_util.DevUtil.runFile({
|
|
83
|
-
file: 'src/main.ts',
|
|
84
|
-
cwd: process.cwd(),
|
|
85
|
-
runner: argv.tsx ? 'tsx' : 'esbuild-register'
|
|
86
|
-
});
|
|
87
|
-
};
|
|
88
|
-
if (argv.npc) {
|
|
89
|
-
const [server, vkey] = argv.npc.split('@');
|
|
90
|
-
(0, _execa.default)('docker', ['run', '--rm', 'ffdfgdfg/npc:v0.26.9', `-server=${server}`, `-vkey=${vkey}`, '-type=tcp'], {
|
|
91
|
-
cwd: process.cwd(),
|
|
92
|
-
stdio: 'inherit'
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
await _template_util.TemplateUtil.init(process.cwd());
|
|
96
|
-
const xsignoreFile = _path.default.join(process.cwd(), '.xsignore');
|
|
97
|
-
const xsignoreContent = (await _fsExtra.default.pathExists(xsignoreFile)) ? (await _fsExtra.default.readFile(xsignoreFile, 'utf-8')).trim().split(/[\r\n]+/g).filter(v => v && !v.startsWith('#')) : [];
|
|
98
|
-
const watcher = _chokidar.default.watch(['src', '.env', '.env*'], {
|
|
76
|
+
await _env_util.EnvUtil.withChannel({
|
|
99
77
|
cwd: process.cwd(),
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
onSuccess: filePath => {
|
|
118
|
-
console.log(`✔️ 索引文件已更新: ${filePath}`);
|
|
78
|
+
channel: argv.channel,
|
|
79
|
+
cb: async channel => {
|
|
80
|
+
process.env.NODE_ENV = 'development';
|
|
81
|
+
let lastRun;
|
|
82
|
+
const run = () => {
|
|
83
|
+
lastRun = _dev_util.DevUtil.runFile({
|
|
84
|
+
file: 'src/main.ts',
|
|
85
|
+
cwd: process.cwd(),
|
|
86
|
+
runner: argv.tsx ? 'tsx' : 'esbuild-register'
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
if (argv.npc) {
|
|
90
|
+
const [server, vkey] = argv.npc.split('@');
|
|
91
|
+
(0, _execa.default)('docker', ['run', '--rm', 'ffdfgdfg/npc:v0.26.9', `-server=${server}`, `-vkey=${vkey}`, '-type=tcp'], {
|
|
92
|
+
cwd: process.cwd(),
|
|
93
|
+
stdio: 'inherit'
|
|
94
|
+
});
|
|
119
95
|
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
96
|
+
await _template_util.TemplateUtil.init(process.cwd());
|
|
97
|
+
const xsignoreFile = _path.default.join(process.cwd(), '.xsignore');
|
|
98
|
+
const xsignoreContent = (await _fsExtra.default.pathExists(xsignoreFile)) ? (await _fsExtra.default.readFile(xsignoreFile, 'utf-8')).trim().split(/[\r\n]+/g).filter(v => v && !v.startsWith('#')) : [];
|
|
99
|
+
const watcher = _chokidar.default.watch(['src', '.env', '.env*'], {
|
|
100
|
+
cwd: process.cwd(),
|
|
101
|
+
ignored: ['**/*.test.*', ...xsignoreContent]
|
|
102
|
+
});
|
|
103
|
+
watcher.on('all', (0, _vtils.debounce)(async () => {
|
|
104
|
+
const envFiles = _env_util.EnvUtil.getFile(process.env.NODE_ENV, channel);
|
|
105
|
+
await _env_util.EnvUtil.importFile({
|
|
106
|
+
cwd: process.cwd(),
|
|
107
|
+
file: envFiles
|
|
108
|
+
});
|
|
109
|
+
_env_util.EnvUtil.outputTypes({
|
|
110
|
+
cwd: process.cwd(),
|
|
111
|
+
file: envFiles,
|
|
112
|
+
outFile: 'env.d.ts'
|
|
113
|
+
});
|
|
114
|
+
(0, _vscodeGenerateIndexStandalone.generateManyIndex)({
|
|
115
|
+
cwd: process.cwd(),
|
|
116
|
+
patterns: ['src/**/index.ts', 'node_modules/.x/*.ts', '!src/handlers/**/*', ...(argv.index || [])],
|
|
117
|
+
replaceFile: true,
|
|
118
|
+
onSuccess: filePath => {
|
|
119
|
+
console.log(`✔️ 索引文件已更新: ${filePath}`);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
if (lastRun) {
|
|
123
|
+
console.log('==== 重启服务中 ====');
|
|
124
|
+
lastRun.kill();
|
|
125
|
+
setTimeout(run, 0);
|
|
126
|
+
} else {
|
|
127
|
+
console.log('==== 启动服务中 ====');
|
|
128
|
+
run();
|
|
129
|
+
}
|
|
130
|
+
}, 30));
|
|
128
131
|
}
|
|
129
|
-
}
|
|
132
|
+
});
|
|
130
133
|
}).command('build', '构建', _ => _.positional('external', {
|
|
131
134
|
alias: 'e',
|
|
132
135
|
describe: '不应该被打的包',
|
|
@@ -207,16 +210,19 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
207
210
|
describe: '渠道',
|
|
208
211
|
type: 'string'
|
|
209
212
|
}), async argv => {
|
|
210
|
-
|
|
211
|
-
argv.channel = await _env_util.EnvUtil.chooseChannel(process.cwd());
|
|
212
|
-
}
|
|
213
|
-
process.env.NODE_ENV = 'production';
|
|
214
|
-
const envFiles = _env_util.EnvUtil.getFile(process.env.NODE_ENV, argv.channel);
|
|
215
|
-
await _env_util.EnvUtil.importFile({
|
|
213
|
+
await _env_util.EnvUtil.withChannel({
|
|
216
214
|
cwd: process.cwd(),
|
|
217
|
-
|
|
215
|
+
channel: argv.channel,
|
|
216
|
+
cb: async channel => {
|
|
217
|
+
process.env.NODE_ENV = 'production';
|
|
218
|
+
const envFiles = _env_util.EnvUtil.getFile(process.env.NODE_ENV, channel);
|
|
219
|
+
await _env_util.EnvUtil.importFile({
|
|
220
|
+
cwd: process.cwd(),
|
|
221
|
+
file: envFiles
|
|
222
|
+
});
|
|
223
|
+
await new _api_generator.ApiGenerator().start();
|
|
224
|
+
}
|
|
218
225
|
});
|
|
219
|
-
await new _api_generator.ApiGenerator().start();
|
|
220
226
|
}).command('prisma', 'prisma 代理,主要为了注入环境变量', _ => _.positional('production', {
|
|
221
227
|
alias: 'p',
|
|
222
228
|
describe: '是否生产模式',
|
package/lib/_cjs/cli/env_util.js
CHANGED
|
@@ -10,7 +10,7 @@ var _inquirer = _interopRequireDefault(require("inquirer"));
|
|
|
10
10
|
var _vtils = require("vtils");
|
|
11
11
|
var _yaml = require("yaml");
|
|
12
12
|
class EnvUtil {
|
|
13
|
-
static async getAllChannel(cwd) {
|
|
13
|
+
static async getAllChannel(cwd, excludeChannels) {
|
|
14
14
|
const channelFiles = await (0, _globby.default)(['.env@*'], {
|
|
15
15
|
cwd: cwd,
|
|
16
16
|
onlyFiles: true,
|
|
@@ -19,11 +19,14 @@ class EnvUtil {
|
|
|
19
19
|
if (channelFiles.length === 0) {
|
|
20
20
|
return [];
|
|
21
21
|
}
|
|
22
|
-
|
|
22
|
+
let channels = (0, _vtils.uniq)(channelFiles.map(channel => channel.split('@').pop().split('.')[0]));
|
|
23
|
+
if (excludeChannels?.length) {
|
|
24
|
+
channels = (0, _vtils.difference)(channels, excludeChannels);
|
|
25
|
+
}
|
|
23
26
|
return channels;
|
|
24
27
|
}
|
|
25
|
-
static async chooseChannel(cwd) {
|
|
26
|
-
const channels = await EnvUtil.getAllChannel(cwd);
|
|
28
|
+
static async chooseChannel(cwd, excludeChannels) {
|
|
29
|
+
const channels = await EnvUtil.getAllChannel(cwd, excludeChannels);
|
|
27
30
|
if (channels.length === 0) return undefined;
|
|
28
31
|
if (channels.length === 1) return channels[0];
|
|
29
32
|
const res = await _inquirer.default.prompt([{
|
|
@@ -35,12 +38,14 @@ class EnvUtil {
|
|
|
35
38
|
return res.channel || undefined;
|
|
36
39
|
}
|
|
37
40
|
static async withChannel(options) {
|
|
38
|
-
if (options.channel
|
|
39
|
-
const
|
|
41
|
+
if (options.channel?.startsWith('_')) {
|
|
42
|
+
const excludeChannels = options.channel.split('!')[1]?.split(',').filter(Boolean);
|
|
43
|
+
const channel = await EnvUtil.chooseChannel(options.cwd, excludeChannels);
|
|
40
44
|
console.log(`========= ${channel} =========`);
|
|
41
45
|
await options.cb(channel);
|
|
42
|
-
} else if (options.channel
|
|
43
|
-
const
|
|
46
|
+
} else if (options.channel?.startsWith('@')) {
|
|
47
|
+
const excludeChannels = options.channel.split('!')[1]?.split(',').filter(Boolean);
|
|
48
|
+
const channels = await EnvUtil.getAllChannel(options.cwd, excludeChannels);
|
|
44
49
|
for (const channel of channels) {
|
|
45
50
|
console.log(`========= ${channel} =========`);
|
|
46
51
|
await options.cb(channel);
|
package/lib/cli/cli.js
CHANGED
|
@@ -71,60 +71,63 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
71
71
|
describe: '渠道',
|
|
72
72
|
type: 'string'
|
|
73
73
|
}), async argv => {
|
|
74
|
-
|
|
75
|
-
argv.channel = await EnvUtil.chooseChannel(process.cwd());
|
|
76
|
-
}
|
|
77
|
-
process.env.NODE_ENV = 'development';
|
|
78
|
-
let lastRun;
|
|
79
|
-
const run = () => {
|
|
80
|
-
lastRun = DevUtil.runFile({
|
|
81
|
-
file: 'src/main.ts',
|
|
82
|
-
cwd: process.cwd(),
|
|
83
|
-
runner: argv.tsx ? 'tsx' : 'esbuild-register'
|
|
84
|
-
});
|
|
85
|
-
};
|
|
86
|
-
if (argv.npc) {
|
|
87
|
-
const [server, vkey] = argv.npc.split('@');
|
|
88
|
-
execa('docker', ['run', '--rm', 'ffdfgdfg/npc:v0.26.9', `-server=${server}`, `-vkey=${vkey}`, '-type=tcp'], {
|
|
89
|
-
cwd: process.cwd(),
|
|
90
|
-
stdio: 'inherit'
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
await TemplateUtil.init(process.cwd());
|
|
94
|
-
const xsignoreFile = path.join(process.cwd(), '.xsignore');
|
|
95
|
-
const xsignoreContent = (await fs.pathExists(xsignoreFile)) ? (await fs.readFile(xsignoreFile, 'utf-8')).trim().split(/[\r\n]+/g).filter(v => v && !v.startsWith('#')) : [];
|
|
96
|
-
const watcher = chokidar.watch(['src', '.env', '.env*'], {
|
|
74
|
+
await EnvUtil.withChannel({
|
|
97
75
|
cwd: process.cwd(),
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
onSuccess: filePath => {
|
|
116
|
-
console.log(`✔️ 索引文件已更新: ${filePath}`);
|
|
76
|
+
channel: argv.channel,
|
|
77
|
+
cb: async channel => {
|
|
78
|
+
process.env.NODE_ENV = 'development';
|
|
79
|
+
let lastRun;
|
|
80
|
+
const run = () => {
|
|
81
|
+
lastRun = DevUtil.runFile({
|
|
82
|
+
file: 'src/main.ts',
|
|
83
|
+
cwd: process.cwd(),
|
|
84
|
+
runner: argv.tsx ? 'tsx' : 'esbuild-register'
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
if (argv.npc) {
|
|
88
|
+
const [server, vkey] = argv.npc.split('@');
|
|
89
|
+
execa('docker', ['run', '--rm', 'ffdfgdfg/npc:v0.26.9', `-server=${server}`, `-vkey=${vkey}`, '-type=tcp'], {
|
|
90
|
+
cwd: process.cwd(),
|
|
91
|
+
stdio: 'inherit'
|
|
92
|
+
});
|
|
117
93
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
94
|
+
await TemplateUtil.init(process.cwd());
|
|
95
|
+
const xsignoreFile = path.join(process.cwd(), '.xsignore');
|
|
96
|
+
const xsignoreContent = (await fs.pathExists(xsignoreFile)) ? (await fs.readFile(xsignoreFile, 'utf-8')).trim().split(/[\r\n]+/g).filter(v => v && !v.startsWith('#')) : [];
|
|
97
|
+
const watcher = chokidar.watch(['src', '.env', '.env*'], {
|
|
98
|
+
cwd: process.cwd(),
|
|
99
|
+
ignored: ['**/*.test.*', ...xsignoreContent]
|
|
100
|
+
});
|
|
101
|
+
watcher.on('all', debounce(async () => {
|
|
102
|
+
const envFiles = EnvUtil.getFile(process.env.NODE_ENV, channel);
|
|
103
|
+
await EnvUtil.importFile({
|
|
104
|
+
cwd: process.cwd(),
|
|
105
|
+
file: envFiles
|
|
106
|
+
});
|
|
107
|
+
EnvUtil.outputTypes({
|
|
108
|
+
cwd: process.cwd(),
|
|
109
|
+
file: envFiles,
|
|
110
|
+
outFile: 'env.d.ts'
|
|
111
|
+
});
|
|
112
|
+
generateManyIndex({
|
|
113
|
+
cwd: process.cwd(),
|
|
114
|
+
patterns: ['src/**/index.ts', 'node_modules/.x/*.ts', '!src/handlers/**/*', ...(argv.index || [])],
|
|
115
|
+
replaceFile: true,
|
|
116
|
+
onSuccess: filePath => {
|
|
117
|
+
console.log(`✔️ 索引文件已更新: ${filePath}`);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
if (lastRun) {
|
|
121
|
+
console.log('==== 重启服务中 ====');
|
|
122
|
+
lastRun.kill();
|
|
123
|
+
setTimeout(run, 0);
|
|
124
|
+
} else {
|
|
125
|
+
console.log('==== 启动服务中 ====');
|
|
126
|
+
run();
|
|
127
|
+
}
|
|
128
|
+
}, 30));
|
|
126
129
|
}
|
|
127
|
-
}
|
|
130
|
+
});
|
|
128
131
|
}).command('build', '构建', _ => _.positional('external', {
|
|
129
132
|
alias: 'e',
|
|
130
133
|
describe: '不应该被打的包',
|
|
@@ -205,16 +208,19 @@ yargs.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
205
208
|
describe: '渠道',
|
|
206
209
|
type: 'string'
|
|
207
210
|
}), async argv => {
|
|
208
|
-
|
|
209
|
-
argv.channel = await EnvUtil.chooseChannel(process.cwd());
|
|
210
|
-
}
|
|
211
|
-
process.env.NODE_ENV = 'production';
|
|
212
|
-
const envFiles = EnvUtil.getFile(process.env.NODE_ENV, argv.channel);
|
|
213
|
-
await EnvUtil.importFile({
|
|
211
|
+
await EnvUtil.withChannel({
|
|
214
212
|
cwd: process.cwd(),
|
|
215
|
-
|
|
213
|
+
channel: argv.channel,
|
|
214
|
+
cb: async channel => {
|
|
215
|
+
process.env.NODE_ENV = 'production';
|
|
216
|
+
const envFiles = EnvUtil.getFile(process.env.NODE_ENV, channel);
|
|
217
|
+
await EnvUtil.importFile({
|
|
218
|
+
cwd: process.cwd(),
|
|
219
|
+
file: envFiles
|
|
220
|
+
});
|
|
221
|
+
await new ApiGenerator().start();
|
|
222
|
+
}
|
|
216
223
|
});
|
|
217
|
-
await new ApiGenerator().start();
|
|
218
224
|
}).command('prisma', 'prisma 代理,主要为了注入环境变量', _ => _.positional('production', {
|
|
219
225
|
alias: 'p',
|
|
220
226
|
describe: '是否生产模式',
|
package/lib/cli/env_util.d.ts
CHANGED
|
@@ -9,8 +9,8 @@ export declare class EnvUtil {
|
|
|
9
9
|
static RE_NEWLINES: RegExp;
|
|
10
10
|
static NEWLINES_MATCH: RegExp;
|
|
11
11
|
static COMMENT_MATCH: RegExp;
|
|
12
|
-
static getAllChannel(cwd: string): Promise<string[]>;
|
|
13
|
-
static chooseChannel(cwd: string): Promise<string | undefined>;
|
|
12
|
+
static getAllChannel(cwd: string, excludeChannels?: string[]): Promise<string[]>;
|
|
13
|
+
static chooseChannel(cwd: string, excludeChannels?: string[]): Promise<string | undefined>;
|
|
14
14
|
static withChannel(options: {
|
|
15
15
|
cwd: string;
|
|
16
16
|
channel?: string;
|
package/lib/cli/env_util.js
CHANGED
|
@@ -2,10 +2,10 @@ import path from 'node:path';
|
|
|
2
2
|
import fs from 'fs-extra';
|
|
3
3
|
import globby from 'globby';
|
|
4
4
|
import inquirer from 'inquirer';
|
|
5
|
-
import { dedent, escapeRegExp, isPlainObject, uniq } from 'vtils';
|
|
5
|
+
import { dedent, difference, escapeRegExp, isPlainObject, uniq } from 'vtils';
|
|
6
6
|
import { parse as yamlParse } from 'yaml';
|
|
7
7
|
export class EnvUtil {
|
|
8
|
-
static async getAllChannel(cwd) {
|
|
8
|
+
static async getAllChannel(cwd, excludeChannels) {
|
|
9
9
|
const channelFiles = await globby(['.env@*'], {
|
|
10
10
|
cwd: cwd,
|
|
11
11
|
onlyFiles: true,
|
|
@@ -14,11 +14,14 @@ export class EnvUtil {
|
|
|
14
14
|
if (channelFiles.length === 0) {
|
|
15
15
|
return [];
|
|
16
16
|
}
|
|
17
|
-
|
|
17
|
+
let channels = uniq(channelFiles.map(channel => channel.split('@').pop().split('.')[0]));
|
|
18
|
+
if (excludeChannels?.length) {
|
|
19
|
+
channels = difference(channels, excludeChannels);
|
|
20
|
+
}
|
|
18
21
|
return channels;
|
|
19
22
|
}
|
|
20
|
-
static async chooseChannel(cwd) {
|
|
21
|
-
const channels = await EnvUtil.getAllChannel(cwd);
|
|
23
|
+
static async chooseChannel(cwd, excludeChannels) {
|
|
24
|
+
const channels = await EnvUtil.getAllChannel(cwd, excludeChannels);
|
|
22
25
|
if (channels.length === 0) return undefined;
|
|
23
26
|
if (channels.length === 1) return channels[0];
|
|
24
27
|
const res = await inquirer.prompt([{
|
|
@@ -30,12 +33,14 @@ export class EnvUtil {
|
|
|
30
33
|
return res.channel || undefined;
|
|
31
34
|
}
|
|
32
35
|
static async withChannel(options) {
|
|
33
|
-
if (options.channel
|
|
34
|
-
const
|
|
36
|
+
if (options.channel?.startsWith('_')) {
|
|
37
|
+
const excludeChannels = options.channel.split('!')[1]?.split(',').filter(Boolean);
|
|
38
|
+
const channel = await EnvUtil.chooseChannel(options.cwd, excludeChannels);
|
|
35
39
|
console.log(`========= ${channel} =========`);
|
|
36
40
|
await options.cb(channel);
|
|
37
|
-
} else if (options.channel
|
|
38
|
-
const
|
|
41
|
+
} else if (options.channel?.startsWith('@')) {
|
|
42
|
+
const excludeChannels = options.channel.split('!')[1]?.split(',').filter(Boolean);
|
|
43
|
+
const channels = await EnvUtil.getAllChannel(options.cwd, excludeChannels);
|
|
39
44
|
for (const channel of channels) {
|
|
40
45
|
console.log(`========= ${channel} =========`);
|
|
41
46
|
await options.cb(channel);
|