baja-lite 1.1.4 → 1.1.8
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} +6 -7
- package/boot.d.ts +2 -0
- package/{src/boot.ts → boot.js} +32 -39
- package/code.d.ts +2 -0
- package/{src/code.ts → code.js} +69 -69
- package/convert-xml.d.ts +10 -0
- package/{src/convert-xml.ts → convert-xml.js} +105 -155
- package/enum.d.ts +18 -0
- package/enum.js +59 -0
- package/error.d.ts +5 -0
- package/error.js +13 -0
- package/fn.d.ts +128 -0
- package/fn.js +172 -0
- package/{src/index.ts → index.d.ts} +11 -11
- package/index.js +11 -0
- package/list.d.ts +10 -0
- package/{src/list.ts → list.js} +8 -9
- package/math.d.ts +83 -0
- package/math.js +451 -0
- package/object.d.ts +83 -0
- package/object.js +221 -0
- package/package.json +2 -1
- package/set-ex.d.ts +198 -0
- package/set-ex.js +338 -0
- package/sql.d.ts +1858 -0
- package/sql.js +5025 -0
- package/sqlite.d.ts +32 -0
- package/{src/sqlite.ts → sqlite.js} +53 -52
- package/string.d.ts +17 -0
- package/string.js +105 -0
- package/test-mysql.d.ts +2 -0
- package/{src/test-mysql.ts → test-mysql.js} +135 -126
- package/test-postgresql.d.ts +2 -0
- package/test-postgresql.js +90 -0
- package/test-sqlite.d.ts +1 -0
- package/{src/test-sqlite.ts → test-sqlite.js} +89 -80
- package/test-xml.d.ts +1 -0
- package/{src/test-xml.ts → test-xml.js} +1 -1
- package/test.d.ts +1 -0
- package/test.js +2 -0
- package/wx/base.d.ts +11 -0
- package/wx/base.js +78 -0
- package/wx/mini.d.ts +45 -0
- package/wx/mini.js +102 -0
- package/wx/organ.d.ts +65 -0
- package/wx/organ.js +171 -0
- package/{src/wx/types.ts → wx/types.d.ts} +21 -10
- package/wx/types.js +1 -0
- package/wx.js +3 -0
- package/.eslintignore +0 -7
- package/.eslintrc.cjs +0 -89
- package/.prettierrc +0 -4
- package/ci.js +0 -29
- package/package-cjs.json +0 -17
- package/src/enum.ts +0 -71
- package/src/error.ts +0 -11
- package/src/fn.ts +0 -295
- 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/string.ts +0 -111
- package/src/test-postgresql.ts +0 -79
- package/src/test.ts +0 -2
- package/src/wx/base.ts +0 -76
- package/src/wx/mini.ts +0 -133
- package/src/wx/organ.ts +0 -290
- package/test.json +0 -0
- package/tsconfig.base.json +0 -80
- package/tsconfig.cjs.json +0 -42
- package/tsconfig.json +0 -44
- package/xml/event-report.xml +0 -13
- package/yarn.lock +0 -1493
- /package/{Readme.md → README.md} +0 -0
- /package/{src/wx.ts → wx.d.ts} +0 -0
package/boot-remote.d.ts
ADDED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { getEnums } from './enum.js';
|
|
2
|
-
import { _primaryDB, _dao, logger, DBType, _sqlCache, _GlobalSqlOption,
|
|
3
|
-
|
|
4
|
-
export const BootRomote = async function (options: GlobalSqlOptionForWeb) {
|
|
2
|
+
import { _primaryDB, _dao, logger, DBType, _sqlCache, _GlobalSqlOption, _defOption, SqlCache, SqliteRemote, _Hump, ColumnMode, _enums } from './sql.js';
|
|
3
|
+
export const BootRomote = async function (options) {
|
|
5
4
|
globalThis[_GlobalSqlOption] = Object.assign({}, _defOption, options);
|
|
6
5
|
globalThis[_Hump] = globalThis[_GlobalSqlOption].columnMode === ColumnMode.HUMP;
|
|
7
6
|
logger.level = options.log ?? 'info';
|
|
@@ -19,7 +18,8 @@ export const BootRomote = async function (options: GlobalSqlOptionForWeb) {
|
|
|
19
18
|
if (typeof options.SqliteRemote.db === 'string') {
|
|
20
19
|
options.SqliteRemote.service.initDB(options.SqliteRemote.db);
|
|
21
20
|
globalThis[_dao][DBType.SqliteRemote][_primaryDB] = new SqliteRemote(options.SqliteRemote.service, options.SqliteRemote.db);
|
|
22
|
-
}
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
23
|
let flag = false;
|
|
24
24
|
for (const [key, fileName] of Object.entries(options.SqliteRemote.db)) {
|
|
25
25
|
await options.SqliteRemote.service.initDB(fileName);
|
|
@@ -32,8 +32,7 @@ export const BootRomote = async function (options: GlobalSqlOptionForWeb) {
|
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
|
-
}
|
|
36
|
-
|
|
35
|
+
};
|
|
37
36
|
// export const AppendRomote = async function (dbName: string) {
|
|
38
37
|
// if (!globalThis[_dao][DBType.SqliteRemote][dbName]) {
|
|
39
38
|
// globalThis[_GlobalSqlOption].SqliteRemote.service.initDB(dbName);
|
|
@@ -43,4 +42,4 @@ export const BootRomote = async function (options: GlobalSqlOptionForWeb) {
|
|
|
43
42
|
// }
|
|
44
43
|
// globalThis[_dao][DBType.SqliteRemote][dbName] = db;
|
|
45
44
|
// }
|
|
46
|
-
// }
|
|
45
|
+
// }
|
package/boot.d.ts
ADDED
package/{src/boot.ts → boot.js}
RENAMED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { getEnums } from './enum.js';
|
|
2
|
-
import { _GlobalSqlOption,
|
|
3
|
-
|
|
4
|
-
export const Boot = async function (options: GlobalSqlOption) {
|
|
2
|
+
import { _GlobalSqlOption, _enums, _EventBus, _defOption, logger, _sqlCache, SqlCache, _dao, DBType, _primaryDB, SqliteRemote, _fs, _path, Mysql, Sqlite, _Hump, ColumnMode, Postgresql } from './sql.js';
|
|
3
|
+
export const Boot = async function (options) {
|
|
5
4
|
globalThis[_GlobalSqlOption] = Object.assign({}, _defOption, options);
|
|
6
5
|
globalThis[_Hump] = globalThis[_GlobalSqlOption].columnMode === ColumnMode.HUMP;
|
|
7
6
|
if (options.sqlDir) {
|
|
@@ -33,8 +32,8 @@ export const Boot = async function (options: GlobalSqlOption) {
|
|
|
33
32
|
decimalNumbers: true,
|
|
34
33
|
supportBigNumbers: true
|
|
35
34
|
}));
|
|
36
|
-
|
|
37
|
-
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
38
37
|
let flag = false;
|
|
39
38
|
for (const [key, option] of Object.entries(options.Mysql)) {
|
|
40
39
|
const db = new Mysql(createPool({
|
|
@@ -43,7 +42,6 @@ export const Boot = async function (options: GlobalSqlOption) {
|
|
|
43
42
|
decimalNumbers: true,
|
|
44
43
|
supportBigNumbers: true
|
|
45
44
|
}));
|
|
46
|
-
|
|
47
45
|
if (flag === false) {
|
|
48
46
|
globalThis[_dao][DBType.Mysql][_primaryDB] = db;
|
|
49
47
|
flag = true;
|
|
@@ -55,7 +53,8 @@ export const Boot = async function (options: GlobalSqlOption) {
|
|
|
55
53
|
if (options.Sqlite) {
|
|
56
54
|
if (typeof options.Sqlite === 'string') {
|
|
57
55
|
globalThis[_dao][DBType.Sqlite][_primaryDB] = new Sqlite(new options.BetterSqlite3(options.Sqlite, { fileMustExist: false }));
|
|
58
|
-
}
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
59
58
|
let flag = false;
|
|
60
59
|
for (const [key, fileName] of Object.entries(options.Sqlite)) {
|
|
61
60
|
const db = new Sqlite(new options.BetterSqlite3(fileName, { fileMustExist: false }));
|
|
@@ -71,7 +70,8 @@ export const Boot = async function (options: GlobalSqlOption) {
|
|
|
71
70
|
if (typeof options.SqliteRemote.db === 'string') {
|
|
72
71
|
options.SqliteRemote.service.initDB(options.SqliteRemote.db);
|
|
73
72
|
globalThis[_dao][DBType.SqliteRemote][_primaryDB] = new SqliteRemote(options.SqliteRemote.service, options.SqliteRemote.db);
|
|
74
|
-
}
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
75
|
let flag = false;
|
|
76
76
|
for (const [key, fileName] of Object.entries(options.SqliteRemote.db)) {
|
|
77
77
|
options.SqliteRemote.service.initDB(fileName);
|
|
@@ -88,7 +88,8 @@ export const Boot = async function (options: GlobalSqlOption) {
|
|
|
88
88
|
const { Redis } = await import('ioredis');
|
|
89
89
|
if (options.Redis['host']) {
|
|
90
90
|
globalThis[_dao][DBType.Redis][_primaryDB] = new Redis(options.Redis);
|
|
91
|
-
}
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
92
93
|
let flag = false;
|
|
93
94
|
for (const [key, option] of Object.entries(options.Redis)) {
|
|
94
95
|
const db = new Redis(option);
|
|
@@ -99,32 +100,25 @@ export const Boot = async function (options: GlobalSqlOption) {
|
|
|
99
100
|
globalThis[_dao][DBType.Redis][key] = db;
|
|
100
101
|
}
|
|
101
102
|
}
|
|
102
|
-
const clients = Object.values(globalThis[_dao][DBType.Redis])
|
|
103
|
+
const clients = Object.values(globalThis[_dao][DBType.Redis]);
|
|
103
104
|
const Redlock = await import('redlock');
|
|
104
|
-
globalThis[_dao][DBType.RedisLock] = new Redlock.default(
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
retryJitter: 200, // time in ms
|
|
122
|
-
|
|
123
|
-
// The minimum remaining time on a lock before an extension is automatically
|
|
124
|
-
// attempted with the `using` API.
|
|
125
|
-
automaticExtensionThreshold: 500, // time in ms
|
|
126
|
-
}
|
|
127
|
-
);
|
|
105
|
+
globalThis[_dao][DBType.RedisLock] = new Redlock.default(clients, {
|
|
106
|
+
// The expected clock drift; for more details see:
|
|
107
|
+
// http://redis.io/topics/distlock
|
|
108
|
+
driftFactor: 0.01, // multiplied by lock ttl to determine drift time
|
|
109
|
+
// The max number of times Redlock will attempt to lock a resource
|
|
110
|
+
// before erroring.
|
|
111
|
+
retryCount: 10,
|
|
112
|
+
// the time in ms between attempts
|
|
113
|
+
retryDelay: 200, // time in ms
|
|
114
|
+
// the max time in ms randomly added to retries
|
|
115
|
+
// to improve performance under high contention
|
|
116
|
+
// see https://www.awsarchitectureblog.com/2015/03/backoff.html
|
|
117
|
+
retryJitter: 200, // time in ms
|
|
118
|
+
// The minimum remaining time on a lock before an extension is automatically
|
|
119
|
+
// attempted with the `using` API.
|
|
120
|
+
automaticExtensionThreshold: 500, // time in ms
|
|
121
|
+
});
|
|
128
122
|
const { EventEmitter } = await import('events');
|
|
129
123
|
const event = new EventEmitter({ captureRejections: true });
|
|
130
124
|
event.on('error', error => {
|
|
@@ -133,15 +127,14 @@ export const Boot = async function (options: GlobalSqlOption) {
|
|
|
133
127
|
globalThis[_EventBus] = event;
|
|
134
128
|
}
|
|
135
129
|
if (options.Postgresql) {
|
|
136
|
-
const Pool
|
|
130
|
+
const Pool = await import('pg-pool');
|
|
137
131
|
if (options.Postgresql['host']) {
|
|
138
132
|
globalThis[_dao][DBType.Postgresql][_primaryDB] = new Postgresql(new Pool.default(options.Postgresql));
|
|
139
|
-
|
|
140
|
-
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
141
135
|
let flag = false;
|
|
142
136
|
for (const [key, option] of Object.entries(options.Postgresql)) {
|
|
143
137
|
const db = new Postgresql(new Pool.default(option));
|
|
144
|
-
|
|
145
138
|
if (flag === false) {
|
|
146
139
|
globalThis[_dao][DBType.Postgresql][_primaryDB] = db;
|
|
147
140
|
flag = true;
|
|
@@ -150,4 +143,4 @@ export const Boot = async function (options: GlobalSqlOption) {
|
|
|
150
143
|
}
|
|
151
144
|
}
|
|
152
145
|
}
|
|
153
|
-
}
|
|
146
|
+
};
|
package/code.d.ts
ADDED
package/{src/code.ts → code.js}
RENAMED
|
@@ -5,7 +5,6 @@ import { start } from 'repl';
|
|
|
5
5
|
import { createPool } from 'mysql2/promise';
|
|
6
6
|
import mustache from 'mustache';
|
|
7
7
|
import { mkdir } from 'shelljs';
|
|
8
|
-
|
|
9
8
|
const lxMap = {
|
|
10
9
|
tinyint: "number",
|
|
11
10
|
smallint: "number",
|
|
@@ -48,7 +47,7 @@ const lxMap = {
|
|
|
48
47
|
geometrycollection: "Object"
|
|
49
48
|
};
|
|
50
49
|
let force = false;
|
|
51
|
-
const basepath = path.join(__dirname, '..', '..'
|
|
50
|
+
const basepath = path.join(__dirname, '..', '..');
|
|
52
51
|
const config = path.join(basepath, 'baja.code.json');
|
|
53
52
|
const templatePath = path.join(basepath, 'code-template');
|
|
54
53
|
console.log(`
|
|
@@ -110,7 +109,8 @@ console.log(`
|
|
|
110
109
|
], Field(类型string),表示字段的注解, Type 表示JS类型
|
|
111
110
|
columnNames_join: 'sku_id, sku_name'
|
|
112
111
|
ColumnNames_join: 'sku_id skuId, sku_name skuName'
|
|
113
|
-
|
|
112
|
+
columnNames_joinT: 't.sku_id, t.sku_name'
|
|
113
|
+
ColumnNames_joinT: 't.sku_id skuId, t.sku_name skuName'
|
|
114
114
|
columns_no_id: [], 同columns,没有ID而已
|
|
115
115
|
columnNames_no_id: [],
|
|
116
116
|
|
|
@@ -129,26 +129,10 @@ console.log(`
|
|
|
129
129
|
-----
|
|
130
130
|
force: 切换是否覆盖
|
|
131
131
|
`);
|
|
132
|
-
|
|
133
|
-
|
|
134
132
|
try {
|
|
135
|
-
const outputs = new Set
|
|
133
|
+
const outputs = new Set();
|
|
136
134
|
const _configData = fs.readFileSync(config, { encoding: 'utf-8' }).toString();
|
|
137
|
-
const configData = JSON.parse(_configData)
|
|
138
|
-
host: string;
|
|
139
|
-
port: number;
|
|
140
|
-
user: string;
|
|
141
|
-
password: string;
|
|
142
|
-
database: string;
|
|
143
|
-
command: Record<string, string>;
|
|
144
|
-
commands: Record<string, string[]>;
|
|
145
|
-
output: string;
|
|
146
|
-
id: string;
|
|
147
|
-
logicDeleteK: string;
|
|
148
|
-
logicDeleteV: number;
|
|
149
|
-
NotlogicDeleteV: number;
|
|
150
|
-
tables: string;
|
|
151
|
-
};
|
|
135
|
+
const configData = JSON.parse(_configData);
|
|
152
136
|
const templates = Object.fromEntries(fs.readdirSync(templatePath).map(r => [path.basename(r, '.mu'), fs.readFileSync(path.join(templatePath, r), { encoding: 'utf-8' }).toString()]));
|
|
153
137
|
const pool = createPool({
|
|
154
138
|
host: configData.host,
|
|
@@ -157,9 +141,9 @@ try {
|
|
|
157
141
|
password: configData.password,
|
|
158
142
|
database: configData.database
|
|
159
143
|
});
|
|
160
|
-
async function getTables(tableName
|
|
144
|
+
async function getTables(tableName) {
|
|
161
145
|
const conn = await pool.getConnection();
|
|
162
|
-
const params
|
|
146
|
+
const params = [configData.database];
|
|
163
147
|
let sql = `
|
|
164
148
|
SELECT TABLE_NAME tableName, IFNULL(TABLE_COMMENT, TABLE_NAME) title FROM information_schema.TABLES
|
|
165
149
|
WHERE TABLE_SCHEMA= ? AND TABLE_TYPE = 'BASE TABLE'`;
|
|
@@ -167,13 +151,13 @@ try {
|
|
|
167
151
|
sql += ` AND TABLE_NAME IN (?)`;
|
|
168
152
|
params.push(tableName.split(/,|\s/).map(r => r.trim()));
|
|
169
153
|
}
|
|
170
|
-
const [result] = await conn.query
|
|
154
|
+
const [result] = await conn.query(sql, params);
|
|
171
155
|
conn.release();
|
|
172
156
|
return result;
|
|
173
157
|
}
|
|
174
|
-
async function getColumns(tableName
|
|
158
|
+
async function getColumns(tableName) {
|
|
175
159
|
const conn = await pool.getConnection();
|
|
176
|
-
const [result] = await conn.query
|
|
160
|
+
const [result] = await conn.query(`
|
|
177
161
|
SELECT
|
|
178
162
|
DATA_TYPE type,
|
|
179
163
|
COLUMN_NAME \`name\`,
|
|
@@ -187,27 +171,38 @@ try {
|
|
|
187
171
|
`, [configData.database, tableName]);
|
|
188
172
|
let logicDelete = '';
|
|
189
173
|
const columns = result.map(r => {
|
|
190
|
-
if (r.id === 1) {
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
else
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
174
|
+
if (r.id === 1) {
|
|
175
|
+
r.id = true;
|
|
176
|
+
}
|
|
177
|
+
else
|
|
178
|
+
delete r.id;
|
|
179
|
+
if (r.notNull === 1) {
|
|
180
|
+
r.notNull = true;
|
|
181
|
+
}
|
|
182
|
+
else
|
|
183
|
+
delete r.notNull;
|
|
184
|
+
const fields = new Array(`type:SqlType.${r.type}`);
|
|
185
|
+
if (r.length !== null) {
|
|
186
|
+
fields.push(`length:${r.length}`);
|
|
187
|
+
}
|
|
188
|
+
if (r.scale !== null) {
|
|
189
|
+
fields.push(`scale:${r.scale}`);
|
|
190
|
+
}
|
|
199
191
|
if (r.def !== null) {
|
|
200
|
-
r.def
|
|
192
|
+
r.def ?? (r.def = '');
|
|
201
193
|
if (isNaN(r.def) || r.def === '') {
|
|
202
194
|
fields.push(`def:'${r.def}'`);
|
|
203
|
-
}
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
204
197
|
fields.push(`def:${r.def}`);
|
|
205
198
|
}
|
|
206
199
|
}
|
|
207
200
|
if (r.id === true) {
|
|
208
201
|
fields.push(`id:true`);
|
|
209
202
|
}
|
|
210
|
-
if (r.notNull === true) {
|
|
203
|
+
if (r.notNull === true) {
|
|
204
|
+
fields.push(`notNull:true`);
|
|
205
|
+
}
|
|
211
206
|
if (r.id === true && configData.id) {
|
|
212
207
|
fields.push(configData.id);
|
|
213
208
|
}
|
|
@@ -215,66 +210,64 @@ try {
|
|
|
215
210
|
fields.push(`logicDelete: ${configData.logicDeleteV}`);
|
|
216
211
|
logicDelete = `AND ${r.name} = ${configData.NotlogicDeleteV}`;
|
|
217
212
|
}
|
|
218
|
-
if (r.comment) {
|
|
213
|
+
if (r.comment) {
|
|
214
|
+
fields.push(`comment: '${r.comment}'`);
|
|
215
|
+
}
|
|
219
216
|
r.comment = r.comment ?? '';
|
|
220
217
|
r.Type = lxMap[r.type];
|
|
221
218
|
r.Field = `@Field({${fields.join(',')}})`;
|
|
222
|
-
r.Name = r.name.replace(/_(\w)/g, (a
|
|
223
|
-
r.NAME = r.Name.replace(/\w/, (v
|
|
219
|
+
r.Name = r.name.replace(/_(\w)/g, (a, b) => b.toUpperCase());
|
|
220
|
+
r.NAME = r.Name.replace(/\w/, (v) => v.toUpperCase());
|
|
224
221
|
return r;
|
|
225
222
|
});
|
|
226
223
|
conn.release();
|
|
227
224
|
return { columns, logicDelete };
|
|
228
225
|
}
|
|
229
|
-
async function excute(command
|
|
226
|
+
async function excute(command, input, modelName) {
|
|
230
227
|
const tables = await getTables(input);
|
|
231
228
|
if (input !== '.') {
|
|
232
|
-
const checkTable = input.split(/,|\s/).map(r => r.trim())
|
|
229
|
+
const checkTable = input.split(/,|\s/).map(r => r.trim());
|
|
233
230
|
if (checkTable.length !== tables.length) {
|
|
234
231
|
console.error(`[错误] 输入的表与数据库查询返回表不符,数据库返回${tables.length}个:${tables.map(i => i.tableName).join(',')}`);
|
|
235
232
|
return;
|
|
236
233
|
}
|
|
237
234
|
}
|
|
238
|
-
modelName
|
|
235
|
+
modelName ?? (modelName = '');
|
|
239
236
|
const modelPath = modelName ? `/${modelName}/` : '';
|
|
240
237
|
for (const { tableName, title } of tables) {
|
|
241
238
|
const { columns, logicDelete } = await getColumns(tableName);
|
|
242
|
-
const className = tableName.replace(/_(\w)/g, (a
|
|
243
|
-
const ClassName = className.replace(/\w/, (v
|
|
239
|
+
const className = tableName.replace(/_(\w)/g, (a, b) => b.toUpperCase());
|
|
240
|
+
const ClassName = className.replace(/\w/, (v) => v.toUpperCase());
|
|
244
241
|
const vueName = tableName.replace(/_/g, '-');
|
|
245
242
|
const splitName = tableName.replace(/_/g, '/');
|
|
246
|
-
const SplitName = tableName.replace(/_/, '/').replace(/_(\w)/g, (a
|
|
243
|
+
const SplitName = tableName.replace(/_/, '/').replace(/_(\w)/g, (a, b) => b.toUpperCase());
|
|
247
244
|
const data = {
|
|
248
245
|
title,
|
|
249
|
-
|
|
250
246
|
tableName,
|
|
251
247
|
className,
|
|
252
248
|
ClassName,
|
|
253
249
|
vueName,
|
|
254
250
|
splitName,
|
|
255
251
|
SplitName,
|
|
256
|
-
|
|
257
252
|
columns,
|
|
258
253
|
columnNames: columns?.map(i => i.name),
|
|
259
254
|
ColumnNames: columns?.map(i => i.Name),
|
|
260
255
|
columnNames_join: columns?.map(i => i.name).join(','),
|
|
261
256
|
ColumnNames_join: columns?.map(i => `${i.name} ${i.Name}`).join(','),
|
|
262
|
-
|
|
257
|
+
columnNames_joinT: columns?.map(i => `t.${i.name}`).join(','),
|
|
258
|
+
ColumnNames_joinT: columns?.map(i => `t.${i.name} ${i.Name}`).join(','),
|
|
263
259
|
columns_no_id: columns?.filter(i => !i.id),
|
|
264
260
|
columnNames_no_id: columns?.filter(i => !i.id).map(i => i.name),
|
|
265
261
|
ColumnNames_no_id: columns?.filter(i => !i.id).map(i => i.Name),
|
|
266
262
|
columnNames_no_id_join: columns?.filter(i => !i.id).map(i => i.name).join(','),
|
|
267
263
|
ColumnNames_no_id_join: columns?.filter(i => !i.id).map(i => i.Name).join(','),
|
|
268
|
-
|
|
269
264
|
ids: columns?.filter(i => i.id),
|
|
270
265
|
idNames: columns?.filter(i => i.id).map(i => i.name),
|
|
271
266
|
IdNames: columns?.filter(i => i.id).map(i => i.Name),
|
|
272
267
|
idNames_join: columns?.filter(i => i.id).map(i => i.name).join(','),
|
|
273
268
|
IdNames_join: columns?.filter(i => i.id).map(i => i.Name).join(','),
|
|
274
|
-
|
|
275
269
|
modelName,
|
|
276
270
|
modelPath,
|
|
277
|
-
|
|
278
271
|
logicDelete
|
|
279
272
|
};
|
|
280
273
|
const template = templates[command];
|
|
@@ -283,9 +276,9 @@ try {
|
|
|
283
276
|
return;
|
|
284
277
|
}
|
|
285
278
|
const txt = mustache.render(template, data, {}, ['<%', '%>']);
|
|
286
|
-
const _fileName = configData.command[command]
|
|
279
|
+
const _fileName = configData.command[command].replace(/{([a-zA-Z]+)}/g, (a, b) => data[b]);
|
|
287
280
|
const fileNames = _fileName.split(',');
|
|
288
|
-
for(const fileName of fileNames){
|
|
281
|
+
for (const fileName of fileNames) {
|
|
289
282
|
const filePath = path.join(basepath, fileName);
|
|
290
283
|
const dirname = path.dirname(filePath);
|
|
291
284
|
mkdir('-p', dirname);
|
|
@@ -300,28 +293,31 @@ try {
|
|
|
300
293
|
if (force === false) {
|
|
301
294
|
console.warn(`[跳过] ${filePath}`);
|
|
302
295
|
return;
|
|
303
|
-
}
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
304
298
|
console.warn(`[覆盖] ${filePath}`);
|
|
305
299
|
}
|
|
306
|
-
}
|
|
300
|
+
}
|
|
301
|
+
catch (error) {
|
|
307
302
|
console.info(`[生成] ${filePath}`);
|
|
308
303
|
}
|
|
309
304
|
if (configData.output) {
|
|
310
|
-
outputs.add(configData.output.replace(/{([a-zA-Z]+)}/g, (a
|
|
305
|
+
outputs.add(configData.output.replace(/{([a-zA-Z]+)}/g, (a, b) => data[b]));
|
|
311
306
|
}
|
|
312
307
|
fs.writeFileSync(path.join(basepath, fileName), txt);
|
|
313
308
|
}
|
|
314
309
|
}
|
|
315
310
|
}
|
|
316
311
|
const replServer = start();
|
|
317
|
-
function defineCommand(command
|
|
312
|
+
function defineCommand(command, comands) {
|
|
318
313
|
if (comands) {
|
|
319
314
|
console.log(`[组合]${command}>${comands.join(',')}注册成功`);
|
|
320
|
-
}
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
321
317
|
console.log(`[命令]${command}注册成功`);
|
|
322
318
|
}
|
|
323
319
|
if (comands) {
|
|
324
|
-
replServer.defineCommand(command, async input => {
|
|
320
|
+
replServer.defineCommand(command, async (input) => {
|
|
325
321
|
outputs.clear();
|
|
326
322
|
const inputs = input.match(/([^:]+):{0,1}([a-zA-Z0-9]*)/);
|
|
327
323
|
if (inputs?.length !== 3) {
|
|
@@ -329,20 +325,21 @@ try {
|
|
|
329
325
|
}
|
|
330
326
|
const [_, tables, modelName] = inputs;
|
|
331
327
|
for (const c of comands) {
|
|
332
|
-
await excute(c, tables
|
|
328
|
+
await excute(c, tables, modelName ?? '');
|
|
333
329
|
}
|
|
334
330
|
console.info('执行完毕!下面打印生成的输出');
|
|
335
331
|
console.info(Array.from(outputs).join(','));
|
|
336
332
|
});
|
|
337
|
-
}
|
|
338
|
-
|
|
333
|
+
}
|
|
334
|
+
else {
|
|
335
|
+
replServer.defineCommand(command, async (input) => {
|
|
339
336
|
outputs.clear();
|
|
340
337
|
const inputs = input.match(/([^:]+):{0,1}([a-zA-Z0-9]*)/);
|
|
341
338
|
if (inputs?.length !== 3) {
|
|
342
339
|
return console.error(`[错误]命令格式应为: table1,table2[:模块名]`);
|
|
343
340
|
}
|
|
344
341
|
const [_, tables, modelName] = inputs;
|
|
345
|
-
await excute(command, tables
|
|
342
|
+
await excute(command, tables, modelName ?? '');
|
|
346
343
|
console.info('执行完毕!下面打印生成的输出');
|
|
347
344
|
console.info(Array.from(outputs).join(','));
|
|
348
345
|
});
|
|
@@ -356,22 +353,25 @@ try {
|
|
|
356
353
|
for (const command of Object.keys(configData.command)) {
|
|
357
354
|
if (!templates[command]) {
|
|
358
355
|
console.error(`命令:${command}没有定义模板,该命令不会生效`);
|
|
359
|
-
}
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
360
358
|
defineCommand(command);
|
|
361
359
|
}
|
|
362
360
|
}
|
|
363
361
|
}
|
|
364
362
|
if (configData.commands) {
|
|
365
363
|
for (const [command, commands] of Object.entries(configData.commands)) {
|
|
366
|
-
const keys = commands
|
|
364
|
+
const keys = commands;
|
|
367
365
|
const error = keys.filter(k => !templates[k]).join(',');
|
|
368
366
|
if (error) {
|
|
369
367
|
console.error(`组合命令:${command}定义了${commands},但是${error}没有定义模板,该命令不会生效`);
|
|
370
|
-
}
|
|
368
|
+
}
|
|
369
|
+
else {
|
|
371
370
|
defineCommand(command, keys);
|
|
372
371
|
}
|
|
373
372
|
}
|
|
374
373
|
}
|
|
375
|
-
}
|
|
374
|
+
}
|
|
375
|
+
catch (error) {
|
|
376
376
|
console.error(error);
|
|
377
377
|
}
|
package/convert-xml.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface XML {
|
|
2
|
+
type: 'tag' | 'text';
|
|
3
|
+
name: string;
|
|
4
|
+
id?: string;
|
|
5
|
+
voidElement: boolean;
|
|
6
|
+
attrs: Record<string, string>;
|
|
7
|
+
children: XML[];
|
|
8
|
+
content: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const convert: (childrens: XML[], param: Record<string, any>, parentIds: string[], myBatisMapper: Record<string, XML[]>) => string;
|