baja-lite 1.6.4 → 1.6.6
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/boot-remote.d.ts +2 -0
- package/{src/boot-remote.ts → boot-remote.js} +66 -64
- package/boot.d.ts +2 -0
- package/{src/boot.ts → boot.js} +166 -170
- package/code.d.ts +2 -0
- package/{src/code.ts → code.js} +405 -414
- package/convert-xml.d.ts +10 -0
- package/{src/convert-xml.ts → convert-xml.js} +410 -460
- package/error.d.ts +5 -0
- package/error.js +13 -0
- package/event.d.ts +10 -0
- package/event.js +38 -0
- package/fn.d.ts +128 -0
- package/fn.js +172 -0
- package/{src/index.ts → index.d.ts} +10 -11
- package/index.js +10 -0
- package/math.d.ts +83 -0
- package/math.js +451 -0
- package/object.d.ts +126 -0
- package/object.js +321 -0
- package/package.json +13 -13
- package/snowflake.d.ts +12 -0
- package/{src/snowflake.ts → snowflake.js} +108 -127
- package/sql.d.ts +2151 -0
- package/sql.js +5371 -0
- package/sqlite.d.ts +32 -0
- package/{src/sqlite.ts → sqlite.js} +156 -157
- package/string.d.ts +17 -0
- package/string.js +105 -0
- package/test-mysql.d.ts +2 -0
- package/test-mysql.js +114 -0
- package/test-postgresql.d.ts +2 -0
- package/{src/test-postgresql.ts → test-postgresql.js} +91 -80
- package/test-sqlite.d.ts +1 -0
- package/{src/test-sqlite.ts → test-sqlite.js} +90 -80
- package/test-xml.d.ts +1 -0
- package/{src/test-xml.ts → test-xml.js} +2 -2
- package/test.d.ts +1 -0
- package/{src/test.ts → test.js} +2 -3
- package/wx/base.d.ts +11 -0
- package/wx/base.js +78 -0
- package/wx/mini.d.ts +52 -0
- package/wx/mini.js +112 -0
- package/wx/organ.d.ts +65 -0
- package/wx/organ.js +171 -0
- package/{src/wx/types.ts → wx/types.d.ts} +560 -549
- package/wx/types.js +1 -0
- package/{src/wx.ts → wx.d.ts} +3 -3
- package/wx.js +3 -0
- package/.eslintignore +0 -7
- package/.eslintrc.cjs +0 -89
- package/.prettierrc +0 -7
- package/.vscode/settings.json +0 -9
- package/ci.js +0 -33
- package/package-cjs.json +0 -17
- package/pnpm-lock.yaml +0 -2840
- package/pnpm-workspace.yaml +0 -2
- package/src/error.ts +0 -11
- package/src/event.ts +0 -34
- package/src/fn.ts +0 -295
- package/src/math.ts +0 -405
- package/src/object.ts +0 -342
- package/src/sql.ts +0 -5529
- package/src/string.ts +0 -111
- package/src/test-mysql.ts +0 -148
- package/src/wx/base.ts +0 -77
- package/src/wx/mini.ts +0 -147
- package/src/wx/organ.ts +0 -290
- package/tsconfig.cjs.json +0 -42
- package/tsconfig.json +0 -44
- package/xml/event-report.xml +0 -13
- package/yarn.lock +0 -1977
- /package/{Readme.md → README.md} +0 -0
package/{src/code.ts → code.js}
RENAMED
|
@@ -1,112 +1,113 @@
|
|
|
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
|
-
|
|
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
|
+
catch (e1) {
|
|
90
|
+
try {
|
|
91
|
+
file = `${p}/baja.code.js`;
|
|
92
|
+
info(`查找配置文件: ${file}`);
|
|
93
|
+
fs.statSync(file);
|
|
94
|
+
success(`发现配置文件: ${file}`);
|
|
95
|
+
js = true;
|
|
96
|
+
return file;
|
|
97
|
+
}
|
|
98
|
+
catch (e2) {
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
let force = false;
|
|
104
|
+
let basepath = path.join(import.meta.dirname, '..', '..');
|
|
105
|
+
let config = checkPath(basepath);
|
|
106
|
+
if (config === null) {
|
|
107
|
+
basepath = path.join(import.meta.dirname, '..', '..', '..', '..', '..');
|
|
108
|
+
config = checkPath(basepath);
|
|
109
|
+
}
|
|
110
|
+
function help1() {
|
|
110
111
|
console.log(`
|
|
111
112
|
**********************-----------
|
|
112
113
|
${info2('配置文件:')}
|
|
@@ -144,9 +145,9 @@ ${info2('配置示例:')}
|
|
|
144
145
|
${warn2(`command`)}是生成命令,这里声明命令同时定义文件生成路径, 同时要求在模板中必须有对应模板. ${info2('路径是相对于项目根目录的相对路径')}.
|
|
145
146
|
${warn2('commands')}是组合命令,上面的配置表示输入${error2('s')}同时生成:${success2('"entity", "controller", "service", "sql", "module"这几个模块')}
|
|
146
147
|
${warn2('output')} 是生成后打印出的内容
|
|
147
|
-
`);
|
|
148
|
-
}
|
|
149
|
-
function help2() {
|
|
148
|
+
`);
|
|
149
|
+
}
|
|
150
|
+
function help2() {
|
|
150
151
|
console.log(`
|
|
151
152
|
${error2('模板文件说明')}
|
|
152
153
|
使用${error2('mustache')}
|
|
@@ -210,84 +211,65 @@ ${warn2('覆盖生成')} .force
|
|
|
210
211
|
${warn2('配置说明')} .help1
|
|
211
212
|
${warn2('模板说明')} .help2
|
|
212
213
|
-----
|
|
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
|
-
|
|
222
|
-
|
|
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
|
-
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];
|
|
214
|
+
`);
|
|
215
|
+
}
|
|
216
|
+
if (config === null) {
|
|
217
|
+
error('NOT FOUND Config File!!');
|
|
218
|
+
help1();
|
|
219
|
+
throw new Error('NOT FOUND Config File');
|
|
220
|
+
}
|
|
221
|
+
const templatePath = path.join(basepath, 'code-template');
|
|
222
|
+
help2();
|
|
223
|
+
try {
|
|
224
|
+
const outputs = new Set();
|
|
225
|
+
let configData;
|
|
226
|
+
if (js === false) {
|
|
227
|
+
const _configData = fs.readFileSync(config, { encoding: 'utf-8' }).toString();
|
|
228
|
+
configData = JSON.parse(_configData);
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
const _configData = fs.readFileSync(config, { encoding: 'utf-8' }).toString();
|
|
232
|
+
configData = new Function(_configData.replace('export default', 'return'))();
|
|
233
|
+
}
|
|
234
|
+
configData.skipColumns ?? (configData.skipColumns = []);
|
|
235
|
+
configData.command ?? (configData.command = {});
|
|
236
|
+
configData.commands ?? (configData.commands = {});
|
|
237
|
+
configData.output ?? (configData.output = '');
|
|
238
|
+
configData.id ?? (configData.id = 'uuidShort: true, notNull: true, uuid: true');
|
|
239
|
+
configData.logicDeleteK ?? (configData.logicDeleteK = '');
|
|
240
|
+
configData.logicDeleteV ?? (configData.logicDeleteV = 0);
|
|
241
|
+
configData.NotlogicDeleteV ?? (configData.NotlogicDeleteV = 0);
|
|
242
|
+
if (!configData.host || !configData.port || !configData.user || !configData.password || !configData.database) {
|
|
243
|
+
error(`[错误]配置文件缺少必要的参数: host, port, user, password, database`);
|
|
244
|
+
}
|
|
245
|
+
if (!fs.existsSync(templatePath)) {
|
|
246
|
+
error(`[错误]模板文件夹不存在,请在项目根目录创建code-template文件夹`);
|
|
247
|
+
}
|
|
248
|
+
const templates = Object.fromEntries(fs.readdirSync(templatePath).map(r => [path.basename(r, '.mu'), fs.readFileSync(path.join(templatePath, r), { encoding: 'utf-8' }).toString()]));
|
|
249
|
+
const pool = createPool({
|
|
250
|
+
host: configData.host,
|
|
251
|
+
port: configData.port,
|
|
252
|
+
user: configData.user,
|
|
253
|
+
password: configData.password,
|
|
254
|
+
database: configData.database
|
|
255
|
+
});
|
|
256
|
+
async function getTables(tableName) {
|
|
257
|
+
const conn = await pool.getConnection();
|
|
258
|
+
const params = [configData.database];
|
|
277
259
|
let sql = `
|
|
278
260
|
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
|
|
285
|
-
conn.release();
|
|
286
|
-
return result;
|
|
287
|
-
}
|
|
288
|
-
async function getColumns(tableName
|
|
289
|
-
const conn = await pool.getConnection();
|
|
290
|
-
const [result] = await conn.query
|
|
261
|
+
WHERE TABLE_SCHEMA= ? AND TABLE_TYPE = 'BASE TABLE'`;
|
|
262
|
+
if (tableName !== '.') {
|
|
263
|
+
sql += ` AND TABLE_NAME IN (?)`;
|
|
264
|
+
params.push(tableName.split(/,|\s/).map(r => r.trim()));
|
|
265
|
+
}
|
|
266
|
+
const [result] = await conn.query(sql, params);
|
|
267
|
+
conn.release();
|
|
268
|
+
return result;
|
|
269
|
+
}
|
|
270
|
+
async function getColumns(tableName) {
|
|
271
|
+
const conn = await pool.getConnection();
|
|
272
|
+
const [result] = await conn.query(`
|
|
291
273
|
SELECT
|
|
292
274
|
DATA_TYPE type,
|
|
293
275
|
COLUMN_NAME \`name\`,
|
|
@@ -298,229 +280,238 @@ try {
|
|
|
298
280
|
IF(IS_NULLABLE = 'NO', 1, 0) notNull,
|
|
299
281
|
COLUMN_COMMENT \`comment\`
|
|
300
282
|
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) {
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
else
|
|
308
|
-
|
|
309
|
-
r.
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
r.
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
if (r.
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
r.
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
tableName,
|
|
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
|
-
const
|
|
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
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
}
|
|
283
|
+
`, [configData.database, tableName]);
|
|
284
|
+
let logicDelete = '';
|
|
285
|
+
const columns = result.map(r => {
|
|
286
|
+
if (r.id === 1) {
|
|
287
|
+
r.id = true;
|
|
288
|
+
}
|
|
289
|
+
else
|
|
290
|
+
delete r.id;
|
|
291
|
+
if (r.notNull === 1) {
|
|
292
|
+
r.notNull = true;
|
|
293
|
+
}
|
|
294
|
+
else
|
|
295
|
+
delete r.notNull;
|
|
296
|
+
const fields = new Array(`type:SqlType.${r.type}`);
|
|
297
|
+
r.Type = lxMap[r.type];
|
|
298
|
+
if (r.length !== null) {
|
|
299
|
+
fields.push(`length:${r.length}`);
|
|
300
|
+
}
|
|
301
|
+
if (r.scale !== null) {
|
|
302
|
+
fields.push(`scale:${r.scale}`);
|
|
303
|
+
}
|
|
304
|
+
if (r.def !== null) {
|
|
305
|
+
r.def ?? (r.def = '');
|
|
306
|
+
if (r.def !== '') {
|
|
307
|
+
if (isNaN(r.def)) {
|
|
308
|
+
fields.push(`def:'${r.def}'`);
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
fields.push(`def:${r.def}`);
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (r.Type === 'string') {
|
|
316
|
+
if (r.def === '' || r.def === null) {
|
|
317
|
+
r.def = "''";
|
|
318
|
+
}
|
|
319
|
+
else {
|
|
320
|
+
r.def = `'${r.def}'`;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
else if (r.Type === 'number') {
|
|
324
|
+
r.def = 0;
|
|
325
|
+
}
|
|
326
|
+
else if (r.Type === 'Date') {
|
|
327
|
+
r.def = 'new Date()';
|
|
328
|
+
}
|
|
329
|
+
else {
|
|
330
|
+
r.def = 'null';
|
|
331
|
+
}
|
|
332
|
+
if (r.id === true) {
|
|
333
|
+
fields.push(`id:true`);
|
|
334
|
+
}
|
|
335
|
+
if (r.notNull === true) {
|
|
336
|
+
fields.push(`notNull:true`);
|
|
337
|
+
}
|
|
338
|
+
if (r.id === true && configData.id) {
|
|
339
|
+
fields.push(configData.id);
|
|
340
|
+
}
|
|
341
|
+
if (r.name === configData.logicDeleteK) {
|
|
342
|
+
fields.push(`logicDelete: ${configData.logicDeleteV}`);
|
|
343
|
+
logicDelete = `AND ${r.name} = ${configData.NotlogicDeleteV}`;
|
|
344
|
+
}
|
|
345
|
+
if (r.comment) {
|
|
346
|
+
fields.push(`comment: '${r.comment}'`);
|
|
347
|
+
}
|
|
348
|
+
r.comment = r.comment ?? '';
|
|
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 ?? (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
|
+
tableName,
|
|
385
|
+
className,
|
|
386
|
+
ClassName,
|
|
387
|
+
vueName,
|
|
388
|
+
splitVueName,
|
|
389
|
+
splitName,
|
|
390
|
+
SplitName,
|
|
391
|
+
columns,
|
|
392
|
+
column_names: columns?.map(i => i.name),
|
|
393
|
+
ColumnNames: columns?.map(i => i.Name),
|
|
394
|
+
column_names_join: columns?.map(i => i.name).join(','),
|
|
395
|
+
ColumnNames_join: columns?.map(i => `${i.name} ${i.Name}`).join(','),
|
|
396
|
+
column_names_joinT: columns?.map(i => `t.${i.name}`).join(','),
|
|
397
|
+
ColumnNames_joinT: columns?.map(i => `t.${i.name} ${i.Name}`).join(','),
|
|
398
|
+
columns_no_id: columns?.filter(i => !i.id),
|
|
399
|
+
column_names_no_id: columns?.filter(i => !i.id).map(i => i.name),
|
|
400
|
+
ColumnNames_no_id: columns?.filter(i => !i.id).map(i => i.Name),
|
|
401
|
+
column_names_no_id_join: columns?.filter(i => !i.id).map(i => i.name).join(','),
|
|
402
|
+
ColumnNames_no_id_join: columns?.filter(i => !i.id).map(i => i.Name).join(','),
|
|
403
|
+
columns_no_skip: columns?.filter(i => !configData.skipColumns.includes(i.name) && !i.id),
|
|
404
|
+
column_names_no_skip: columns?.filter(i => !configData.skipColumns.includes(i.name) && !i.id).map(i => i.name),
|
|
405
|
+
ColumnNames_no_skip: columns?.filter(i => !configData.skipColumns.includes(i.name) && !i.id).map(i => i.Name),
|
|
406
|
+
column_names_no_skip_join: columns?.filter(i => !configData.skipColumns.includes(i.name) && !i.id).map(i => i.name).join(','),
|
|
407
|
+
ColumnNames_no_skip_join: columns?.filter(i => !configData.skipColumns.includes(i.name) && !i.id).map(i => i.Name).join(','),
|
|
408
|
+
ids: columns?.filter(i => i.id),
|
|
409
|
+
id_names: columns?.filter(i => i.id).map(i => i.name),
|
|
410
|
+
IdNames: columns?.filter(i => i.id).map(i => i.Name),
|
|
411
|
+
id_names_join: columns?.filter(i => i.id).map(i => i.name).join(','),
|
|
412
|
+
IdNames_join: columns?.filter(i => i.id).map(i => i.Name).join(','),
|
|
413
|
+
modelName,
|
|
414
|
+
modelPath,
|
|
415
|
+
logicDelete
|
|
416
|
+
};
|
|
417
|
+
const template = templates[command];
|
|
418
|
+
if (!template) {
|
|
419
|
+
error(`[错误] ${command} 未定义模板!`);
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
const txt = mustache.render(template, data, {}, ['<%', '%>']);
|
|
423
|
+
const _fileName = configData.command[command].replace(/{([a-zA-Z]+)}/g, (a, b) => data[b]);
|
|
424
|
+
const fileNames = _fileName.split(',');
|
|
425
|
+
for (const fileName of fileNames) {
|
|
426
|
+
const filePath = path.join(basepath, fileName);
|
|
427
|
+
const dirname = path.dirname(filePath);
|
|
428
|
+
mkdir('-p', dirname);
|
|
429
|
+
try {
|
|
430
|
+
fs.statSync(filePath);
|
|
431
|
+
if (force === false) {
|
|
432
|
+
warn(`[跳过] ${filePath}`);
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
else {
|
|
436
|
+
warn(`[覆盖] ${filePath}`);
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
catch (error) {
|
|
440
|
+
info(`[生成] ${filePath}`);
|
|
441
|
+
}
|
|
442
|
+
if (configData.output) {
|
|
443
|
+
outputs.add(configData.output.replace(/{([a-zA-Z]+)}/g, (a, b) => data[b]));
|
|
444
|
+
}
|
|
445
|
+
fs.writeFileSync(path.join(basepath, fileName), txt);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
const replServer = start();
|
|
450
|
+
function defineCommand(command, comands) {
|
|
451
|
+
if (comands) {
|
|
452
|
+
log(`\x1b[42m\x1b[30m[组合]${command}>${comands.join(',')}注册成功\x1b[0m`);
|
|
453
|
+
}
|
|
454
|
+
else {
|
|
455
|
+
log(`\x1b[42m\x1b[30m[命令]${command}注册成功\x1b[0m`);
|
|
456
|
+
}
|
|
457
|
+
if (comands) {
|
|
458
|
+
replServer.defineCommand(command, async (input) => {
|
|
459
|
+
outputs.clear();
|
|
460
|
+
const inputs = input.match(/([^:]+):{0,1}([a-zA-Z0-9]*)/);
|
|
461
|
+
if (inputs?.length !== 3) {
|
|
462
|
+
return error(`[错误]命令格式应为: table1,table2[:模块名]`);
|
|
463
|
+
}
|
|
464
|
+
const [_, tables, modelName] = inputs;
|
|
465
|
+
for (const c of comands) {
|
|
466
|
+
await excute(c, tables, modelName ?? '');
|
|
467
|
+
}
|
|
468
|
+
info('执行完毕!下面打印生成的输出');
|
|
469
|
+
info(Array.from(outputs).join(','));
|
|
470
|
+
});
|
|
471
|
+
}
|
|
472
|
+
else {
|
|
473
|
+
replServer.defineCommand(command, async (input) => {
|
|
474
|
+
outputs.clear();
|
|
475
|
+
const inputs = input.match(/([^:]+):{0,1}([a-zA-Z0-9]*)/);
|
|
476
|
+
if (inputs?.length !== 3) {
|
|
477
|
+
return error(`[错误]命令格式应为: table1,table2[:模块名]`);
|
|
478
|
+
}
|
|
479
|
+
const [_, tables, modelName] = inputs;
|
|
480
|
+
await excute(command, tables, modelName ?? '');
|
|
481
|
+
info('执行完毕!下面打印生成的输出');
|
|
482
|
+
info(Array.from(outputs).join(','));
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
replServer.defineCommand('force', () => {
|
|
487
|
+
force = !force;
|
|
488
|
+
log(force ? '覆盖生成' : '不覆盖生成!');
|
|
489
|
+
});
|
|
490
|
+
replServer.defineCommand('help1', help1);
|
|
491
|
+
replServer.defineCommand('help2', help2);
|
|
492
|
+
if (configData.command) {
|
|
493
|
+
for (const command of Object.keys(configData.command)) {
|
|
494
|
+
if (!templates[command]) {
|
|
495
|
+
error(`命令:${command}没有定义模板,该命令不会生效`);
|
|
496
|
+
}
|
|
497
|
+
else {
|
|
498
|
+
defineCommand(command);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
if (configData.commands) {
|
|
503
|
+
for (const [command, commands] of Object.entries(configData.commands)) {
|
|
504
|
+
const keys = commands;
|
|
505
|
+
const e = keys.filter(k => !templates[k]).join(',');
|
|
506
|
+
if (e) {
|
|
507
|
+
error(`组合命令:${command}定义了${commands},但是${e}没有定义模板,该命令不会生效`);
|
|
508
|
+
}
|
|
509
|
+
else {
|
|
510
|
+
defineCommand(command, keys);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
catch (error) {
|
|
516
|
+
error(error);
|
|
517
|
+
}
|