baja-lite 1.0.33 → 1.0.34
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/{cjs/boot-remote.d.ts → boot-remote.d.ts} +1 -1
- package/{es/boot-remote.js → boot-remote.js} +2 -2
- package/{es/boot.d.ts → boot.d.ts} +1 -1
- package/{es/boot.js → boot.js} +2 -2
- package/{es/enum.js → enum.js} +1 -1
- package/{es/fn.js → fn.js} +2 -2
- package/index.d.ts +12 -0
- package/index.js +12 -0
- package/package.json +6 -8
- package/{cjs/sql.d.ts → sql.d.ts} +3 -3
- package/{es/sql.js → sql.js} +7 -7
- package/{es/sqlite.d.ts → sqlite.d.ts} +1 -1
- package/{es/sqlite.js → sqlite.js} +1 -1
- package/{es/test-mysql.js → test-mysql.js} +2 -2
- package/{es/test-postgresql.js → test-postgresql.js} +2 -2
- package/cjs/boot-remote.js +0 -49
- package/cjs/boot.d.ts +0 -2
- package/cjs/boot.js +0 -183
- package/cjs/code.js +0 -379
- package/cjs/convert-xml.js +0 -417
- package/cjs/enum.js +0 -64
- package/cjs/error.js +0 -16
- package/cjs/fn.js +0 -179
- package/cjs/index.d.ts +0 -10
- package/cjs/index.js +0 -26
- package/cjs/list.js +0 -60
- package/cjs/math.js +0 -474
- package/cjs/object.js +0 -242
- package/cjs/set-ex.js +0 -345
- package/cjs/sql.js +0 -5083
- package/cjs/sqlite.d.ts +0 -32
- package/cjs/sqlite.js +0 -169
- package/cjs/string.js +0 -119
- package/cjs/test-mysql.js +0 -138
- package/cjs/test-postgresql.js +0 -93
- package/cjs/test-sqlite.js +0 -91
- package/cjs/test-xml.js +0 -75
- package/cjs/test.js +0 -4
- package/es/boot-remote.d.ts +0 -2
- package/es/code.d.ts +0 -2
- package/es/convert-xml.d.ts +0 -10
- package/es/enum.d.ts +0 -18
- package/es/error.d.ts +0 -5
- package/es/fn.d.ts +0 -128
- package/es/index.d.ts +0 -10
- package/es/index.js +0 -10
- package/es/list.d.ts +0 -10
- package/es/math.d.ts +0 -83
- package/es/object.d.ts +0 -83
- package/es/set-ex.d.ts +0 -198
- package/es/sql.d.ts +0 -1858
- package/es/string.d.ts +0 -17
- package/es/test-mysql.d.ts +0 -2
- package/es/test-postgresql.d.ts +0 -2
- package/es/test-sqlite.d.ts +0 -1
- package/es/test-xml.d.ts +0 -1
- package/es/test.d.ts +0 -1
- package/src/boot-remote.ts +0 -46
- package/src/boot.ts +0 -153
- package/src/code.ts +0 -377
- package/src/convert-xml.ts +0 -460
- package/src/enum.ts +0 -71
- package/src/error.ts +0 -11
- package/src/fn.ts +0 -295
- package/src/index.ts +0 -10
- package/src/list.ts +0 -57
- package/src/math.ts +0 -405
- package/src/object.ts +0 -247
- package/src/set-ex.ts +0 -374
- package/src/sql.ts +0 -5281
- package/src/sqlite.ts +0 -161
- package/src/string.ts +0 -111
- package/src/test-mysql.ts +0 -126
- package/src/test-postgresql.ts +0 -79
- package/src/test-sqlite.ts +0 -80
- package/src/test-xml.ts +0 -70
- package/src/test.ts +0 -2
- /package/{cjs/code.d.ts → code.d.ts} +0 -0
- /package/{es/code.js → code.js} +0 -0
- /package/{cjs/convert-xml.d.ts → convert-xml.d.ts} +0 -0
- /package/{es/convert-xml.js → convert-xml.js} +0 -0
- /package/{cjs/enum.d.ts → enum.d.ts} +0 -0
- /package/{cjs/error.d.ts → error.d.ts} +0 -0
- /package/{es/error.js → error.js} +0 -0
- /package/{cjs/fn.d.ts → fn.d.ts} +0 -0
- /package/{cjs/list.d.ts → list.d.ts} +0 -0
- /package/{es/list.js → list.js} +0 -0
- /package/{cjs/math.d.ts → math.d.ts} +0 -0
- /package/{es/math.js → math.js} +0 -0
- /package/{cjs/object.d.ts → object.d.ts} +0 -0
- /package/{es/object.js → object.js} +0 -0
- /package/{cjs/set-ex.d.ts → set-ex.d.ts} +0 -0
- /package/{es/set-ex.js → set-ex.js} +0 -0
- /package/{cjs/string.d.ts → string.d.ts} +0 -0
- /package/{es/string.js → string.js} +0 -0
- /package/{cjs/test-mysql.d.ts → test-mysql.d.ts} +0 -0
- /package/{cjs/test-postgresql.d.ts → test-postgresql.d.ts} +0 -0
- /package/{cjs/test-sqlite.d.ts → test-sqlite.d.ts} +0 -0
- /package/{es/test-sqlite.js → test-sqlite.js} +0 -0
- /package/{cjs/test-xml.d.ts → test-xml.d.ts} +0 -0
- /package/{es/test-xml.js → test-xml.js} +0 -0
- /package/{cjs/test.d.ts → test.d.ts} +0 -0
- /package/{es/test.js → test.js} +0 -0
package/cjs/code.js
DELETED
|
@@ -1,379 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
"use strict";
|
|
3
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
-
};
|
|
6
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
-
const path_1 = __importDefault(require("path"));
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const repl_1 = require("repl");
|
|
10
|
-
const promise_1 = require("mysql2/promise");
|
|
11
|
-
const mustache_1 = __importDefault(require("mustache"));
|
|
12
|
-
const shelljs_1 = require("shelljs");
|
|
13
|
-
const lxMap = {
|
|
14
|
-
tinyint: "number",
|
|
15
|
-
smallint: "number",
|
|
16
|
-
mediumint: "number",
|
|
17
|
-
int: "number",
|
|
18
|
-
integer: "number",
|
|
19
|
-
bigint: "BigInt",
|
|
20
|
-
bit: "boolean",
|
|
21
|
-
double: "number",
|
|
22
|
-
real: "number",
|
|
23
|
-
float: "number",
|
|
24
|
-
decimal: "number",
|
|
25
|
-
numeric: "number",
|
|
26
|
-
char: "string",
|
|
27
|
-
varchar: "string",
|
|
28
|
-
date: "Date",
|
|
29
|
-
time: "string",
|
|
30
|
-
year: "string",
|
|
31
|
-
timestamp: "BigInt",
|
|
32
|
-
datetime: "Date",
|
|
33
|
-
tinyblob: "string",
|
|
34
|
-
blob: "string",
|
|
35
|
-
mediumblob: "string",
|
|
36
|
-
longblob: "string",
|
|
37
|
-
tinytext: "string",
|
|
38
|
-
text: "string",
|
|
39
|
-
mediumtext: "string",
|
|
40
|
-
longtext: "string",
|
|
41
|
-
enum: "string",
|
|
42
|
-
set: "string",
|
|
43
|
-
binary: "string",
|
|
44
|
-
varbinary: "string",
|
|
45
|
-
point: "Object",
|
|
46
|
-
linestring: "Object",
|
|
47
|
-
polygon: "Object",
|
|
48
|
-
geometry: "string",
|
|
49
|
-
multipoint: "Object",
|
|
50
|
-
multilinestring: "Object",
|
|
51
|
-
multipolygon: "Object",
|
|
52
|
-
geometrycollection: "Object"
|
|
53
|
-
};
|
|
54
|
-
let force = false;
|
|
55
|
-
const basepath = path_1.default.join(__dirname, '..', '..', '..');
|
|
56
|
-
const config = path_1.default.join(basepath, 'baja.code.json');
|
|
57
|
-
const templatePath = path_1.default.join(basepath, 'code-template');
|
|
58
|
-
console.log(`
|
|
59
|
-
**********************-----------
|
|
60
|
-
配置文件:
|
|
61
|
-
请在项目根目录添加文件:baja.code.json!配置如下:
|
|
62
|
-
{
|
|
63
|
-
"host": "",
|
|
64
|
-
"port": "",
|
|
65
|
-
"user": "",
|
|
66
|
-
"password": "",
|
|
67
|
-
"database": "",
|
|
68
|
-
|
|
69
|
-
"command": {
|
|
70
|
-
"entity": "src/{vueName}/{vueName}.entity.ts",
|
|
71
|
-
"controller": "src/{vueName}/{vueName}.controller.ts",
|
|
72
|
-
"service": "src/{vueName}/{vueName}.service.ts",
|
|
73
|
-
"sql": "src/sql/{vueName}.mu",
|
|
74
|
-
"module": "src/{vueName}/{vueName}.module.ts"
|
|
75
|
-
},
|
|
76
|
-
"commands": {
|
|
77
|
-
"s": ["entity", "controller", "service", "sql", "module"]
|
|
78
|
-
}
|
|
79
|
-
"commands": {
|
|
80
|
-
"s": ["entity", "controller", "service", "sql", "module"]
|
|
81
|
-
},
|
|
82
|
-
"output": "{ClassName}Module",
|
|
83
|
-
"id"? : "uuidShort: true, notNull: true, uuid: true",
|
|
84
|
-
"logicDeleteK"?: "逻辑删除字段名",
|
|
85
|
-
"logicDeleteV"?: "逻辑删除值",如果是字符串需要这样 logicDeleteV: "'0'"
|
|
86
|
-
"NotlogicDeleteV"?: "未逻辑删除值",如果是字符串需要这样 NotlogicDeleteV: "'0'"
|
|
87
|
-
}
|
|
88
|
-
command是生成命令,这里声明命令同时定义文件生成路径:可用下面的变量替换.同时必须有同名模板.
|
|
89
|
-
路径是相对于项目根目录的
|
|
90
|
-
commands是组合命令,上面表示输入s,同时生成:"entity", "controller", "service", "sql", "module"
|
|
91
|
-
output 是生成后打印出的内容
|
|
92
|
-
模板转义:<%& 变量 %>
|
|
93
|
-
**********************-----------
|
|
94
|
-
**********************-----------
|
|
95
|
-
**********************-----------
|
|
96
|
-
模板文件
|
|
97
|
-
请在项目根目录的code-template添加模板文件, 按照mustache(标签定义成了[ '<%', '%>' ])进行格式化,变量:
|
|
98
|
-
title,
|
|
99
|
-
|
|
100
|
-
tableName, event_main_info
|
|
101
|
-
className, eventMainInfo
|
|
102
|
-
ClassName, EventMainInfo
|
|
103
|
-
vueName, event-main-info
|
|
104
|
-
splitName, event/main/info
|
|
105
|
-
SplitName, event/mainInfo
|
|
106
|
-
|
|
107
|
-
columns: [
|
|
108
|
-
comment:
|
|
109
|
-
name: sku_id
|
|
110
|
-
Name: skuId
|
|
111
|
-
NAME: SkuId
|
|
112
|
-
Field
|
|
113
|
-
Type
|
|
114
|
-
], Field(类型string),表示字段的注解, Type 表示JS类型
|
|
115
|
-
columnNames_join: 'sku_id, sku_name'
|
|
116
|
-
ColumnNames_join: 'sku_id skuId, sku_name skuName'
|
|
117
|
-
|
|
118
|
-
columns_no_id: [], 同columns,没有ID而已
|
|
119
|
-
columnNames_no_id: [],
|
|
120
|
-
|
|
121
|
-
ids: [], 参见 FieldOption,多一个参数Field,表示字段的注解, Type 表示JS类型
|
|
122
|
-
idNames: [], 主键字段数组
|
|
123
|
-
idNames_join: []
|
|
124
|
-
|
|
125
|
-
modelName: 模块名称,可能为空字符串
|
|
126
|
-
modelPath: 模块名称实际就影响访问路径,所以这里会直接拼好controller的模块访问路径,如果模块为空,则该属性就是空字符串,否则是 /模块名称/
|
|
127
|
-
|
|
128
|
-
logicDelete: 逻辑删除的查询条件,可以附加在sql条件的末尾,可能是空的
|
|
129
|
-
-----
|
|
130
|
-
命令 table1,table2,table3:模块名称
|
|
131
|
-
table=. 表示扫描全库表
|
|
132
|
-
:模块名称 可以省略
|
|
133
|
-
-----
|
|
134
|
-
force: 切换是否覆盖
|
|
135
|
-
`);
|
|
136
|
-
try {
|
|
137
|
-
const outputs = new Set();
|
|
138
|
-
const _configData = fs_1.default.readFileSync(config, { encoding: 'utf-8' }).toString();
|
|
139
|
-
const configData = JSON.parse(_configData);
|
|
140
|
-
const templates = Object.fromEntries(fs_1.default.readdirSync(templatePath).map(r => [path_1.default.basename(r, '.mu'), fs_1.default.readFileSync(path_1.default.join(templatePath, r), { encoding: 'utf-8' }).toString()]));
|
|
141
|
-
const pool = (0, promise_1.createPool)({
|
|
142
|
-
host: configData.host,
|
|
143
|
-
port: configData.port,
|
|
144
|
-
user: configData.user,
|
|
145
|
-
password: configData.password,
|
|
146
|
-
database: configData.database
|
|
147
|
-
});
|
|
148
|
-
async function getTables(tableName) {
|
|
149
|
-
const conn = await pool.getConnection();
|
|
150
|
-
const params = [configData.database];
|
|
151
|
-
let sql = `
|
|
152
|
-
SELECT TABLE_NAME tableName, IFNULL(TABLE_COMMENT, TABLE_NAME) title FROM information_schema.TABLES
|
|
153
|
-
WHERE TABLE_SCHEMA= ? AND TABLE_TYPE = 'BASE TABLE'`;
|
|
154
|
-
if (tableName !== '.') {
|
|
155
|
-
sql += ` AND TABLE_NAME IN (?)`;
|
|
156
|
-
params.push(tableName.split(/,|\s/).map(r => r.trim()));
|
|
157
|
-
}
|
|
158
|
-
const [result] = await conn.query(sql, params);
|
|
159
|
-
conn.release();
|
|
160
|
-
return result;
|
|
161
|
-
}
|
|
162
|
-
async function getColumns(tableName) {
|
|
163
|
-
const conn = await pool.getConnection();
|
|
164
|
-
const [result] = await conn.query(`
|
|
165
|
-
SELECT
|
|
166
|
-
DATA_TYPE type,
|
|
167
|
-
COLUMN_NAME \`name\`,
|
|
168
|
-
IFNULL(IFNULL(CHARACTER_MAXIMUM_LENGTH,NUMERIC_PRECISION),DATETIME_PRECISION) \`length\`,
|
|
169
|
-
NUMERIC_SCALE scale,
|
|
170
|
-
COLUMN_DEFAULT def,
|
|
171
|
-
IF(COLUMN_KEY = 'PRI', 1, 0) id,
|
|
172
|
-
IF(IS_NULLABLE = 'NO', 1, 0) notNull,
|
|
173
|
-
COLUMN_COMMENT \`comment\`
|
|
174
|
-
FROM information_schema.COLUMNS WHERE TABLE_SCHEMA=? AND TABLE_NAME = ?;
|
|
175
|
-
`, [configData.database, tableName]);
|
|
176
|
-
let logicDelete = '';
|
|
177
|
-
const columns = result.map(r => {
|
|
178
|
-
if (r.id === 1) {
|
|
179
|
-
r.id = true;
|
|
180
|
-
}
|
|
181
|
-
else
|
|
182
|
-
delete r.id;
|
|
183
|
-
if (r.notNull === 1) {
|
|
184
|
-
r.notNull = true;
|
|
185
|
-
}
|
|
186
|
-
else
|
|
187
|
-
delete r.notNull;
|
|
188
|
-
const fields = new Array(`type:SqlType.${r.type}`);
|
|
189
|
-
if (r.length !== null) {
|
|
190
|
-
fields.push(`length:${r.length}`);
|
|
191
|
-
}
|
|
192
|
-
if (r.scale !== null) {
|
|
193
|
-
fields.push(`scale:${r.scale}`);
|
|
194
|
-
}
|
|
195
|
-
if (r.def !== null) {
|
|
196
|
-
r.def ?? (r.def = '');
|
|
197
|
-
if (isNaN(r.def) || r.def === '') {
|
|
198
|
-
fields.push(`def:'${r.def}'`);
|
|
199
|
-
}
|
|
200
|
-
else {
|
|
201
|
-
fields.push(`def:${r.def}`);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
if (r.id === true) {
|
|
205
|
-
fields.push(`id:true`);
|
|
206
|
-
}
|
|
207
|
-
if (r.notNull === true) {
|
|
208
|
-
fields.push(`notNull:true`);
|
|
209
|
-
}
|
|
210
|
-
if (r.id === true && configData.id) {
|
|
211
|
-
fields.push(configData.id);
|
|
212
|
-
}
|
|
213
|
-
if (r.name === configData.logicDeleteK) {
|
|
214
|
-
fields.push(`logicDelete: ${configData.logicDeleteV}`);
|
|
215
|
-
logicDelete = `AND ${r.name} = ${configData.NotlogicDeleteV}`;
|
|
216
|
-
}
|
|
217
|
-
if (r.comment) {
|
|
218
|
-
fields.push(`comment: '${r.comment}'`);
|
|
219
|
-
}
|
|
220
|
-
r.comment = r.comment ?? '';
|
|
221
|
-
r.Type = lxMap[r.type];
|
|
222
|
-
r.Field = `@Field({${fields.join(',')}})`;
|
|
223
|
-
r.Name = r.name.replace(/_(\w)/g, (a, b) => b.toUpperCase());
|
|
224
|
-
r.NAME = r.Name.replace(/\w/, (v) => v.toUpperCase());
|
|
225
|
-
return r;
|
|
226
|
-
});
|
|
227
|
-
conn.release();
|
|
228
|
-
return { columns, logicDelete };
|
|
229
|
-
}
|
|
230
|
-
async function excute(command, input, modelName) {
|
|
231
|
-
const tables = await getTables(input);
|
|
232
|
-
if (input !== '.') {
|
|
233
|
-
const checkTable = input.split(/,|\s/).map(r => r.trim());
|
|
234
|
-
if (checkTable.length !== tables.length) {
|
|
235
|
-
console.error(`[错误] 输入的表与数据库查询返回表不符,数据库返回${tables.length}个:${tables.map(i => i.tableName).join(',')}`);
|
|
236
|
-
return;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
modelName ?? (modelName = '');
|
|
240
|
-
const modelPath = modelName ? `/${modelName}/` : '';
|
|
241
|
-
for (const { tableName, title } of tables) {
|
|
242
|
-
const { columns, logicDelete } = await getColumns(tableName);
|
|
243
|
-
const className = tableName.replace(/_(\w)/g, (a, b) => b.toUpperCase());
|
|
244
|
-
const ClassName = className.replace(/\w/, (v) => v.toUpperCase());
|
|
245
|
-
const vueName = tableName.replace(/_/g, '-');
|
|
246
|
-
const splitName = tableName.replace(/_/g, '/');
|
|
247
|
-
const SplitName = tableName.replace(/_/, '/').replace(/_(\w)/g, (a, b) => b.toUpperCase());
|
|
248
|
-
const data = {
|
|
249
|
-
title,
|
|
250
|
-
tableName,
|
|
251
|
-
className,
|
|
252
|
-
ClassName,
|
|
253
|
-
vueName,
|
|
254
|
-
splitName,
|
|
255
|
-
SplitName,
|
|
256
|
-
columns,
|
|
257
|
-
columnNames: columns?.map(i => i.name),
|
|
258
|
-
ColumnNames: columns?.map(i => i.Name),
|
|
259
|
-
columnNames_join: columns?.map(i => i.name).join(','),
|
|
260
|
-
ColumnNames_join: columns?.map(i => `${i.name} ${i.Name}`).join(','),
|
|
261
|
-
columns_no_id: columns?.filter(i => !i.id),
|
|
262
|
-
columnNames_no_id: columns?.filter(i => !i.id).map(i => i.name),
|
|
263
|
-
ColumnNames_no_id: columns?.filter(i => !i.id).map(i => i.Name),
|
|
264
|
-
columnNames_no_id_join: columns?.filter(i => !i.id).map(i => i.name).join(','),
|
|
265
|
-
ColumnNames_no_id_join: columns?.filter(i => !i.id).map(i => i.Name).join(','),
|
|
266
|
-
ids: columns?.filter(i => i.id),
|
|
267
|
-
idNames: columns?.filter(i => i.id).map(i => i.name),
|
|
268
|
-
IdNames: columns?.filter(i => i.id).map(i => i.Name),
|
|
269
|
-
idNames_join: columns?.filter(i => i.id).map(i => i.name).join(','),
|
|
270
|
-
IdNames_join: columns?.filter(i => i.id).map(i => i.Name).join(','),
|
|
271
|
-
modelName,
|
|
272
|
-
modelPath,
|
|
273
|
-
logicDelete
|
|
274
|
-
};
|
|
275
|
-
const template = templates[command];
|
|
276
|
-
if (!template) {
|
|
277
|
-
console.error(`[错误] ${command} 未定义模板!`);
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
const txt = mustache_1.default.render(template, data, {}, ['<%', '%>']);
|
|
281
|
-
const _fileName = configData.command[command].replace(/{([a-zA-Z]+)}/g, (a, b) => data[b]);
|
|
282
|
-
const fileNames = _fileName.split(',');
|
|
283
|
-
for (const fileName of fileNames) {
|
|
284
|
-
const filePath = path_1.default.join(basepath, fileName);
|
|
285
|
-
const dirname = path_1.default.dirname(filePath);
|
|
286
|
-
(0, shelljs_1.mkdir)('-p', dirname);
|
|
287
|
-
// try {
|
|
288
|
-
// fs.statSync(dirname);
|
|
289
|
-
// } catch (error) {
|
|
290
|
-
// fs.mkdirSync(dirname);
|
|
291
|
-
// console.info(`[生成] ${dirname}`);
|
|
292
|
-
// }
|
|
293
|
-
try {
|
|
294
|
-
fs_1.default.statSync(filePath);
|
|
295
|
-
if (force === false) {
|
|
296
|
-
console.warn(`[跳过] ${filePath}`);
|
|
297
|
-
return;
|
|
298
|
-
}
|
|
299
|
-
else {
|
|
300
|
-
console.warn(`[覆盖] ${filePath}`);
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
catch (error) {
|
|
304
|
-
console.info(`[生成] ${filePath}`);
|
|
305
|
-
}
|
|
306
|
-
if (configData.output) {
|
|
307
|
-
outputs.add(configData.output.replace(/{([a-zA-Z]+)}/g, (a, b) => data[b]));
|
|
308
|
-
}
|
|
309
|
-
fs_1.default.writeFileSync(path_1.default.join(basepath, fileName), txt);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
const replServer = (0, repl_1.start)();
|
|
314
|
-
function defineCommand(command, comands) {
|
|
315
|
-
if (comands) {
|
|
316
|
-
console.log(`[组合]${command}>${comands.join(',')}注册成功`);
|
|
317
|
-
}
|
|
318
|
-
else {
|
|
319
|
-
console.log(`[命令]${command}注册成功`);
|
|
320
|
-
}
|
|
321
|
-
if (comands) {
|
|
322
|
-
replServer.defineCommand(command, async (input) => {
|
|
323
|
-
outputs.clear();
|
|
324
|
-
const inputs = input.match(/([^:]+):{0,1}([a-zA-Z0-9]*)/);
|
|
325
|
-
if (inputs?.length !== 3) {
|
|
326
|
-
return console.error(`[错误]命令格式应为: table1,table2[:模块名]`);
|
|
327
|
-
}
|
|
328
|
-
const [_, tables, modelName] = inputs;
|
|
329
|
-
for (const c of comands) {
|
|
330
|
-
await excute(c, tables, modelName ?? '');
|
|
331
|
-
}
|
|
332
|
-
console.info('执行完毕!下面打印生成的输出');
|
|
333
|
-
console.info(Array.from(outputs).join(','));
|
|
334
|
-
});
|
|
335
|
-
}
|
|
336
|
-
else {
|
|
337
|
-
replServer.defineCommand(command, async (input) => {
|
|
338
|
-
outputs.clear();
|
|
339
|
-
const inputs = input.match(/([^:]+):{0,1}([a-zA-Z0-9]*)/);
|
|
340
|
-
if (inputs?.length !== 3) {
|
|
341
|
-
return console.error(`[错误]命令格式应为: table1,table2[:模块名]`);
|
|
342
|
-
}
|
|
343
|
-
const [_, tables, modelName] = inputs;
|
|
344
|
-
await excute(command, tables, modelName ?? '');
|
|
345
|
-
console.info('执行完毕!下面打印生成的输出');
|
|
346
|
-
console.info(Array.from(outputs).join(','));
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
replServer.defineCommand('force', () => {
|
|
351
|
-
force = !force;
|
|
352
|
-
console.log(force ? '覆盖生成' : '不覆盖生成!');
|
|
353
|
-
});
|
|
354
|
-
if (configData.command) {
|
|
355
|
-
for (const command of Object.keys(configData.command)) {
|
|
356
|
-
if (!templates[command]) {
|
|
357
|
-
console.error(`命令:${command}没有定义模板,该命令不会生效`);
|
|
358
|
-
}
|
|
359
|
-
else {
|
|
360
|
-
defineCommand(command);
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
}
|
|
364
|
-
if (configData.commands) {
|
|
365
|
-
for (const [command, commands] of Object.entries(configData.commands)) {
|
|
366
|
-
const keys = commands;
|
|
367
|
-
const error = keys.filter(k => !templates[k]).join(',');
|
|
368
|
-
if (error) {
|
|
369
|
-
console.error(`组合命令:${command}定义了${commands},但是${error}没有定义模板,该命令不会生效`);
|
|
370
|
-
}
|
|
371
|
-
else {
|
|
372
|
-
defineCommand(command, keys);
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
catch (error) {
|
|
378
|
-
console.error(error);
|
|
379
|
-
}
|