baja-lite 1.6.2 → 1.6.4
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/.eslintignore +7 -0
- package/.eslintrc.cjs +89 -0
- package/.prettierrc +7 -0
- package/.vscode/settings.json +9 -0
- package/ci.js +33 -0
- package/package-cjs.json +17 -0
- package/package.json +80 -80
- package/pnpm-lock.yaml +2840 -0
- package/pnpm-workspace.yaml +2 -0
- package/{boot-remote.js → src/boot-remote.ts} +64 -63
- package/{boot.js → src/boot.ts} +170 -163
- package/{code.js → src/code.ts} +526 -517
- package/{convert-xml.js → src/convert-xml.ts} +460 -410
- package/src/error.ts +11 -0
- package/src/event.ts +34 -0
- package/src/fn.ts +295 -0
- package/{index.d.ts → src/index.ts} +11 -10
- package/src/math.ts +405 -0
- package/src/object.ts +342 -0
- package/{snowflake.js → src/snowflake.ts} +127 -108
- package/src/sql.ts +5529 -0
- package/{sqlite.js → src/sqlite.ts} +157 -156
- package/src/string.ts +111 -0
- package/src/test-mysql.ts +148 -0
- package/{test-postgresql.js → src/test-postgresql.ts} +80 -91
- package/{test-sqlite.js → src/test-sqlite.ts} +80 -90
- package/{test-xml.js → src/test-xml.ts} +70 -70
- package/{test.js → src/test.ts} +3 -2
- package/src/wx/base.ts +77 -0
- package/src/wx/mini.ts +147 -0
- package/src/wx/organ.ts +290 -0
- package/{wx/types.d.ts → src/wx/types.ts} +549 -560
- package/{wx.d.ts → src/wx.ts} +3 -3
- package/tsconfig.cjs.json +42 -0
- package/tsconfig.json +44 -0
- package/xml/event-report.xml +13 -0
- package/yarn.lock +1977 -0
- package/boot-remote.d.ts +0 -2
- package/boot.d.ts +0 -2
- package/code.d.ts +0 -2
- package/convert-xml.d.ts +0 -10
- package/error.d.ts +0 -5
- package/error.js +0 -13
- package/event.d.ts +0 -10
- package/event.js +0 -38
- package/fn.d.ts +0 -128
- package/fn.js +0 -172
- package/index.js +0 -10
- package/math.d.ts +0 -83
- package/math.js +0 -451
- package/object.d.ts +0 -126
- package/object.js +0 -321
- package/snowflake.d.ts +0 -12
- package/sql.d.ts +0 -2148
- package/sql.js +0 -5372
- package/sqlite.d.ts +0 -32
- package/string.d.ts +0 -17
- package/string.js +0 -105
- package/test-mysql.d.ts +0 -2
- package/test-mysql.js +0 -114
- package/test-postgresql.d.ts +0 -2
- package/test-sqlite.d.ts +0 -1
- package/test-xml.d.ts +0 -1
- package/test.d.ts +0 -1
- package/wx/base.d.ts +0 -11
- package/wx/base.js +0 -78
- package/wx/mini.d.ts +0 -52
- package/wx/mini.js +0 -112
- package/wx/organ.d.ts +0 -65
- package/wx/organ.js +0 -171
- package/wx/types.js +0 -1
- package/wx.js +0 -3
- /package/{README.md → Readme.md} +0 -0
package/{code.js → src/code.ts}
RENAMED
|
@@ -1,517 +1,526 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import fs from 'fs';
|
|
3
|
-
import mustache from 'mustache';
|
|
4
|
-
import { createPool } from 'mysql2/promise';
|
|
5
|
-
import path from 'path';
|
|
6
|
-
import { start } from 'repl';
|
|
7
|
-
import pkg from 'shelljs';
|
|
8
|
-
const { mkdir } = pkg;
|
|
9
|
-
const lxMap = {
|
|
10
|
-
tinyint: "number",
|
|
11
|
-
smallint: "number",
|
|
12
|
-
mediumint: "number",
|
|
13
|
-
int: "number",
|
|
14
|
-
integer: "number",
|
|
15
|
-
bigint: "number",
|
|
16
|
-
bit: "boolean",
|
|
17
|
-
double: "number",
|
|
18
|
-
real: "number",
|
|
19
|
-
float: "number",
|
|
20
|
-
decimal: "number",
|
|
21
|
-
numeric: "number",
|
|
22
|
-
char: "string",
|
|
23
|
-
varchar: "string",
|
|
24
|
-
date: "Date",
|
|
25
|
-
time: "string",
|
|
26
|
-
year: "string",
|
|
27
|
-
timestamp: "number",
|
|
28
|
-
datetime: "Date",
|
|
29
|
-
tinyblob: "string",
|
|
30
|
-
blob: "string",
|
|
31
|
-
mediumblob: "string",
|
|
32
|
-
longblob: "string",
|
|
33
|
-
tinytext: "string",
|
|
34
|
-
text: "string",
|
|
35
|
-
mediumtext: "string",
|
|
36
|
-
longtext: "string",
|
|
37
|
-
enum: "string",
|
|
38
|
-
set: "string",
|
|
39
|
-
binary: "string",
|
|
40
|
-
varbinary: "string",
|
|
41
|
-
point: "Object",
|
|
42
|
-
linestring: "Object",
|
|
43
|
-
polygon: "Object",
|
|
44
|
-
geometry: "string",
|
|
45
|
-
multipoint: "Object",
|
|
46
|
-
multilinestring: "Object",
|
|
47
|
-
multipolygon: "Object",
|
|
48
|
-
geometrycollection: "Object"
|
|
49
|
-
};
|
|
50
|
-
function info(i) {
|
|
51
|
-
console.log(info2(i));
|
|
52
|
-
}
|
|
53
|
-
function warn(i) {
|
|
54
|
-
console.log(warn2(i));
|
|
55
|
-
}
|
|
56
|
-
function success(i) {
|
|
57
|
-
console.log(success2(i));
|
|
58
|
-
}
|
|
59
|
-
function error(i) {
|
|
60
|
-
console.log(error2(i));
|
|
61
|
-
}
|
|
62
|
-
function log(i) {
|
|
63
|
-
console.log(log2(i));
|
|
64
|
-
}
|
|
65
|
-
function info2(i) {
|
|
66
|
-
return `\x1b[46m\x1b[30m${i}\x1b[0m`;
|
|
67
|
-
}
|
|
68
|
-
function warn2(i) {
|
|
69
|
-
return `\x1b[43m\x1b[30m${i}\x1b[0m`;
|
|
70
|
-
}
|
|
71
|
-
function success2(i) {
|
|
72
|
-
return `\x1b[42m\x1b[30m${i}\x1b[0m`;
|
|
73
|
-
}
|
|
74
|
-
function error2(i) {
|
|
75
|
-
return `\x1b[41m\x1b[30m${i}\x1b[0m`;
|
|
76
|
-
}
|
|
77
|
-
function log2(i) {
|
|
78
|
-
return `\x1b[47m\x1b[30m${i}\x1b[0m`;
|
|
79
|
-
}
|
|
80
|
-
let js = false;
|
|
81
|
-
function checkPath(p) {
|
|
82
|
-
let file = `${p}/baja.code.json`;
|
|
83
|
-
try {
|
|
84
|
-
info(`查找配置文件: ${file}`);
|
|
85
|
-
fs.statSync(file);
|
|
86
|
-
success(`发现配置文件: ${file}`);
|
|
87
|
-
return file;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
let
|
|
104
|
-
let
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
${
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
"
|
|
119
|
-
"
|
|
120
|
-
"
|
|
121
|
-
"
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
"
|
|
126
|
-
"
|
|
127
|
-
"
|
|
128
|
-
"
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
},
|
|
137
|
-
"
|
|
138
|
-
"
|
|
139
|
-
"
|
|
140
|
-
"
|
|
141
|
-
"
|
|
142
|
-
"
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
${warn2(
|
|
146
|
-
${warn2('
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
${warn2('
|
|
155
|
-
${warn2('
|
|
156
|
-
${warn2('
|
|
157
|
-
${warn2('
|
|
158
|
-
${
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
${warn2('
|
|
208
|
-
${warn2('
|
|
209
|
-
${warn2('
|
|
210
|
-
${warn2('
|
|
211
|
-
${warn2('
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
const templatePath = path.join(basepath, 'code-template');
|
|
222
|
-
help2();
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
if (r.
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
}
|
|
335
|
-
if (r.
|
|
336
|
-
fields.push(`
|
|
337
|
-
}
|
|
338
|
-
if (r.
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
logicDelete
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
r.Name = r.name.replace(/_(\w)/g, (a, b) => b.toUpperCase());
|
|
350
|
-
r.NAME = r.Name.replace(/\w/, (v) => v.toUpperCase());
|
|
351
|
-
r.Field = `@Field({${fields.join(',')}})`;
|
|
352
|
-
r.JSField_name = `{${fields.join(',')}, P: '${r.name}'}`;
|
|
353
|
-
r.JSFieldName = `{${fields.join(',')}, P: '${r.Name}'}`;
|
|
354
|
-
if (configData.custom) {
|
|
355
|
-
r.custom = configData.custom(r.name);
|
|
356
|
-
}
|
|
357
|
-
return r;
|
|
358
|
-
});
|
|
359
|
-
conn.release();
|
|
360
|
-
return { columns, logicDelete };
|
|
361
|
-
}
|
|
362
|
-
async function excute(command, input, modelName) {
|
|
363
|
-
const tables = await getTables(input);
|
|
364
|
-
if (input !== '.') {
|
|
365
|
-
const checkTable = input.split(/,|\s/).map(r => r.trim())
|
|
366
|
-
if (checkTable.length !== tables.length) {
|
|
367
|
-
error(`[错误] 输入的表与数据库查询返回表不符,数据库返回${tables.length}个:${tables.map(i => i.tableName).join(',')}`);
|
|
368
|
-
return;
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
modelName
|
|
372
|
-
const modelPath = modelName ? `/${modelName}/` : '';
|
|
373
|
-
for (const { tableName, title } of tables) {
|
|
374
|
-
const { columns, logicDelete } = await getColumns(tableName);
|
|
375
|
-
const className = tableName.replace(/_(\w)/g, (a, b) => b.toUpperCase());
|
|
376
|
-
const ClassName = className.replace(/\w/, (v) => v.toUpperCase());
|
|
377
|
-
const vueName = tableName.replace(/_/g, '-');
|
|
378
|
-
const splitVueName = tableName.replace(/_/, '/').replace(/_/g, '-');
|
|
379
|
-
const modelName = tableName.substring(0, tableName.indexOf('_'));
|
|
380
|
-
const splitName = tableName.replace(/_/g, '/');
|
|
381
|
-
const SplitName = tableName.replace(/_/, '/').replace(/_(\w)/g, (a, b) => b.toUpperCase());
|
|
382
|
-
const data = {
|
|
383
|
-
title,
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
info('执行完毕!下面打印生成的输出');
|
|
482
|
-
info(Array.from(outputs).join(','));
|
|
483
|
-
});
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
}
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
if (
|
|
507
|
-
error(
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import mustache from 'mustache';
|
|
4
|
+
import { createPool } from 'mysql2/promise';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { start } from 'repl';
|
|
7
|
+
import pkg from 'shelljs';
|
|
8
|
+
const { mkdir } = pkg;
|
|
9
|
+
const lxMap = {
|
|
10
|
+
tinyint: "number",
|
|
11
|
+
smallint: "number",
|
|
12
|
+
mediumint: "number",
|
|
13
|
+
int: "number",
|
|
14
|
+
integer: "number",
|
|
15
|
+
bigint: "number",
|
|
16
|
+
bit: "boolean",
|
|
17
|
+
double: "number",
|
|
18
|
+
real: "number",
|
|
19
|
+
float: "number",
|
|
20
|
+
decimal: "number",
|
|
21
|
+
numeric: "number",
|
|
22
|
+
char: "string",
|
|
23
|
+
varchar: "string",
|
|
24
|
+
date: "Date",
|
|
25
|
+
time: "string",
|
|
26
|
+
year: "string",
|
|
27
|
+
timestamp: "number",
|
|
28
|
+
datetime: "Date",
|
|
29
|
+
tinyblob: "string",
|
|
30
|
+
blob: "string",
|
|
31
|
+
mediumblob: "string",
|
|
32
|
+
longblob: "string",
|
|
33
|
+
tinytext: "string",
|
|
34
|
+
text: "string",
|
|
35
|
+
mediumtext: "string",
|
|
36
|
+
longtext: "string",
|
|
37
|
+
enum: "string",
|
|
38
|
+
set: "string",
|
|
39
|
+
binary: "string",
|
|
40
|
+
varbinary: "string",
|
|
41
|
+
point: "Object",
|
|
42
|
+
linestring: "Object",
|
|
43
|
+
polygon: "Object",
|
|
44
|
+
geometry: "string",
|
|
45
|
+
multipoint: "Object",
|
|
46
|
+
multilinestring: "Object",
|
|
47
|
+
multipolygon: "Object",
|
|
48
|
+
geometrycollection: "Object"
|
|
49
|
+
};
|
|
50
|
+
function info(i: string) {
|
|
51
|
+
console.log(info2(i));
|
|
52
|
+
}
|
|
53
|
+
function warn(i: string) {
|
|
54
|
+
console.log(warn2(i));
|
|
55
|
+
}
|
|
56
|
+
function success(i: string) {
|
|
57
|
+
console.log(success2(i));
|
|
58
|
+
}
|
|
59
|
+
function error(i: string) {
|
|
60
|
+
console.log(error2(i));
|
|
61
|
+
}
|
|
62
|
+
function log(i: string) {
|
|
63
|
+
console.log(log2(i));
|
|
64
|
+
}
|
|
65
|
+
function info2(i: string) {
|
|
66
|
+
return `\x1b[46m\x1b[30m${i}\x1b[0m`;
|
|
67
|
+
}
|
|
68
|
+
function warn2(i: string) {
|
|
69
|
+
return `\x1b[43m\x1b[30m${i}\x1b[0m`;
|
|
70
|
+
}
|
|
71
|
+
function success2(i: string) {
|
|
72
|
+
return `\x1b[42m\x1b[30m${i}\x1b[0m`;
|
|
73
|
+
}
|
|
74
|
+
function error2(i: string) {
|
|
75
|
+
return `\x1b[41m\x1b[30m${i}\x1b[0m`;
|
|
76
|
+
}
|
|
77
|
+
function log2(i: string) {
|
|
78
|
+
return `\x1b[47m\x1b[30m${i}\x1b[0m`;
|
|
79
|
+
}
|
|
80
|
+
let js = false;
|
|
81
|
+
function checkPath(p: string) {
|
|
82
|
+
let file = `${p}/baja.code.json`;
|
|
83
|
+
try {
|
|
84
|
+
info(`查找配置文件: ${file}`);
|
|
85
|
+
fs.statSync(file);
|
|
86
|
+
success(`发现配置文件: ${file}`);
|
|
87
|
+
return file;
|
|
88
|
+
} catch (e1) {
|
|
89
|
+
try {
|
|
90
|
+
file = `${p}/baja.code.js`;
|
|
91
|
+
info(`查找配置文件: ${file}`);
|
|
92
|
+
fs.statSync(file);
|
|
93
|
+
success(`发现配置文件: ${file}`);
|
|
94
|
+
js = true;
|
|
95
|
+
return file;
|
|
96
|
+
} catch (e2) {
|
|
97
|
+
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
let force = false;
|
|
103
|
+
let basepath = path.join(import.meta.dirname, '..', '..');
|
|
104
|
+
let config = checkPath(basepath);
|
|
105
|
+
if (config === null) {
|
|
106
|
+
basepath = path.join(import.meta.dirname, '..', '..', '..', '..', '..');
|
|
107
|
+
config = checkPath(basepath);
|
|
108
|
+
}
|
|
109
|
+
function help1() {
|
|
110
|
+
console.log(`
|
|
111
|
+
**********************-----------
|
|
112
|
+
${info2('配置文件:')}
|
|
113
|
+
请在项目根目录添加文件:${warn2('baja.code.json')} 或者 ${warn2('baja.code.js(export defult {})')}
|
|
114
|
+
${info2('配置示例:')}
|
|
115
|
+
{
|
|
116
|
+
|
|
117
|
+
"host": "",
|
|
118
|
+
"port": "",
|
|
119
|
+
"user": "",
|
|
120
|
+
"password": "",
|
|
121
|
+
"database": "",
|
|
122
|
+
|
|
123
|
+
"command": {
|
|
124
|
+
"entity": "src/{vueName}/{vueName}.entity.ts",
|
|
125
|
+
"controller": "src/{vueName}/{vueName}.controller.ts",
|
|
126
|
+
"service": "src/{vueName}/{vueName}.service.ts",
|
|
127
|
+
"sql": "src/sql/{vueName}.mu",
|
|
128
|
+
"module": "src/{vueName}/{vueName}.module.ts"
|
|
129
|
+
},
|
|
130
|
+
"commands": {
|
|
131
|
+
"s": ["entity", "controller", "service", "sql", "module"]
|
|
132
|
+
}
|
|
133
|
+
"commands": {
|
|
134
|
+
"s": ["entity", "controller", "service", "sql", "module"]
|
|
135
|
+
},
|
|
136
|
+
"output": "{ClassName}Module",
|
|
137
|
+
"id"? : "uuidShort: true, notNull: true, uuid: true",
|
|
138
|
+
"logicDeleteK"?: "逻辑删除字段名",
|
|
139
|
+
"logicDeleteV"?: "逻辑删除值",如果是字符串需要这样 logicDeleteV: "'0'"
|
|
140
|
+
"NotlogicDeleteV"?: "未逻辑删除值",如果是字符串需要这样 NotlogicDeleteV: "'0'",
|
|
141
|
+
"skipColumns"?: ["跳过的列名1", "跳过的列名2"],
|
|
142
|
+
"custom"?: (列名:string) => string; 该属性支持为每个数据库列自定义一个名称,例如 字段名为 ci_name 可通过custom改造为 Ci Name
|
|
143
|
+
}
|
|
144
|
+
${warn2(`command`)}是生成命令,这里声明命令同时定义文件生成路径, 同时要求在模板中必须有对应模板. ${info2('路径是相对于项目根目录的相对路径')}.
|
|
145
|
+
${warn2('commands')}是组合命令,上面的配置表示输入${error2('s')}同时生成:${success2('"entity", "controller", "service", "sql", "module"这几个模块')}
|
|
146
|
+
${warn2('output')} 是生成后打印出的内容
|
|
147
|
+
`);
|
|
148
|
+
}
|
|
149
|
+
function help2() {
|
|
150
|
+
console.log(`
|
|
151
|
+
${error2('模板文件说明')}
|
|
152
|
+
使用${error2('mustache')}
|
|
153
|
+
${warn2('模板变量输出')}${info2('<% 变量 %>')}
|
|
154
|
+
${warn2('模板转义')}${info2('<%& 变量 %>')}
|
|
155
|
+
${warn2('模板循环')}${info2('<%# 变量 %> <%/变量%>')}
|
|
156
|
+
${warn2('模板路径')} 项目根目录的${error2('code-template')}
|
|
157
|
+
${warn2('模板使用')} 在配置文件中的command下定义命令,每个命令的key
|
|
158
|
+
${error2('变量说明')}
|
|
159
|
+
---------------------------------------------------------------------------------------------------------------
|
|
160
|
+
************* 以下假设表名为${error2('event_main_info')},列名为${error2('sku_id,sku_name')}
|
|
161
|
+
title // 字符串,表的注释
|
|
162
|
+
|
|
163
|
+
tableName // 字符串,event_main_info
|
|
164
|
+
className // 字符串,eventMainInfo
|
|
165
|
+
ClassName // 字符串,EventMainInfo
|
|
166
|
+
vueName // 字符串,event-main-info
|
|
167
|
+
splitVueName // 字符串,event/main-info
|
|
168
|
+
splitName // 字符串,event/main/info
|
|
169
|
+
SplitName // 字符串,event/mainInfo
|
|
170
|
+
|
|
171
|
+
columns // 数组, 元素格式为{comment:注释,name: sku_id,Name: skuId,NAME: SkuId,Field:表示字段的注解,JSField_name、JSFieldName 分别表示JS的注解,Type:表示JS类
|
|
172
|
+
型,custom:自定义列名}
|
|
173
|
+
column_names // 数组, 元素是列名字符串,格式是 sku_id,sku_name
|
|
174
|
+
ColumnNames // 数组, 元素是列名字符串,格式是 skuId,skuName
|
|
175
|
+
column_names_join // 字符串,列名join的字符串,格式是 "sku_id,sku_name"
|
|
176
|
+
ColumnNames_join // 字符串,列名join的字符串,格式是 "skuId,skuName"
|
|
177
|
+
|
|
178
|
+
column_names_joinT // 字符串,列名join的字符串,格式是 "t.sku_id,t.sku_name"
|
|
179
|
+
ColumnNames_joinT // 字符串,列名join的字符串,格式是 "t.skuId,t.skuName"
|
|
180
|
+
|
|
181
|
+
columns_no_id // 数组, 不含主键, 元素格式为{comment:注释,name: sku_id,Name: skuId,NAME: SkuId,Field:表示字段的注解,JSField_name, JSFieldName 分别表示JS的注解,Type:表示JS类型
|
|
182
|
+
}
|
|
183
|
+
column_names_no_id // 数组, 不含主键, 元素是列名字符串,格式是 sku_id,sku_name
|
|
184
|
+
ColumnNames_no_id // 数组, 不含主键, 元素是列名字符串,格式是 skuId,skuName
|
|
185
|
+
column_names_no_id_join // 字符串, 不含主键, 列名join的字符串,格式是 "sku_id,sku_name"
|
|
186
|
+
ColumnNames_no_id_join // 字符串, 不含主键, 列名join的字符串,格式是 "skuId,skuName"
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
columns_no_skip // 数组, 不含跳过的列,元素格式为{comment:注释,name: sku_id,Name: skuId,NAME: SkuId,Field:表示字段的注解,JSField_name, JSFieldName 分别表示JS的注解,Type:表示JS类型}
|
|
190
|
+
column_names_no_skip // 数组, 不含跳过的列, 元素是列名字符串,格式是 sku_id,sku_name
|
|
191
|
+
ColumnNames_no_skip // 数组, 不含跳过的列, 元素是列名字符串,格式是 skuId,skuName
|
|
192
|
+
column_names_no_skip_join // 数组, 不含跳过的列, 元素是列名字符串,格式是 "sku_id,sku_name"
|
|
193
|
+
ColumnNames_no_skip_join // 数组, 不含跳过的列, 元素是列名字符串,格式是 "skuId,skuName"
|
|
194
|
+
|
|
195
|
+
ids // 数组, 只有主键, 元素格式为{comment:注释,name: sku_id,Name: skuId,NAME: SkuId,Field:表示字段的注解,JSField_name, JSFieldName 分别表示JS的注解,Type:表示JS类型}
|
|
196
|
+
id_names // 数组, 只有主键, 元素是列名字符串,格式是 sku_id,sku_name
|
|
197
|
+
IdNames // 数组, 只有主键, 元素是列名字符串,格式是 skuId,skuName
|
|
198
|
+
id_names_join // 字符串,列名join的字符串,格式是 "sku_id,sku_name"
|
|
199
|
+
IdNames_join // 字符串,列名join的字符串,格式是 "skuId,skuName"
|
|
200
|
+
|
|
201
|
+
modelName // 推断出的模块名称,可能为空字符串, 如果表名为event_main_info, 则模块为 event
|
|
202
|
+
modelPath // 模块名称实际就影响访问路径,所以这里会直接拼好controller的模块访问路径,如果模块为空,则该属性就是空字符串,否则是 /模块名称/
|
|
203
|
+
|
|
204
|
+
logicDelete // 逻辑删除的查询条件,可以附加在sql条件的末尾,可能是空的
|
|
205
|
+
---------------------------------------------------------------------------------------------------------------
|
|
206
|
+
${warn2('特殊命令')}
|
|
207
|
+
${warn2('多表操作')} .命令 table1,table2,table3:模块名称 ${info2(':模块名称 可以省略')}
|
|
208
|
+
${warn2('全库操作')} .命令 . ${info2('注意:.表示全表')}
|
|
209
|
+
${warn2('覆盖生成')} .force
|
|
210
|
+
${warn2('配置说明')} .help1
|
|
211
|
+
${warn2('模板说明')} .help2
|
|
212
|
+
-----
|
|
213
|
+
`);
|
|
214
|
+
}
|
|
215
|
+
if (config === null) {
|
|
216
|
+
error('NOT FOUND Config File!!');
|
|
217
|
+
help1();
|
|
218
|
+
throw new Error('NOT FOUND Config File');
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
const templatePath = path.join(basepath, 'code-template');
|
|
222
|
+
help2();
|
|
223
|
+
|
|
224
|
+
try {
|
|
225
|
+
const outputs = new Set<string>();
|
|
226
|
+
let configData: {
|
|
227
|
+
host: string;
|
|
228
|
+
port: number;
|
|
229
|
+
user: string;
|
|
230
|
+
password: string;
|
|
231
|
+
database: string;
|
|
232
|
+
command: Record<string, string>;
|
|
233
|
+
commands: Record<string, string[]>;
|
|
234
|
+
output: string;
|
|
235
|
+
id: string;
|
|
236
|
+
logicDeleteK: string;
|
|
237
|
+
logicDeleteV: number;
|
|
238
|
+
NotlogicDeleteV: number;
|
|
239
|
+
tables: string;
|
|
240
|
+
skipColumns: string[];
|
|
241
|
+
custom?: (c: string) => string;
|
|
242
|
+
};
|
|
243
|
+
if (js === false) {
|
|
244
|
+
const _configData = fs.readFileSync(config, { encoding: 'utf-8' }).toString();
|
|
245
|
+
configData = JSON.parse(_configData);
|
|
246
|
+
} else {
|
|
247
|
+
const _configData = fs.readFileSync(config, { encoding: 'utf-8' }).toString();
|
|
248
|
+
configData = new Function(_configData.replace('export default', 'return'))();
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
configData.skipColumns ??= [];
|
|
252
|
+
configData.command ??= {};
|
|
253
|
+
configData.commands ??= {};
|
|
254
|
+
configData.output ??= '';
|
|
255
|
+
configData.id ??= 'uuidShort: true, notNull: true, uuid: true';
|
|
256
|
+
configData.logicDeleteK ??= '';
|
|
257
|
+
configData.logicDeleteV ??= 0;
|
|
258
|
+
configData.NotlogicDeleteV ??= 0;
|
|
259
|
+
if (!configData.host || !configData.port || !configData.user || !configData.password || !configData.database) {
|
|
260
|
+
error(`[错误]配置文件缺少必要的参数: host, port, user, password, database`);
|
|
261
|
+
}
|
|
262
|
+
if (!fs.existsSync(templatePath)) {
|
|
263
|
+
error(`[错误]模板文件夹不存在,请在项目根目录创建code-template文件夹`);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
const templates = Object.fromEntries(fs.readdirSync(templatePath).map(r => [path.basename(r, '.mu'), fs.readFileSync(path.join(templatePath, r), { encoding: 'utf-8' }).toString()]));
|
|
267
|
+
const pool = createPool({
|
|
268
|
+
host: configData.host,
|
|
269
|
+
port: configData.port,
|
|
270
|
+
user: configData.user,
|
|
271
|
+
password: configData.password,
|
|
272
|
+
database: configData.database
|
|
273
|
+
});
|
|
274
|
+
async function getTables(tableName: string) {
|
|
275
|
+
const conn = await pool.getConnection();
|
|
276
|
+
const params: (string | string[])[] = [configData.database];
|
|
277
|
+
let sql = `
|
|
278
|
+
SELECT TABLE_NAME tableName, IFNULL(TABLE_COMMENT, TABLE_NAME) title FROM information_schema.TABLES
|
|
279
|
+
WHERE TABLE_SCHEMA= ? AND TABLE_TYPE = 'BASE TABLE'`;
|
|
280
|
+
if (tableName !== '.') {
|
|
281
|
+
sql += ` AND TABLE_NAME IN (?)`;
|
|
282
|
+
params.push(tableName.split(/,|\s/).map(r => r.trim()));
|
|
283
|
+
}
|
|
284
|
+
const [result] = await conn.query<any[]>(sql, params);
|
|
285
|
+
conn.release();
|
|
286
|
+
return result;
|
|
287
|
+
}
|
|
288
|
+
async function getColumns(tableName: string) {
|
|
289
|
+
const conn = await pool.getConnection();
|
|
290
|
+
const [result] = await conn.query<any[]>(`
|
|
291
|
+
SELECT
|
|
292
|
+
DATA_TYPE type,
|
|
293
|
+
COLUMN_NAME \`name\`,
|
|
294
|
+
IFNULL(IFNULL(CHARACTER_MAXIMUM_LENGTH,NUMERIC_PRECISION),DATETIME_PRECISION) \`length\`,
|
|
295
|
+
NUMERIC_SCALE scale,
|
|
296
|
+
COLUMN_DEFAULT def,
|
|
297
|
+
IF(COLUMN_KEY = 'PRI', 1, 0) id,
|
|
298
|
+
IF(IS_NULLABLE = 'NO', 1, 0) notNull,
|
|
299
|
+
COLUMN_COMMENT \`comment\`
|
|
300
|
+
FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=? AND TABLE_NAME = ?;
|
|
301
|
+
`, [configData.database, tableName]);
|
|
302
|
+
let logicDelete = '';
|
|
303
|
+
const columns = result.map(r => {
|
|
304
|
+
if (r.id === 1) { r.id = true; }
|
|
305
|
+
else delete r.id;
|
|
306
|
+
if (r.notNull === 1) { r.notNull = true; }
|
|
307
|
+
else delete r.notNull;
|
|
308
|
+
const fields = new Array<string>(`type:SqlType.${r.type}`);
|
|
309
|
+
r.Type = lxMap[r.type];
|
|
310
|
+
if (r.length !== null) { fields.push(`length:${r.length}`); }
|
|
311
|
+
if (r.scale !== null) { fields.push(`scale:${r.scale}`); }
|
|
312
|
+
if (r.def !== null) {
|
|
313
|
+
r.def ??= '';
|
|
314
|
+
if (r.def !== '') {
|
|
315
|
+
if (isNaN(r.def)) {
|
|
316
|
+
fields.push(`def:'${r.def}'`);
|
|
317
|
+
} else {
|
|
318
|
+
fields.push(`def:${r.def}`);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
if (r.Type === 'string') {
|
|
323
|
+
if (r.def === '' || r.def === null) {
|
|
324
|
+
r.def = "''";
|
|
325
|
+
} else {
|
|
326
|
+
r.def = `'${r.def}'`;
|
|
327
|
+
}
|
|
328
|
+
} else if (r.Type === 'number') {
|
|
329
|
+
r.def = 0;
|
|
330
|
+
} else if (r.Type === 'Date') {
|
|
331
|
+
r.def = 'new Date()';
|
|
332
|
+
} else {
|
|
333
|
+
r.def = 'null';
|
|
334
|
+
}
|
|
335
|
+
if (r.id === true) {
|
|
336
|
+
fields.push(`id:true`);
|
|
337
|
+
}
|
|
338
|
+
if (r.notNull === true) { fields.push(`notNull:true`); }
|
|
339
|
+
if (r.id === true && configData.id) {
|
|
340
|
+
fields.push(configData.id);
|
|
341
|
+
}
|
|
342
|
+
if (r.name === configData.logicDeleteK) {
|
|
343
|
+
fields.push(`logicDelete: ${configData.logicDeleteV}`);
|
|
344
|
+
logicDelete = `AND ${r.name} = ${configData.NotlogicDeleteV}`;
|
|
345
|
+
}
|
|
346
|
+
if (r.comment) { fields.push(`comment: '${r.comment}'`); }
|
|
347
|
+
r.comment = r.comment ?? '';
|
|
348
|
+
|
|
349
|
+
r.Name = r.name.replace(/_(\w)/g, (a: string, b: string) => b.toUpperCase());
|
|
350
|
+
r.NAME = r.Name.replace(/\w/, (v: string) => v.toUpperCase());
|
|
351
|
+
r.Field = `@Field({${fields.join(',')}})`;
|
|
352
|
+
r.JSField_name = `{${fields.join(',')}, P: '${r.name}'}`;
|
|
353
|
+
r.JSFieldName = `{${fields.join(',')}, P: '${r.Name}'}`;
|
|
354
|
+
if (configData.custom) {
|
|
355
|
+
r.custom = configData.custom(r.name);
|
|
356
|
+
}
|
|
357
|
+
return r;
|
|
358
|
+
});
|
|
359
|
+
conn.release();
|
|
360
|
+
return { columns, logicDelete };
|
|
361
|
+
}
|
|
362
|
+
async function excute(command: string, input: string, modelName: string) {
|
|
363
|
+
const tables = await getTables(input);
|
|
364
|
+
if (input !== '.') {
|
|
365
|
+
const checkTable = input.split(/,|\s/).map(r => r.trim())
|
|
366
|
+
if (checkTable.length !== tables.length) {
|
|
367
|
+
error(`[错误] 输入的表与数据库查询返回表不符,数据库返回${tables.length}个:${tables.map(i => i.tableName).join(',')}`);
|
|
368
|
+
return;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
modelName ??= '';
|
|
372
|
+
const modelPath = modelName ? `/${modelName}/` : '';
|
|
373
|
+
for (const { tableName, title } of tables) {
|
|
374
|
+
const { columns, logicDelete } = await getColumns(tableName);
|
|
375
|
+
const className = tableName.replace(/_(\w)/g, (a: string, b: string) => b.toUpperCase());
|
|
376
|
+
const ClassName = className.replace(/\w/, (v: string) => v.toUpperCase());
|
|
377
|
+
const vueName = tableName.replace(/_/g, '-');
|
|
378
|
+
const splitVueName = tableName.replace(/_/, '/').replace(/_/g, '-');
|
|
379
|
+
const modelName = tableName.substring(0, tableName.indexOf('_'));
|
|
380
|
+
const splitName = tableName.replace(/_/g, '/');
|
|
381
|
+
const SplitName = tableName.replace(/_/, '/').replace(/_(\w)/g, (a: string, b: string) => b.toUpperCase());
|
|
382
|
+
const data = {
|
|
383
|
+
title,
|
|
384
|
+
|
|
385
|
+
tableName,
|
|
386
|
+
className,
|
|
387
|
+
ClassName,
|
|
388
|
+
vueName,
|
|
389
|
+
splitVueName,
|
|
390
|
+
splitName,
|
|
391
|
+
SplitName,
|
|
392
|
+
|
|
393
|
+
columns,
|
|
394
|
+
|
|
395
|
+
column_names: columns?.map(i => i.name),
|
|
396
|
+
ColumnNames: columns?.map(i => i.Name),
|
|
397
|
+
|
|
398
|
+
column_names_join: columns?.map(i => i.name).join(','),
|
|
399
|
+
ColumnNames_join: columns?.map(i => `${i.name} ${i.Name}`).join(','),
|
|
400
|
+
|
|
401
|
+
column_names_joinT: columns?.map(i => `t.${i.name}`).join(','),
|
|
402
|
+
ColumnNames_joinT: columns?.map(i => `t.${i.name} ${i.Name}`).join(','),
|
|
403
|
+
|
|
404
|
+
columns_no_id: columns?.filter(i => !i.id),
|
|
405
|
+
|
|
406
|
+
column_names_no_id: columns?.filter(i => !i.id).map(i => i.name),
|
|
407
|
+
ColumnNames_no_id: columns?.filter(i => !i.id).map(i => i.Name),
|
|
408
|
+
|
|
409
|
+
column_names_no_id_join: columns?.filter(i => !i.id).map(i => i.name).join(','),
|
|
410
|
+
ColumnNames_no_id_join: columns?.filter(i => !i.id).map(i => i.Name).join(','),
|
|
411
|
+
|
|
412
|
+
columns_no_skip: columns?.filter(i => !configData.skipColumns.includes(i.name) && !i.id),
|
|
413
|
+
|
|
414
|
+
column_names_no_skip: columns?.filter(i => !configData.skipColumns.includes(i.name) && !i.id).map(i => i.name),
|
|
415
|
+
ColumnNames_no_skip: columns?.filter(i => !configData.skipColumns.includes(i.name) && !i.id).map(i => i.Name),
|
|
416
|
+
|
|
417
|
+
column_names_no_skip_join: columns?.filter(i => !configData.skipColumns.includes(i.name) && !i.id).map(i => i.name).join(','),
|
|
418
|
+
ColumnNames_no_skip_join: columns?.filter(i => !configData.skipColumns.includes(i.name) && !i.id).map(i => i.Name).join(','),
|
|
419
|
+
|
|
420
|
+
ids: columns?.filter(i => i.id),
|
|
421
|
+
|
|
422
|
+
id_names: columns?.filter(i => i.id).map(i => i.name),
|
|
423
|
+
IdNames: columns?.filter(i => i.id).map(i => i.Name),
|
|
424
|
+
|
|
425
|
+
id_names_join: columns?.filter(i => i.id).map(i => i.name).join(','),
|
|
426
|
+
IdNames_join: columns?.filter(i => i.id).map(i => i.Name).join(','),
|
|
427
|
+
|
|
428
|
+
modelName,
|
|
429
|
+
modelPath,
|
|
430
|
+
|
|
431
|
+
logicDelete
|
|
432
|
+
};
|
|
433
|
+
const template = templates[command];
|
|
434
|
+
if (!template) {
|
|
435
|
+
error(`[错误] ${command} 未定义模板!`);
|
|
436
|
+
return;
|
|
437
|
+
}
|
|
438
|
+
const txt = mustache.render(template, data, {}, ['<%', '%>']);
|
|
439
|
+
const _fileName = configData.command[command]!.replace(/{([a-zA-Z]+)}/g, (a: string, b: string) => data[b]);
|
|
440
|
+
const fileNames = _fileName.split(',');
|
|
441
|
+
for (const fileName of fileNames) {
|
|
442
|
+
const filePath = path.join(basepath, fileName);
|
|
443
|
+
const dirname = path.dirname(filePath);
|
|
444
|
+
mkdir('-p', dirname);
|
|
445
|
+
try {
|
|
446
|
+
fs.statSync(filePath);
|
|
447
|
+
if (force === false) {
|
|
448
|
+
warn(`[跳过] ${filePath}`);
|
|
449
|
+
return;
|
|
450
|
+
} else {
|
|
451
|
+
warn(`[覆盖] ${filePath}`);
|
|
452
|
+
}
|
|
453
|
+
} catch (error) {
|
|
454
|
+
info(`[生成] ${filePath}`);
|
|
455
|
+
}
|
|
456
|
+
if (configData.output) {
|
|
457
|
+
outputs.add(configData.output.replace(/{([a-zA-Z]+)}/g, (a: string, b: string) => data[b]));
|
|
458
|
+
}
|
|
459
|
+
fs.writeFileSync(path.join(basepath, fileName), txt);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
const replServer = start();
|
|
464
|
+
function defineCommand(command: string, comands?: string[]) {
|
|
465
|
+
if (comands) {
|
|
466
|
+
log(`\x1b[42m\x1b[30m[组合]${command}>${comands.join(',')}注册成功\x1b[0m`);
|
|
467
|
+
} else {
|
|
468
|
+
log(`\x1b[42m\x1b[30m[命令]${command}注册成功\x1b[0m`);
|
|
469
|
+
}
|
|
470
|
+
if (comands) {
|
|
471
|
+
replServer.defineCommand(command, async input => {
|
|
472
|
+
outputs.clear();
|
|
473
|
+
const inputs = input.match(/([^:]+):{0,1}([a-zA-Z0-9]*)/);
|
|
474
|
+
if (inputs?.length !== 3) {
|
|
475
|
+
return error(`[错误]命令格式应为: table1,table2[:模块名]`);
|
|
476
|
+
}
|
|
477
|
+
const [_, tables, modelName] = inputs;
|
|
478
|
+
for (const c of comands) {
|
|
479
|
+
await excute(c, tables!, modelName ?? '');
|
|
480
|
+
}
|
|
481
|
+
info('执行完毕!下面打印生成的输出');
|
|
482
|
+
info(Array.from(outputs).join(','));
|
|
483
|
+
});
|
|
484
|
+
} else {
|
|
485
|
+
replServer.defineCommand(command, async input => {
|
|
486
|
+
outputs.clear();
|
|
487
|
+
const inputs = input.match(/([^:]+):{0,1}([a-zA-Z0-9]*)/);
|
|
488
|
+
if (inputs?.length !== 3) {
|
|
489
|
+
return error(`[错误]命令格式应为: table1,table2[:模块名]`);
|
|
490
|
+
}
|
|
491
|
+
const [_, tables, modelName] = inputs;
|
|
492
|
+
await excute(command, tables!, modelName ?? '');
|
|
493
|
+
info('执行完毕!下面打印生成的输出');
|
|
494
|
+
info(Array.from(outputs).join(','));
|
|
495
|
+
});
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
replServer.defineCommand('force', () => {
|
|
499
|
+
force = !force;
|
|
500
|
+
log(force ? '覆盖生成' : '不覆盖生成!');
|
|
501
|
+
});
|
|
502
|
+
replServer.defineCommand('help1', help1);
|
|
503
|
+
replServer.defineCommand('help2', help2);
|
|
504
|
+
if (configData.command) {
|
|
505
|
+
for (const command of Object.keys(configData.command)) {
|
|
506
|
+
if (!templates[command]) {
|
|
507
|
+
error(`命令:${command}没有定义模板,该命令不会生效`);
|
|
508
|
+
} else {
|
|
509
|
+
defineCommand(command);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
if (configData.commands) {
|
|
514
|
+
for (const [command, commands] of Object.entries(configData.commands)) {
|
|
515
|
+
const keys = commands as string[];
|
|
516
|
+
const e = keys.filter(k => !templates[k]).join(',');
|
|
517
|
+
if (e) {
|
|
518
|
+
error(`组合命令:${command}定义了${commands},但是${e}没有定义模板,该命令不会生效`);
|
|
519
|
+
} else {
|
|
520
|
+
defineCommand(command, keys);
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
} catch (error) {
|
|
525
|
+
error(error);
|
|
526
|
+
}
|