@jayfong/x-server 2.12.7 → 2.12.15
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/api_generator.js +20 -54
- package/lib/_cjs/cli/build_util.js +16 -45
- package/lib/_cjs/cli/cli.js +6 -27
- package/lib/_cjs/cli/deploy_util.js +0 -12
- package/lib/_cjs/cli/env_util.js +16 -49
- package/lib/_cjs/cli/template_util.js +26 -29
- package/lib/_cjs/core/define_bus.js +9 -6
- package/lib/_cjs/core/define_cron.js +0 -2
- package/lib/_cjs/core/define_handler.js +10 -12
- package/lib/_cjs/core/define_hook.js +0 -2
- package/lib/_cjs/core/define_server.js +0 -2
- package/lib/_cjs/core/define_task.js +7 -13
- package/lib/_cjs/core/get_handler_url.js +1 -2
- package/lib/_cjs/core/handler.js +8 -29
- package/lib/_cjs/core/http_error.js +0 -3
- package/lib/_cjs/core/http_header.js +8 -12
- package/lib/_cjs/core/server.js +8 -41
- package/lib/_cjs/core/types.js +0 -7
- package/lib/_cjs/index.js +0 -72
- package/lib/_cjs/plugins/cors.js +0 -7
- package/lib/_cjs/plugins/file_parser.js +2 -9
- package/lib/_cjs/plugins/form_body_parser.js +0 -6
- package/lib/_cjs/plugins/ws_parser.js +0 -6
- package/lib/_cjs/plugins/xml_parser.js +0 -12
- package/lib/_cjs/services/cache.js +18 -58
- package/lib/_cjs/services/captcha.js +0 -14
- package/lib/_cjs/services/dingtalk.js +0 -14
- package/lib/_cjs/services/dispose.js +0 -9
- package/lib/_cjs/services/emoji.js +2 -5
- package/lib/_cjs/services/jwt.js +0 -21
- package/lib/_cjs/services/log.js +0 -17
- package/lib/_cjs/services/mail.js +0 -9
- package/lib/_cjs/services/pay.js +9 -40
- package/lib/_cjs/services/rate_limit.js +0 -12
- package/lib/_cjs/services/redis.js +0 -4
- package/lib/_cjs/services/request.js +14 -299
- package/lib/_cjs/services/sensitive_words.js +13 -19
- package/lib/_cjs/x.js +0 -11
- package/lib/cli/api_generator.js +20 -42
- package/lib/cli/build_util.js +16 -19
- package/lib/cli/cli.js +6 -12
- package/lib/cli/deploy_util.js +0 -4
- package/lib/cli/env_util.js +16 -37
- package/lib/cli/template_util.d.ts +1 -0
- package/lib/cli/template_util.js +26 -14
- package/lib/core/define_bus.js +7 -5
- package/lib/core/define_handler.js +10 -9
- package/lib/core/define_task.js +7 -6
- package/lib/core/get_handler_url.js +2 -1
- package/lib/core/handler.js +9 -22
- package/lib/core/http_header.js +6 -9
- package/lib/core/server.js +8 -31
- package/lib/core/types.js +0 -7
- package/lib/index.js +4 -3
- package/lib/plugins/cors.js +0 -3
- package/lib/plugins/file_parser.js +2 -5
- package/lib/plugins/form_body_parser.js +0 -3
- package/lib/plugins/ws_parser.js +0 -3
- package/lib/plugins/xml_parser.js +0 -10
- package/lib/services/cache.js +18 -52
- package/lib/services/captcha.js +0 -7
- package/lib/services/dingtalk.js +0 -7
- package/lib/services/dispose.js +0 -5
- package/lib/services/emoji.js +2 -3
- package/lib/services/jwt.js +0 -13
- package/lib/services/log.js +0 -8
- package/lib/services/mail.js +0 -3
- package/lib/services/pay.js +9 -30
- package/lib/services/rate_limit.js +0 -8
- package/lib/services/redis.js +0 -1
- package/lib/services/request.d.ts +3 -130
- package/lib/services/request.js +5 -274
- package/lib/services/sensitive_words.js +13 -15
- package/package.json +4 -28
- package/README.md +0 -51
- package/lib/_cjs/cli/register.js +0 -8
- package/lib/_cjs/client_helper.js +0 -26
- package/lib/_cjs/types/_formstream.js +0 -1
- package/lib/cli/register.d.ts +0 -1
- package/lib/cli/register.js +0 -5
- package/lib/client_helper.d.ts +0 -1
- package/lib/client_helper.js +0 -16
- package/lib/types/_formstream.d.ts +0 -49
- package/lib/types/_formstream.js +0 -0
|
@@ -1,41 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
6
|
-
|
|
7
5
|
exports.__esModule = true;
|
|
8
6
|
exports.ApiGenerator = void 0;
|
|
9
|
-
|
|
10
7
|
var parseComment = _interopRequireWildcard(require("comment-parser"));
|
|
11
|
-
|
|
12
8
|
var ts = _interopRequireWildcard(require("ts-morph"));
|
|
13
|
-
|
|
14
9
|
var _debug = _interopRequireDefault(require("debug"));
|
|
15
|
-
|
|
16
10
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
17
|
-
|
|
18
11
|
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
19
|
-
|
|
20
12
|
var _http_method = require("../core/http_method");
|
|
21
|
-
|
|
22
13
|
var _vtils = require("vtils");
|
|
23
|
-
|
|
24
14
|
class ApiGenerator {
|
|
25
15
|
constructor() {
|
|
26
16
|
this.debug = (0, _debug.default)('api');
|
|
27
17
|
this.cwd = process.cwd();
|
|
18
|
+
// cwd = '/Users/admin/Documents/jfWorks/x-server-test'
|
|
28
19
|
this.project = void 0;
|
|
29
20
|
}
|
|
30
|
-
|
|
31
21
|
getTypeBySymbol(symbol) {
|
|
32
22
|
return symbol.getTypeAtLocation(symbol.getDeclarations()[0] || symbol.getValueDeclarationOrThrow());
|
|
33
23
|
}
|
|
34
|
-
|
|
35
24
|
getComment(declaration) {
|
|
36
25
|
var _declaration$getLeadi;
|
|
37
|
-
|
|
38
|
-
const text = ((declaration == null ? void 0 : (_declaration$getLeadi = declaration.getLeadingCommentRanges()[0]) == null ? void 0 : _declaration$getLeadi.getText()) || '').trim();
|
|
26
|
+
const text = ((declaration == null || (_declaration$getLeadi = declaration.getLeadingCommentRanges()[0]) == null ? void 0 : _declaration$getLeadi.getText()) || '').trim();
|
|
39
27
|
const comment = parseComment.parse(text)[0];
|
|
40
28
|
const description = (comment == null ? void 0 : comment.description) || '';
|
|
41
29
|
const tags = new Map();
|
|
@@ -48,16 +36,12 @@ class ApiGenerator {
|
|
|
48
36
|
tags: tags
|
|
49
37
|
};
|
|
50
38
|
}
|
|
51
|
-
|
|
52
39
|
getCommentBySymbol(symbol) {
|
|
53
40
|
var _this$getComment;
|
|
54
|
-
|
|
55
41
|
return ((_this$getComment = this.getComment(symbol.getDeclarations()[0])) == null ? void 0 : _this$getComment.description) || '';
|
|
56
42
|
}
|
|
57
|
-
|
|
58
43
|
typeToApiData(type, _symbol) {
|
|
59
44
|
var _type$getSymbol, _type$getSymbol2, _type$getSymbol3;
|
|
60
|
-
|
|
61
45
|
// ws
|
|
62
46
|
if (((_type$getSymbol = type.getSymbol()) == null ? void 0 : _type$getSymbol.getName()) === 'SocketStream') {
|
|
63
47
|
return {
|
|
@@ -68,12 +52,11 @@ class ApiGenerator {
|
|
|
68
52
|
children: [],
|
|
69
53
|
enum: []
|
|
70
54
|
};
|
|
71
|
-
}
|
|
72
|
-
|
|
55
|
+
}
|
|
73
56
|
|
|
57
|
+
// XFile
|
|
74
58
|
if (((_type$getSymbol2 = type.getSymbol()) == null ? void 0 : _type$getSymbol2.getName()) === 'MultipartFile') {
|
|
75
59
|
const symbol = _symbol || type.getSymbol();
|
|
76
|
-
|
|
77
60
|
return {
|
|
78
61
|
name: 'file',
|
|
79
62
|
desc: symbol && this.getCommentBySymbol(symbol) || '',
|
|
@@ -83,25 +66,22 @@ class ApiGenerator {
|
|
|
83
66
|
enum: []
|
|
84
67
|
};
|
|
85
68
|
}
|
|
86
|
-
|
|
87
69
|
let isRequired = true;
|
|
88
70
|
let isUnion = type.isUnion();
|
|
89
71
|
const unionTypes = isUnion ? type.getUnionTypes().filter(item => !item.isBooleanLiteral() && !item.isNull() && !item.isUndefined()) : [];
|
|
90
72
|
isUnion = !!unionTypes.length;
|
|
91
|
-
|
|
92
73
|
if (isUnion) {
|
|
93
74
|
if (unionTypes.length === 1 && !unionTypes[0].isLiteral()) {
|
|
94
75
|
isUnion = false;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
76
|
+
}
|
|
77
|
+
// 兼容 prisma 生成的类型用 null 表示可选
|
|
78
|
+
isRequired = unionTypes.length === type.getUnionTypes().length;
|
|
79
|
+
// 必须用 getBaseTypeOfLiteralType 获取枚举字面量的原始类型
|
|
100
80
|
type = unionTypes[0].getBaseTypeOfLiteralType();
|
|
101
81
|
}
|
|
102
|
-
|
|
103
82
|
const isEnum = type.isEnum();
|
|
104
|
-
const enumData = isEnum ?
|
|
83
|
+
const enumData = isEnum ?
|
|
84
|
+
// @ts-ignore
|
|
105
85
|
type.compilerType.types.reduce((res, item) => {
|
|
106
86
|
res[item.getSymbol().getName()] = item.value;
|
|
107
87
|
return res;
|
|
@@ -114,11 +94,10 @@ class ApiGenerator {
|
|
|
114
94
|
const isString = isEnum ? typeof enumValues[0] === 'string' : type.isString() || ['Date'].includes(((_type$getSymbol3 = type.getSymbol()) == null ? void 0 : _type$getSymbol3.getName()) || '');
|
|
115
95
|
const isNumber = isEnum ? typeof enumValues[0] === 'number' : type.isNumber();
|
|
116
96
|
const isBoolean = type.isBoolean() || type.isUnion() && type.getUnionTypes().some(item => item.isBooleanLiteral()) && type.getUnionTypes().every(item => item.isBooleanLiteral() || item.isNull() || item.isUndefined());
|
|
117
|
-
const isObject = !isArray && !isString && !isNumber && !isBoolean && type.isObject() ||
|
|
97
|
+
const isObject = !isArray && !isString && !isNumber && !isBoolean && type.isObject() ||
|
|
98
|
+
// 将交集类型视为对象
|
|
118
99
|
isIntersection;
|
|
119
|
-
|
|
120
100
|
const symbol = _symbol || type.getSymbol();
|
|
121
|
-
|
|
122
101
|
const apiName = (symbol == null ? void 0 : symbol.getName()) || '__type';
|
|
123
102
|
const apiDesc = [symbol && this.getCommentBySymbol(symbol), isEnum && `枚举:${enumKeys.map((key, index) => `${key}->${enumValues[index]}`).join('; ')}`].filter(Boolean).join('\n');
|
|
124
103
|
const apiEnum = isUnion ? unionTypes.map(t => t.getLiteralValue()) : isEnum ? enumValues : [];
|
|
@@ -129,20 +108,21 @@ class ApiGenerator {
|
|
|
129
108
|
const compilerFactory = context.compilerFactory;
|
|
130
109
|
const rawChecker = type.compilerType.checker;
|
|
131
110
|
let symbols = [];
|
|
132
|
-
|
|
133
111
|
if (intersectionTypes) {
|
|
134
112
|
// https://github.com/microsoft/TypeScript/issues/38184
|
|
135
|
-
symbols = rawChecker.getAllPossiblePropertiesOfTypes(intersectionTypes.map(item => item.compilerType))
|
|
113
|
+
symbols = rawChecker.getAllPossiblePropertiesOfTypes(intersectionTypes.map(item => item.compilerType))
|
|
114
|
+
// https://github.com/dsherret/ts-morph/blob/a7072fcf6f9babb784b40f0326c80dea4563a4aa/packages/ts-morph/src/compiler/types/Type.ts#L296
|
|
136
115
|
.map(symbol => compilerFactory.getSymbol(symbol));
|
|
137
116
|
} else {
|
|
138
117
|
// symbols = type.getApparentProperties()
|
|
139
118
|
// https://github.com/microsoft/TypeScript/issues/38184
|
|
140
|
-
symbols = rawChecker.getAllPossiblePropertiesOfTypes([type.compilerType])
|
|
119
|
+
symbols = rawChecker.getAllPossiblePropertiesOfTypes([type.compilerType])
|
|
120
|
+
// https://github.com/dsherret/ts-morph/blob/a7072fcf6f9babb784b40f0326c80dea4563a4aa/packages/ts-morph/src/compiler/types/Type.ts#L296
|
|
141
121
|
.map(symbol => compilerFactory.getSymbol(symbol));
|
|
142
122
|
}
|
|
143
|
-
|
|
144
123
|
return symbols.map(symbol => {
|
|
145
|
-
return this.typeToApiData(!symbol.compilerSymbol.declarations ?
|
|
124
|
+
return this.typeToApiData(!symbol.compilerSymbol.declarations ?
|
|
125
|
+
// 对于复杂对象,没有定义的,通过 type 直接获取(在前面通过 getText 预处理得到)
|
|
146
126
|
compilerFactory.getType(symbol.compilerSymbol.type) : this.getTypeBySymbol(symbol), symbol);
|
|
147
127
|
});
|
|
148
128
|
}) : [];
|
|
@@ -155,10 +135,8 @@ class ApiGenerator {
|
|
|
155
135
|
children: apiChildren
|
|
156
136
|
};
|
|
157
137
|
}
|
|
158
|
-
|
|
159
138
|
apiDataToJsonSchema(apiData, jsonSchema = {}) {
|
|
160
139
|
jsonSchema.description = apiData.desc;
|
|
161
|
-
|
|
162
140
|
if (apiData.type === 'object') {
|
|
163
141
|
jsonSchema.type = 'object';
|
|
164
142
|
jsonSchema.properties = apiData.children.reduce((res, item) => {
|
|
@@ -172,18 +150,14 @@ class ApiGenerator {
|
|
|
172
150
|
jsonSchema.items = apiData.children.map(item => this.apiDataToJsonSchema(item))[0];
|
|
173
151
|
} else {
|
|
174
152
|
jsonSchema.type = apiData.type;
|
|
175
|
-
|
|
176
153
|
if (apiData.enum.length) {
|
|
177
154
|
jsonSchema.enum = apiData.enum;
|
|
178
155
|
}
|
|
179
156
|
}
|
|
180
|
-
|
|
181
157
|
return jsonSchema;
|
|
182
158
|
}
|
|
183
|
-
|
|
184
159
|
genYApiData(handles) {
|
|
185
160
|
const data = {};
|
|
186
|
-
|
|
187
161
|
for (const handle of handles) {
|
|
188
162
|
data[handle.category] = data[handle.category] || [];
|
|
189
163
|
data[handle.category].push(handle.handlerMethod === 'GET' ? {
|
|
@@ -237,14 +211,12 @@ class ApiGenerator {
|
|
|
237
211
|
res_body: JSON.stringify(handle.responseDataJsonSchema)
|
|
238
212
|
});
|
|
239
213
|
}
|
|
240
|
-
|
|
241
214
|
return Object.keys(data).map(cat => ({
|
|
242
215
|
name: cat,
|
|
243
216
|
desc: cat,
|
|
244
217
|
list: data[cat]
|
|
245
218
|
}));
|
|
246
219
|
}
|
|
247
|
-
|
|
248
220
|
async generate() {
|
|
249
221
|
this.debug('启动项目...');
|
|
250
222
|
this.project = new ts.Project({
|
|
@@ -256,11 +228,9 @@ class ApiGenerator {
|
|
|
256
228
|
const handlerGroup = sourceFile.getExportSymbols();
|
|
257
229
|
const handles = [];
|
|
258
230
|
this.debug('生成API文档...');
|
|
259
|
-
|
|
260
231
|
for (const handlerList of handlerGroup) {
|
|
261
232
|
const handlerListSourceFile = this.getTypeBySymbol(handlerList).getProperties()[0].getDeclarations()[0].getSourceFile();
|
|
262
233
|
const basePath = `/${handlerListSourceFile.getFilePath().replace('.ts', '').split('/src/handlers/')[1].replace(/(^|\/)index$/, '/').split('/').map(v => (0, _vtils.snakeCase)(v)).join('/')}/`.replace(/\/{2,}/g, '/');
|
|
263
|
-
|
|
264
234
|
for (const handler of handlerListSourceFile.getVariableStatements().filter(item => item.isExported())) {
|
|
265
235
|
// 重要:这一步必须,先调一遍 getText 获取看到的对象,后续对于复杂定义才不会报错
|
|
266
236
|
handler.getDeclarations().forEach(exp => {
|
|
@@ -271,12 +241,10 @@ class ApiGenerator {
|
|
|
271
241
|
this.debug('生成接口: %s ...', handlerPath);
|
|
272
242
|
const [requestType, responseType, methodType] = handlerExp.getType().getTypeArguments();
|
|
273
243
|
const handlerComment = this.getComment(handlerExp.getParent().getParent());
|
|
274
|
-
|
|
275
244
|
if (handlerComment.tags.has('private')) {
|
|
276
245
|
this.debug('跳过生成接口: %s', `${handlerPath}`);
|
|
277
246
|
continue;
|
|
278
247
|
}
|
|
279
|
-
|
|
280
248
|
const handlerCategory = (0, _vtils.pascalCase)(basePath) || 'Index';
|
|
281
249
|
const handlerName = handlerComment.description || handlerPath;
|
|
282
250
|
const handlerMethod = methodType.getLiteralValueOrThrow();
|
|
@@ -298,7 +266,6 @@ class ApiGenerator {
|
|
|
298
266
|
});
|
|
299
267
|
}
|
|
300
268
|
}
|
|
301
|
-
|
|
302
269
|
this.debug('写入文件...');
|
|
303
270
|
await Promise.all([_fsExtra.default.outputJSON(_nodePath.default.join(this.cwd, 'temp/api.json'), handles, {
|
|
304
271
|
spaces: 2
|
|
@@ -306,8 +273,7 @@ class ApiGenerator {
|
|
|
306
273
|
spaces: 2
|
|
307
274
|
})]);
|
|
308
275
|
}
|
|
276
|
+
}
|
|
309
277
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
278
|
+
// new ApiGenerator().generate()
|
|
313
279
|
exports.ApiGenerator = ApiGenerator;
|
|
@@ -1,60 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
6
|
-
|
|
7
5
|
exports.__esModule = true;
|
|
8
6
|
exports.BuildUtil = void 0;
|
|
9
|
-
|
|
10
7
|
var esbuild = _interopRequireWildcard(require("esbuild"));
|
|
11
|
-
|
|
12
8
|
var _compressing = _interopRequireDefault(require("compressing"));
|
|
13
|
-
|
|
14
9
|
var _execa = _interopRequireDefault(require("execa"));
|
|
15
|
-
|
|
16
10
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
17
|
-
|
|
18
11
|
var _globby = _interopRequireDefault(require("globby"));
|
|
19
|
-
|
|
20
12
|
var _nodePath = _interopRequireDefault(require("node:path"));
|
|
21
|
-
|
|
22
13
|
var _vtils = require("vtils");
|
|
23
|
-
|
|
24
14
|
class BuildUtil {
|
|
25
15
|
static async build(options) {
|
|
26
16
|
var _options$minify, _options$inlineEnvs;
|
|
27
|
-
|
|
28
17
|
const mainFile = _nodePath.default.join(options.cwd, 'src/main.ts');
|
|
29
|
-
|
|
30
18
|
const pkgFile = _nodePath.default.join(options.cwd, 'package.json');
|
|
31
|
-
|
|
32
19
|
const pkgContent = await _fsExtra.default.readJson(pkgFile);
|
|
33
|
-
|
|
34
20
|
const distDir = _nodePath.default.join(options.cwd, 'dist');
|
|
35
|
-
|
|
36
21
|
const tempDir = _nodePath.default.join(options.cwd, 'temp');
|
|
37
|
-
|
|
38
22
|
const distMainFile = _nodePath.default.join(distDir, 'main.js');
|
|
39
|
-
|
|
40
23
|
const distPkgFile = _nodePath.default.join(distDir, 'package.json');
|
|
41
|
-
|
|
42
24
|
const distPm2File = _nodePath.default.join(distDir, 'pm2.config.js');
|
|
43
|
-
|
|
44
25
|
const distNoInstallFile = _nodePath.default.join(distDir, 'no_install.lock');
|
|
45
|
-
|
|
46
26
|
const distBundleFile = _nodePath.default.join(tempDir, `app.${pkgContent.version}.tgz`);
|
|
47
|
-
|
|
48
27
|
await _fsExtra.default.ensureDir(distDir);
|
|
49
|
-
await _fsExtra.default.ensureDir(tempDir);
|
|
28
|
+
await _fsExtra.default.ensureDir(tempDir);
|
|
50
29
|
|
|
30
|
+
// 处理 external
|
|
51
31
|
const external = (0, _vtils.uniq)(options.external || []);
|
|
52
32
|
const externalWithVersions = (await Promise.all(external.map(async item => {
|
|
53
33
|
try {
|
|
54
34
|
// 为何不用 require.resolve:
|
|
55
35
|
// Package subpath './package.json' is not defined by "exports"
|
|
56
36
|
const itemPkgFile = _nodePath.default.join(process.cwd(), `node_modules/${item}/package.json`);
|
|
57
|
-
|
|
58
37
|
const itemPkgContent = await _fsExtra.default.readJson(itemPkgFile);
|
|
59
38
|
return {
|
|
60
39
|
name: item,
|
|
@@ -66,17 +45,17 @@ class BuildUtil {
|
|
|
66
45
|
version: ''
|
|
67
46
|
};
|
|
68
47
|
}
|
|
69
|
-
}))).filter(item => !!item.version);
|
|
48
|
+
}))).filter(item => !!item.version);
|
|
70
49
|
|
|
50
|
+
// fix: hexoid 构建问题
|
|
71
51
|
try {
|
|
72
52
|
const hexoidPackageJsonFile = require.resolve('hexoid/package.json');
|
|
73
|
-
|
|
74
53
|
const pkg = await _fsExtra.default.readJson(hexoidPackageJsonFile);
|
|
75
54
|
delete pkg.module;
|
|
76
55
|
await _fsExtra.default.writeJson(hexoidPackageJsonFile, pkg);
|
|
77
|
-
} catch {}
|
|
78
|
-
|
|
56
|
+
} catch {}
|
|
79
57
|
|
|
58
|
+
// 构建
|
|
80
59
|
await _fsExtra.default.emptyDir(distDir);
|
|
81
60
|
await esbuild.build({
|
|
82
61
|
entryPoints: [mainFile],
|
|
@@ -102,7 +81,6 @@ class BuildUtil {
|
|
|
102
81
|
},
|
|
103
82
|
plugins: [{
|
|
104
83
|
name: 'extract-assets',
|
|
105
|
-
|
|
106
84
|
setup(build) {
|
|
107
85
|
build.onLoad({
|
|
108
86
|
filter: /\/svg-captcha\/lib\/option-manager\.js$/
|
|
@@ -130,11 +108,8 @@ class BuildUtil {
|
|
|
130
108
|
filter: /\/vm2\/lib\/vm\.js$/
|
|
131
109
|
}, async args => {
|
|
132
110
|
let js = await _fsExtra.default.readFile(args.path, 'utf-8');
|
|
133
|
-
|
|
134
111
|
const jsDir = _nodePath.default.dirname(args.path);
|
|
135
|
-
|
|
136
112
|
const assetsDir = _nodePath.default.join(distDir, 'assets/vm2');
|
|
137
|
-
|
|
138
113
|
await _fsExtra.default.ensureDir(assetsDir);
|
|
139
114
|
js = js.replace(/__dirname/g, '"./assets/vm2"');
|
|
140
115
|
await Promise.all([_fsExtra.default.copyFile(_nodePath.default.join(jsDir, 'bridge.js'), _nodePath.default.join(assetsDir, 'bridge.js')), _fsExtra.default.copyFile(_nodePath.default.join(jsDir, 'setup-sandbox.js'), _nodePath.default.join(assetsDir, 'setup-sandbox.js'))]);
|
|
@@ -144,31 +119,29 @@ class BuildUtil {
|
|
|
144
119
|
};
|
|
145
120
|
});
|
|
146
121
|
}
|
|
147
|
-
|
|
148
122
|
}]
|
|
149
|
-
});
|
|
123
|
+
});
|
|
150
124
|
|
|
125
|
+
// 兼容 prisma
|
|
151
126
|
const prismaSchemaFile = _nodePath.default.join(options.cwd, 'src/db/schema.prisma');
|
|
152
|
-
|
|
153
127
|
if (await _fsExtra.default.pathExists(prismaSchemaFile)) {
|
|
154
128
|
// 复制 schema.prisma
|
|
155
129
|
const distPrismaSchemaFile = _nodePath.default.join(distDir, _nodePath.default.basename(prismaSchemaFile));
|
|
130
|
+
await _fsExtra.default.copyFile(prismaSchemaFile, distPrismaSchemaFile);
|
|
156
131
|
|
|
157
|
-
|
|
158
|
-
|
|
132
|
+
// 复制查询引擎
|
|
159
133
|
const libqueryEngineFiles = await (0, _globby.default)('libquery_engine-*', {
|
|
160
134
|
cwd: _nodePath.default.join(options.cwd, 'node_modules/.prisma/client'),
|
|
161
135
|
ignore: ['libquery_engine-{darwin,windows}*'],
|
|
162
136
|
onlyFiles: true,
|
|
163
137
|
absolute: true
|
|
164
138
|
});
|
|
165
|
-
|
|
166
139
|
for (const libqueryEngineFile of libqueryEngineFiles) {
|
|
167
140
|
await _fsExtra.default.copyFile(libqueryEngineFile, _nodePath.default.join(distDir, _nodePath.default.basename(libqueryEngineFile)));
|
|
168
141
|
}
|
|
169
|
-
}
|
|
170
|
-
|
|
142
|
+
}
|
|
171
143
|
|
|
144
|
+
// 写入 pkg
|
|
172
145
|
const deps = externalWithVersions.reduce((res, item) => {
|
|
173
146
|
res[item.name] = item.version;
|
|
174
147
|
return res;
|
|
@@ -178,8 +151,9 @@ class BuildUtil {
|
|
|
178
151
|
version: pkgContent.version,
|
|
179
152
|
dependencies: deps
|
|
180
153
|
};
|
|
181
|
-
await _fsExtra.default.writeJSON(distPkgFile, distPkgContent);
|
|
154
|
+
await _fsExtra.default.writeJSON(distPkgFile, distPkgContent);
|
|
182
155
|
|
|
156
|
+
// 写入 pm2 配置
|
|
183
157
|
await _fsExtra.default.writeFile(distPm2File, (0, _vtils.dedent)`
|
|
184
158
|
module.exports = {
|
|
185
159
|
apps: [
|
|
@@ -191,7 +165,6 @@ class BuildUtil {
|
|
|
191
165
|
],
|
|
192
166
|
}
|
|
193
167
|
`);
|
|
194
|
-
|
|
195
168
|
if (externalWithVersions.length) {
|
|
196
169
|
if (options.noInstall) {
|
|
197
170
|
await _fsExtra.default.writeFile(distNoInstallFile, '');
|
|
@@ -208,12 +181,10 @@ class BuildUtil {
|
|
|
208
181
|
}
|
|
209
182
|
});
|
|
210
183
|
}
|
|
211
|
-
}
|
|
212
|
-
|
|
184
|
+
}
|
|
213
185
|
|
|
186
|
+
// 打包为 tgz
|
|
214
187
|
await _compressing.default.tgz.compressDir(distDir, distBundleFile);
|
|
215
188
|
}
|
|
216
|
-
|
|
217
189
|
}
|
|
218
|
-
|
|
219
190
|
exports.BuildUtil = BuildUtil;
|
package/lib/_cjs/cli/cli.js
CHANGED
|
@@ -2,27 +2,16 @@
|
|
|
2
2
|
"use strict";
|
|
3
3
|
|
|
4
4
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
5
|
-
|
|
6
5
|
var _chokidar = _interopRequireDefault(require("chokidar"));
|
|
7
|
-
|
|
8
6
|
var _execa = _interopRequireDefault(require("execa"));
|
|
9
|
-
|
|
10
7
|
var _yargs = _interopRequireDefault(require("yargs"));
|
|
11
|
-
|
|
12
8
|
var _api_generator = require("./api_generator");
|
|
13
|
-
|
|
14
9
|
var _build_util = require("./build_util");
|
|
15
|
-
|
|
16
10
|
var _vtils = require("vtils");
|
|
17
|
-
|
|
18
11
|
var _deploy_util = require("./deploy_util");
|
|
19
|
-
|
|
20
12
|
var _env_util = require("./env_util");
|
|
21
|
-
|
|
22
13
|
var _vscodeGenerateIndexStandalone = require("vscode-generate-index-standalone");
|
|
23
|
-
|
|
24
14
|
var _template_util = require("./template_util");
|
|
25
|
-
|
|
26
15
|
_yargs.default.command('dev', '开始开发', _ => _.positional('index', {
|
|
27
16
|
alias: 'i',
|
|
28
17
|
describe: '额外需要生成的索引文件',
|
|
@@ -34,14 +23,12 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
34
23
|
}), async argv => {
|
|
35
24
|
process.env.NODE_ENV = 'development';
|
|
36
25
|
let lastRun;
|
|
37
|
-
|
|
38
26
|
const run = () => {
|
|
39
|
-
lastRun = (0, _execa.default)('
|
|
27
|
+
lastRun = (0, _execa.default)('tsx', ['src/main.ts'], {
|
|
40
28
|
cwd: process.cwd(),
|
|
41
29
|
stdio: 'inherit'
|
|
42
30
|
});
|
|
43
31
|
};
|
|
44
|
-
|
|
45
32
|
if (argv.npc) {
|
|
46
33
|
const [server, vkey] = argv.npc.split('@');
|
|
47
34
|
(0, _execa.default)('docker', ['run', '--rm', 'ffdfgdfg/npc:v0.26.9', `-server=${server}`, `-vkey=${vkey}`, '-type=tcp'], {
|
|
@@ -49,25 +36,21 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
49
36
|
stdio: 'inherit'
|
|
50
37
|
});
|
|
51
38
|
}
|
|
52
|
-
|
|
53
39
|
await _template_util.TemplateUtil.init(process.cwd());
|
|
54
|
-
|
|
55
40
|
const watcher = _chokidar.default.watch(['src', '.env', '.env.*'], {
|
|
56
|
-
cwd: process.cwd()
|
|
41
|
+
cwd: process.cwd(),
|
|
42
|
+
ignored: '**/*.test.*'
|
|
57
43
|
});
|
|
58
|
-
|
|
59
44
|
watcher.on('all', (0, _vtils.debounce)(async () => {
|
|
60
45
|
await _env_util.EnvUtil.importFile({
|
|
61
46
|
cwd: process.cwd(),
|
|
62
47
|
file: '.env'
|
|
63
48
|
});
|
|
64
|
-
|
|
65
49
|
_env_util.EnvUtil.outputTypes({
|
|
66
50
|
cwd: process.cwd(),
|
|
67
51
|
file: '.env',
|
|
68
52
|
outFile: 'env.d.ts'
|
|
69
53
|
});
|
|
70
|
-
|
|
71
54
|
(0, _vscodeGenerateIndexStandalone.generateManyIndex)({
|
|
72
55
|
cwd: process.cwd(),
|
|
73
56
|
patterns: ['src/**/index.ts', 'node_modules/.x/*.ts', '!src/handlers/**/*', ...(argv.index || [])],
|
|
@@ -76,7 +59,6 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
76
59
|
console.log(`✔️ 索引文件已更新: ${filePath}`);
|
|
77
60
|
}
|
|
78
61
|
});
|
|
79
|
-
|
|
80
62
|
if (lastRun) {
|
|
81
63
|
console.log('==== 重启服务中 ====');
|
|
82
64
|
lastRun.kill();
|
|
@@ -142,15 +124,14 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
142
124
|
await _env_util.EnvUtil.importFile({
|
|
143
125
|
cwd: process.cwd(),
|
|
144
126
|
file: '.env'
|
|
145
|
-
});
|
|
127
|
+
});
|
|
128
|
+
// 之所以能成功是因为 Prisma 用的 dotenv 默认不会覆盖已经设置的环境变量
|
|
146
129
|
// https://github.com/motdotla/dotenv#override
|
|
147
|
-
|
|
148
130
|
process.env.DATABASE_URL = process.env.DATABASE_ACTION_URL || process.env.DATABASE_URL;
|
|
149
131
|
await (0, _execa.default)('tnpx', ['prisma', ...argv._.slice(1), '--schema', 'src/db/schema.prisma'], {
|
|
150
132
|
cwd: process.cwd(),
|
|
151
133
|
stdio: 'inherit'
|
|
152
134
|
});
|
|
153
|
-
|
|
154
135
|
if (!argv.production) {
|
|
155
136
|
await _template_util.TemplateUtil.initModels(process.cwd());
|
|
156
137
|
}
|
|
@@ -169,14 +150,13 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
169
150
|
file: '.env'
|
|
170
151
|
});
|
|
171
152
|
process.env.DATABASE_URL = process.env.DATABASE_ACTION_URL || process.env.DATABASE_URL;
|
|
172
|
-
|
|
173
153
|
if (!argv.script) {
|
|
174
154
|
await (0, _execa.default)('tnpx', ['select-run'], {
|
|
175
155
|
cwd: process.cwd(),
|
|
176
156
|
stdio: 'inherit'
|
|
177
157
|
});
|
|
178
158
|
} else {
|
|
179
|
-
await (0, _execa.default)('
|
|
159
|
+
await (0, _execa.default)('tsx', [argv.script], {
|
|
180
160
|
cwd: process.cwd(),
|
|
181
161
|
stdio: 'inherit'
|
|
182
162
|
});
|
|
@@ -190,7 +170,6 @@ _yargs.default.command('dev', '开始开发', _ => _.positional('index', {
|
|
|
190
170
|
cwd: process.cwd(),
|
|
191
171
|
file: '.env.deploy'
|
|
192
172
|
});
|
|
193
|
-
|
|
194
173
|
if (argv.type === 'env') {
|
|
195
174
|
const appEnv = await _env_util.EnvUtil.parseFileAsMap({
|
|
196
175
|
cwd: process.cwd(),
|
|
@@ -1,28 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
|
|
5
4
|
exports.__esModule = true;
|
|
6
5
|
exports.DeployUtil = void 0;
|
|
7
|
-
|
|
8
6
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
9
|
-
|
|
10
7
|
var _path = _interopRequireDefault(require("path"));
|
|
11
|
-
|
|
12
8
|
var _vtils = require("vtils");
|
|
13
|
-
|
|
14
9
|
var _nodeSsh = require("node-ssh");
|
|
15
|
-
|
|
16
10
|
class DeployUtil {
|
|
17
11
|
static async deploy(options) {
|
|
18
12
|
const pkgContent = await _fsExtra.default.readJson(_path.default.join(options.cwd, 'package.json'));
|
|
19
|
-
|
|
20
13
|
const appFile = _path.default.join(options.cwd, `temp/app.${pkgContent.version}.tgz`);
|
|
21
|
-
|
|
22
14
|
if (!(await _fsExtra.default.pathExists(appFile))) {
|
|
23
15
|
throw new Error('请先构建');
|
|
24
16
|
}
|
|
25
|
-
|
|
26
17
|
const ssh = new _nodeSsh.NodeSSH();
|
|
27
18
|
await ssh.connect({
|
|
28
19
|
host: options.host,
|
|
@@ -56,7 +47,6 @@ class DeployUtil {
|
|
|
56
47
|
});
|
|
57
48
|
ssh.dispose();
|
|
58
49
|
}
|
|
59
|
-
|
|
60
50
|
static async deployEnv(options) {
|
|
61
51
|
const ssh = new _nodeSsh.NodeSSH();
|
|
62
52
|
await ssh.connect({
|
|
@@ -80,7 +70,5 @@ class DeployUtil {
|
|
|
80
70
|
});
|
|
81
71
|
ssh.dispose();
|
|
82
72
|
}
|
|
83
|
-
|
|
84
73
|
}
|
|
85
|
-
|
|
86
74
|
exports.DeployUtil = DeployUtil;
|