@biuxiu/codegen 0.2.12 → 0.2.14
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/code/nest.d.ts +2 -2
- package/dist/code/nest.js +33 -35
- package/dist/code/vue.d.ts +11 -0
- package/dist/code/vue.js +176 -0
- package/dist/config.d.ts +2 -0
- package/dist/config.js +6 -0
- package/dist/format/api.js +10 -1
- package/dist/gen-type.js +4 -4
- package/dist/index.d.ts +6 -4
- package/dist/index.js +21 -20
- package/dist/libs/nest-lib.d.ts +2 -2
- package/dist/libs/nest-lib.js +17 -11
- package/dist/libs.d.ts +9 -0
- package/dist/libs.js +51 -0
- package/dist/lua_codegen_bg.js +4 -6
- package/dist/lua_codegen_bg.wasm +0 -0
- package/dist/render.js +1 -4
- package/dist/task.d.ts +6 -0
- package/dist/task.js +16 -0
- package/dist/types.d.ts +13 -3
- package/dist/util.d.ts +2 -2
- package/dist/util.js +9 -10
- package/package.json +4 -3
package/dist/code/nest.d.ts
CHANGED
@@ -2,8 +2,8 @@ import { ApiServiceField, DtoField, EntityField } from '../types';
|
|
2
2
|
export declare class RenderNest {
|
3
3
|
#private;
|
4
4
|
constructor(name: string, path?: string);
|
5
|
-
remove(): void
|
6
|
-
editAppModule(isDelete?: boolean): void
|
5
|
+
remove(): Promise<void>;
|
6
|
+
editAppModule(isDelete?: boolean): Promise<void>;
|
7
7
|
genModule(): Promise<void>;
|
8
8
|
genApiService(apiService: ApiServiceField[]): Promise<void>;
|
9
9
|
genEntity(entity: EntityField[]): Promise<void>;
|
package/dist/code/nest.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import xiu from "../render";
|
2
2
|
import { join } from "path";
|
3
|
-
import {
|
3
|
+
import { writeFormatFile } from "../util";
|
4
4
|
import { existsSync, mkdirSync, statSync } from "fs";
|
5
5
|
import { DTOFromat } from "../format/dto";
|
6
6
|
import { EntityFormat } from "../format/entity";
|
@@ -44,15 +44,14 @@ class RenderNest {
|
|
44
44
|
await unlink(filePath);
|
45
45
|
}
|
46
46
|
}
|
47
|
-
rmdir(path);
|
47
|
+
await rmdir(path);
|
48
48
|
}
|
49
|
-
remove() {
|
49
|
+
async remove() {
|
50
50
|
if (existsSync(this.#moduleDir)) {
|
51
|
-
this.#deleteDir(this.#moduleDir);
|
51
|
+
await this.#deleteDir(this.#moduleDir);
|
52
52
|
}
|
53
|
-
this.editAppModule(true);
|
54
53
|
}
|
55
|
-
editAppModule(isDelete = false) {
|
54
|
+
async editAppModule(isDelete = false) {
|
56
55
|
if (!isDelete) {
|
57
56
|
let basePath = "";
|
58
57
|
const apiDir = getApiDir();
|
@@ -131,16 +130,15 @@ class RenderNest {
|
|
131
130
|
consumerStatement.replaceWithText(newText);
|
132
131
|
}
|
133
132
|
}
|
134
|
-
await source.
|
135
|
-
await reFromatFile(appModuleFile);
|
133
|
+
await writeFormatFile(appModuleFile, source.getFullText());
|
136
134
|
}
|
137
135
|
});
|
138
|
-
runEditTask();
|
136
|
+
await runEditTask();
|
139
137
|
}
|
140
138
|
async genModule() {
|
141
139
|
const modulePath = join(this.#moduleDir, `${this.#name}.module.ts`);
|
142
140
|
const moduleStr = await xiu.render("module", { name: this.#name });
|
143
|
-
writeFormatFile(modulePath, moduleStr);
|
141
|
+
await writeFormatFile(modulePath, moduleStr);
|
144
142
|
}
|
145
143
|
async genApiService(apiService) {
|
146
144
|
const controllerPath = join(
|
@@ -152,24 +150,26 @@ class RenderNest {
|
|
152
150
|
this.#name,
|
153
151
|
apiService
|
154
152
|
).format();
|
155
|
-
xiu.render("controller", {
|
156
|
-
name: this.#name,
|
157
|
-
importInfo: apiImport,
|
158
|
-
content: apiContent
|
159
|
-
}).then((controllerStr) => {
|
160
|
-
writeFormatFile(controllerPath, controllerStr);
|
161
|
-
});
|
162
153
|
const [serviceImport, serviceContent] = new ServiceFormat(
|
163
154
|
this.#name,
|
164
155
|
apiService
|
165
156
|
).format();
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
157
|
+
const [controllerStr, serviceStr] = await Promise.all([
|
158
|
+
xiu.render("controller", {
|
159
|
+
name: this.#name,
|
160
|
+
importInfo: apiImport,
|
161
|
+
content: apiContent
|
162
|
+
}),
|
163
|
+
xiu.render("service", {
|
164
|
+
name: this.#name,
|
165
|
+
content: serviceContent,
|
166
|
+
importInfo: serviceImport
|
167
|
+
})
|
168
|
+
]);
|
169
|
+
await Promise.all([
|
170
|
+
writeFormatFile(controllerPath, controllerStr),
|
171
|
+
writeFormatFile(servicePath, serviceStr)
|
172
|
+
]);
|
173
173
|
}
|
174
174
|
async genEntity(entity) {
|
175
175
|
const entityDir = join(this.#moduleDir, "entities");
|
@@ -183,7 +183,7 @@ class RenderNest {
|
|
183
183
|
importInfo,
|
184
184
|
content
|
185
185
|
});
|
186
|
-
writeFormatFile(entityPath, entityStr);
|
186
|
+
await writeFormatFile(entityPath, entityStr);
|
187
187
|
}
|
188
188
|
async genDto(dto) {
|
189
189
|
const dtoPath = join(this.#moduleDir, "dto");
|
@@ -193,16 +193,14 @@ class RenderNest {
|
|
193
193
|
const createDtoPath = join(dtoPath, `create-${this.#name}.dto.ts`);
|
194
194
|
const updateDtoPath = join(dtoPath, `update-${this.#name}.dto.ts`);
|
195
195
|
const [importInfo, content] = new DTOFromat(dto).format();
|
196
|
-
const createDtoStr = await
|
197
|
-
importInfo,
|
198
|
-
name: this.#name
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
writeFormatFile(createDtoPath, createDtoStr);
|
205
|
-
writeFormatFile(updateDtoPath, updateDtoStr);
|
196
|
+
const [createDtoStr, updateDtoStr] = await Promise.all([
|
197
|
+
xiu.render("create-dto", { importInfo, name: this.#name, content }),
|
198
|
+
xiu.render("update-dto", { name: this.#name })
|
199
|
+
]);
|
200
|
+
await Promise.all([
|
201
|
+
writeFormatFile(createDtoPath, createDtoStr),
|
202
|
+
writeFormatFile(updateDtoPath, updateDtoStr)
|
203
|
+
]);
|
206
204
|
}
|
207
205
|
}
|
208
206
|
export {
|
@@ -0,0 +1,11 @@
|
|
1
|
+
import { ApiServiceField, FieldSchema, ModuleConfig, ModuleRoute } from '@/types';
|
2
|
+
export declare class RenderVue {
|
3
|
+
#private;
|
4
|
+
constructor(name: string, path?: string);
|
5
|
+
editDir(isDelete?: boolean): Promise<void>;
|
6
|
+
setDatabase(route: ModuleRoute, isDelete?: boolean): Promise<undefined>;
|
7
|
+
genRoute(route: ModuleRoute): Promise<void>;
|
8
|
+
genVueTable({ name, comment }: ModuleConfig, fields: FieldSchema[]): Promise<void>;
|
9
|
+
genVueForm(config: ModuleConfig, fields: FieldSchema[]): Promise<void>;
|
10
|
+
genTsFile(fields: FieldSchema[], api: ApiServiceField[]): Promise<void>;
|
11
|
+
}
|
package/dist/code/vue.js
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
import { getSqliteFile, getWebDir } from "@/config";
|
2
|
+
import xiu from "@/render";
|
3
|
+
import { writeFormatFile } from "@/util";
|
4
|
+
import { existsSync, mkdirSync, statSync } from "fs";
|
5
|
+
import { readdir, rmdir, unlink } from "fs/promises";
|
6
|
+
import { join } from "path";
|
7
|
+
import Database from "better-sqlite3";
|
8
|
+
class RenderVue {
|
9
|
+
#moduleDir;
|
10
|
+
#name;
|
11
|
+
#path;
|
12
|
+
#formatPath(path) {
|
13
|
+
return path.split("/").filter((p) => p).join("/");
|
14
|
+
}
|
15
|
+
constructor(name, path) {
|
16
|
+
this.#path = path ? path.endsWith("/") ? `${this.#formatPath(path)}/${name}` : this.#formatPath(path) : name;
|
17
|
+
const webDir = getWebDir();
|
18
|
+
this.#name = name;
|
19
|
+
this.#moduleDir = join(webDir, this.#path);
|
20
|
+
}
|
21
|
+
async #deleteDir(path) {
|
22
|
+
const files = await readdir(path);
|
23
|
+
for (let i = 0; i < files.length; i++) {
|
24
|
+
const filePath = join(path, files[i]);
|
25
|
+
if (statSync(filePath).isDirectory()) {
|
26
|
+
await this.#deleteDir(filePath);
|
27
|
+
} else {
|
28
|
+
await unlink(filePath);
|
29
|
+
}
|
30
|
+
}
|
31
|
+
await rmdir(path);
|
32
|
+
}
|
33
|
+
async editDir(isDelete = false) {
|
34
|
+
if (isDelete) {
|
35
|
+
if (existsSync(this.#moduleDir)) {
|
36
|
+
await this.#deleteDir(this.#moduleDir);
|
37
|
+
}
|
38
|
+
} else {
|
39
|
+
let basePath = "";
|
40
|
+
const apiDir = getWebDir();
|
41
|
+
if (this.#path.includes("/")) {
|
42
|
+
const pathArr = this.#path.split("/");
|
43
|
+
for (let i = 0; i < pathArr.length; i++) {
|
44
|
+
const curPath = pathArr[i];
|
45
|
+
if (i === 0) {
|
46
|
+
basePath = join(apiDir, curPath);
|
47
|
+
} else {
|
48
|
+
basePath = join(basePath, curPath);
|
49
|
+
}
|
50
|
+
if (!existsSync(basePath)) {
|
51
|
+
mkdirSync(basePath);
|
52
|
+
}
|
53
|
+
}
|
54
|
+
} else {
|
55
|
+
basePath = join(apiDir, this.#path);
|
56
|
+
if (!existsSync(basePath)) {
|
57
|
+
mkdirSync(basePath);
|
58
|
+
}
|
59
|
+
}
|
60
|
+
}
|
61
|
+
}
|
62
|
+
#findIdByKey(key, select) {
|
63
|
+
const result = select.get(key);
|
64
|
+
return result ? result.id : void 0;
|
65
|
+
}
|
66
|
+
async setDatabase(route, isDelete = false) {
|
67
|
+
const sqliteFile = getSqliteFile();
|
68
|
+
if (!existsSync(sqliteFile)) {
|
69
|
+
return;
|
70
|
+
}
|
71
|
+
const db = new Database(sqliteFile);
|
72
|
+
const selectStmt = db.prepare(
|
73
|
+
`SELECT id FROM w_permission WHERE key = ?`
|
74
|
+
);
|
75
|
+
const insertStmt = db.prepare(
|
76
|
+
`INSERT INTO w_permission (title, key, description, pid) VALUES (@title, @key, @description, @pid)`
|
77
|
+
);
|
78
|
+
const deleteStmt = db.prepare(`DELETE FROM w_permission WHERE key = ?`);
|
79
|
+
const hasPremissionTbl = db.prepare(
|
80
|
+
`SELECT name FROM sqlite_master WHERE type='table' AND name=?`
|
81
|
+
).get("w_permission");
|
82
|
+
if (!hasPremissionTbl) {
|
83
|
+
return Promise.reject("\u6743\u9650\u8868\u4E0D\u5B58\u5728");
|
84
|
+
}
|
85
|
+
const pathList = route.path.split("/").filter((p) => p);
|
86
|
+
const prefixKey = pathList.length > 1 ? "#" + pathList[0].replaceAll("-", "_") : "";
|
87
|
+
let pid = null;
|
88
|
+
if (prefixKey) {
|
89
|
+
const id = this.#findIdByKey(prefixKey, selectStmt);
|
90
|
+
if (!id) return Promise.reject(`\u7236\u7EA7\u6743\u9650${prefixKey}\u4E0D\u5B58\u5728`);
|
91
|
+
pid = id;
|
92
|
+
}
|
93
|
+
const key = "#" + pathList.join("_").replaceAll("-", "_");
|
94
|
+
let fn;
|
95
|
+
if (isDelete) {
|
96
|
+
const list = ["@add", "@update", "@delete"].map((k) => key + k);
|
97
|
+
fn = db.transaction(() => {
|
98
|
+
for (const k of list) {
|
99
|
+
deleteStmt.run(k);
|
100
|
+
}
|
101
|
+
deleteStmt.run(key);
|
102
|
+
});
|
103
|
+
} else {
|
104
|
+
const keyId = this.#findIdByKey(key, selectStmt);
|
105
|
+
if (keyId) return Promise.reject(`\u5F53\u524D\u6743\u9650${key}\u5DF2\u5B58\u5728`);
|
106
|
+
const list = [
|
107
|
+
{ k: "@add", title: "\u6DFB\u52A0" },
|
108
|
+
{ k: "@update", title: "\u4FEE\u6539" },
|
109
|
+
{ k: "@delete", title: "\u5220\u9664" }
|
110
|
+
].map(({ k, title }) => ({
|
111
|
+
title: title + route.title,
|
112
|
+
key: key + k,
|
113
|
+
description: title + route.title + "\u4FE1\u606F"
|
114
|
+
}));
|
115
|
+
fn = db.transaction(() => {
|
116
|
+
const { lastInsertRowid } = insertStmt.run({
|
117
|
+
key,
|
118
|
+
title: route.title,
|
119
|
+
description: `${route.title}\u9875\u9762\u67E5\u770B`,
|
120
|
+
pid
|
121
|
+
});
|
122
|
+
for (const item of list) {
|
123
|
+
insertStmt.run({ ...item, pid: lastInsertRowid });
|
124
|
+
}
|
125
|
+
});
|
126
|
+
}
|
127
|
+
try {
|
128
|
+
fn();
|
129
|
+
} catch (error) {
|
130
|
+
return Promise.reject(error);
|
131
|
+
}
|
132
|
+
}
|
133
|
+
async genRoute(route) {
|
134
|
+
const filePath = join(this.#moduleDir, "meta.json");
|
135
|
+
const source = await xiu.render("route-mata", route);
|
136
|
+
await writeFormatFile(filePath, source, "json");
|
137
|
+
}
|
138
|
+
async genVueTable({ name, comment }, fields) {
|
139
|
+
const filePath = join(this.#moduleDir, "index.vue");
|
140
|
+
const source = await xiu.render("index-vue", {
|
141
|
+
name,
|
142
|
+
comment,
|
143
|
+
fields
|
144
|
+
});
|
145
|
+
await writeFormatFile(filePath, source, "vue");
|
146
|
+
}
|
147
|
+
async genVueForm(config, fields) {
|
148
|
+
const filePath = join(this.#moduleDir, "form.vue");
|
149
|
+
const source = await xiu.render("form-vue", {
|
150
|
+
name: config.name,
|
151
|
+
comment: config.comment,
|
152
|
+
fields: fields.map((f) => ({
|
153
|
+
...f,
|
154
|
+
isNumber: f.type === "number",
|
155
|
+
isString: f.type === "string"
|
156
|
+
}))
|
157
|
+
});
|
158
|
+
await writeFormatFile(filePath, source, "vue");
|
159
|
+
}
|
160
|
+
async genTsFile(fields, api) {
|
161
|
+
const apiMathods = api.map((a) => a.key);
|
162
|
+
const filePath = join(this.#moduleDir, "fetch-type.ts");
|
163
|
+
const source = await xiu.render("fetch-type", {
|
164
|
+
name: this.#name,
|
165
|
+
filedList: fields,
|
166
|
+
add: apiMathods.includes("add"),
|
167
|
+
delete: apiMathods.includes("delete"),
|
168
|
+
all: apiMathods.includes("all"),
|
169
|
+
update: apiMathods.includes("update")
|
170
|
+
});
|
171
|
+
await writeFormatFile(filePath, source);
|
172
|
+
}
|
173
|
+
}
|
174
|
+
export {
|
175
|
+
RenderVue
|
176
|
+
};
|
package/dist/config.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
declare const CodegenConfig: {
|
2
2
|
webDir: string;
|
3
3
|
apiDir: string;
|
4
|
+
sqliteFile: string;
|
4
5
|
reverse: boolean;
|
5
6
|
};
|
6
7
|
export type ConfigType = Omit<Partial<typeof CodegenConfig>, 'reverse'>;
|
@@ -8,5 +9,6 @@ export declare function setConfig(config: ConfigType): void;
|
|
8
9
|
export declare const setReverse: (reverse: boolean) => boolean;
|
9
10
|
export declare const getWebDir: () => string;
|
10
11
|
export declare const getApiDir: () => string;
|
12
|
+
export declare const getSqliteFile: () => string;
|
11
13
|
export declare const isReverse: () => boolean;
|
12
14
|
export {};
|
package/dist/config.js
CHANGED
@@ -2,6 +2,7 @@ import { resolve } from "path";
|
|
2
2
|
const CodegenConfig = {
|
3
3
|
webDir: resolve(__dirname, ".."),
|
4
4
|
apiDir: resolve(__dirname, ".."),
|
5
|
+
sqliteFile: resolve(__dirname, "..", "admin.db"),
|
5
6
|
reverse: false
|
6
7
|
};
|
7
8
|
function setConfig(config) {
|
@@ -11,13 +12,18 @@ function setConfig(config) {
|
|
11
12
|
if (config.apiDir) {
|
12
13
|
CodegenConfig.apiDir = config.apiDir;
|
13
14
|
}
|
15
|
+
if (config.sqliteFile) {
|
16
|
+
CodegenConfig.sqliteFile = config.sqliteFile;
|
17
|
+
}
|
14
18
|
}
|
15
19
|
const setReverse = (reverse) => CodegenConfig.reverse = reverse;
|
16
20
|
const getWebDir = () => CodegenConfig.webDir;
|
17
21
|
const getApiDir = () => CodegenConfig.apiDir;
|
22
|
+
const getSqliteFile = () => CodegenConfig.sqliteFile;
|
18
23
|
const isReverse = () => CodegenConfig.reverse;
|
19
24
|
export {
|
20
25
|
getApiDir,
|
26
|
+
getSqliteFile,
|
21
27
|
getWebDir,
|
22
28
|
isReverse,
|
23
29
|
setConfig,
|
package/dist/format/api.js
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import { BaseFormat } from "./base";
|
2
2
|
class ApiFormat extends BaseFormat {
|
3
3
|
#hasInterceptor = false;
|
4
|
+
#isNoAuth = false;
|
4
5
|
#moudleName;
|
5
6
|
#upperName;
|
6
7
|
#apiMap = {};
|
@@ -11,7 +12,7 @@ class ApiFormat extends BaseFormat {
|
|
11
12
|
this.#upperName = moduleName[0].toUpperCase() + moduleName.slice(1);
|
12
13
|
}
|
13
14
|
formatOnceStep() {
|
14
|
-
const { key, interceptor } = this.getCurSchema();
|
15
|
+
const { key, interceptor, noAuth } = this.getCurSchema();
|
15
16
|
if (this.#apiMap[key]) {
|
16
17
|
return;
|
17
18
|
}
|
@@ -20,6 +21,10 @@ class ApiFormat extends BaseFormat {
|
|
20
21
|
this.#hasInterceptor = true;
|
21
22
|
this.content += "\n@UseInterceptors(ClassSerializerInterceptor)\n";
|
22
23
|
}
|
24
|
+
if (noAuth) {
|
25
|
+
this.#isNoAuth = true;
|
26
|
+
this.content += "\n@NoAuthToken()\n";
|
27
|
+
}
|
23
28
|
if (key === "get") {
|
24
29
|
this.content += `
|
25
30
|
@Get(':id')
|
@@ -86,6 +91,10 @@ class ApiFormat extends BaseFormat {
|
|
86
91
|
if (this.#apiMap["add"] || this.#apiMap["update"]) {
|
87
92
|
this.#importCommon += "Body,";
|
88
93
|
}
|
94
|
+
if (this.#isNoAuth) {
|
95
|
+
this.importInfo += `import { NoAuthToken } from '@api/common/utils/passport'
|
96
|
+
`;
|
97
|
+
}
|
89
98
|
if (this.#hasInterceptor) {
|
90
99
|
this.#importCommon += "UseInterceptors,ClassSerializerInterceptor,";
|
91
100
|
}
|
package/dist/gen-type.js
CHANGED
@@ -3,14 +3,14 @@ import { writeFormatFile } from "./util";
|
|
3
3
|
import { existsSync, mkdirSync } from "fs";
|
4
4
|
import { readFile, writeFile } from "fs/promises";
|
5
5
|
const genLuaTypes = async (path) => {
|
6
|
-
const types = ["base", "
|
6
|
+
const types = ["api", "base", "dto", "orm"];
|
7
7
|
const vscodePath = join(path, ".vscode");
|
8
8
|
if (!existsSync(vscodePath)) {
|
9
9
|
mkdirSync(vscodePath);
|
10
10
|
}
|
11
11
|
const moveList = types.map((t) => ({
|
12
12
|
writePath: join(vscodePath, `${t}-type.lua`),
|
13
|
-
readPath: resolve(__dirname, `../sources/${t}-type.
|
13
|
+
readPath: resolve(__dirname, `../sources/${t}-type.lua`)
|
14
14
|
}));
|
15
15
|
moveList.forEach((m) => {
|
16
16
|
if (!existsSync(m.writePath)) {
|
@@ -27,7 +27,7 @@ const genLuaTypes = async (path) => {
|
|
27
27
|
settionObj["Lua.workspace.library"] = types.map(
|
28
28
|
(t) => `.vscode/${t}-type.lua`
|
29
29
|
);
|
30
|
-
writeFormatFile(settingPath, JSON.stringify(settionObj),
|
30
|
+
writeFormatFile(settingPath, JSON.stringify(settionObj), "json");
|
31
31
|
}
|
32
32
|
} else {
|
33
33
|
writeFormatFile(
|
@@ -35,7 +35,7 @@ const genLuaTypes = async (path) => {
|
|
35
35
|
JSON.stringify({
|
36
36
|
"Lua.workspace.library": types.map((t) => `.vscode/${t}-type.lua`)
|
37
37
|
}),
|
38
|
-
|
38
|
+
"json"
|
39
39
|
);
|
40
40
|
}
|
41
41
|
};
|
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
-
import { genLuaTypes } from './gen-type';
|
2
1
|
import { ConfigType } from './config';
|
3
|
-
declare const
|
4
|
-
|
5
|
-
|
2
|
+
declare const _default: {
|
3
|
+
startGen: (filePath: string, config?: ConfigType | undefined) => Promise<undefined>;
|
4
|
+
startRemove: (filePath: string, config?: ConfigType | undefined) => Promise<undefined>;
|
5
|
+
genLuaTypes: (path: string) => Promise<void>;
|
6
|
+
};
|
7
|
+
export default _default;
|
package/dist/index.js
CHANGED
@@ -2,29 +2,30 @@ import { compileToByte } from "./compile";
|
|
2
2
|
import { existsSync } from "fs";
|
3
3
|
import { genLuaTypes } from "./gen-type";
|
4
4
|
import { setConfig, setReverse } from "./config";
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
import { runTask } from "./task";
|
6
|
+
function startRun(isDelete) {
|
7
|
+
return async function(filePath, config) {
|
8
|
+
if (config) setConfig(config);
|
9
|
+
setReverse(isDelete);
|
10
|
+
if (existsSync(filePath)) {
|
11
|
+
try {
|
12
|
+
const data = await compileToByte(filePath);
|
13
|
+
const { run } = await import("./lua_codegen");
|
12
14
|
run(new Uint8Array(data), filePath);
|
13
|
-
|
14
|
-
|
15
|
+
await runTask();
|
16
|
+
} catch (error) {
|
17
|
+
return Promise.reject(error);
|
18
|
+
}
|
19
|
+
} else {
|
20
|
+
return Promise.reject(`${filePath}\u6587\u4EF6\u5B58\u5728`);
|
15
21
|
}
|
16
|
-
}
|
17
|
-
return Promise.reject(`${filePath}\u6587\u4EF6\u5B58\u5728`);
|
18
|
-
}
|
22
|
+
};
|
19
23
|
}
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
return startRun(filePath, true, config);
|
24
|
+
var src_default = {
|
25
|
+
startGen: startRun(false),
|
26
|
+
startRemove: startRun(true),
|
27
|
+
genLuaTypes
|
25
28
|
};
|
26
29
|
export {
|
27
|
-
|
28
|
-
startGen,
|
29
|
-
startRemove
|
30
|
+
src_default as default
|
30
31
|
};
|
package/dist/libs/nest-lib.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { ApiServiceField, DtoField, EntityField } from '../types';
|
2
|
-
export declare function renderNestCode(
|
2
|
+
export declare function renderNestCode(config: {
|
3
3
|
name: string;
|
4
4
|
path?: string;
|
5
|
-
}): void;
|
5
|
+
}, entity: EntityField[], dto: DtoField[], apiService: ApiServiceField[]): void;
|
package/dist/libs/nest-lib.js
CHANGED
@@ -1,16 +1,22 @@
|
|
1
|
+
import { setTask } from "../task";
|
1
2
|
import { RenderNest } from "../code/nest";
|
2
3
|
import { isReverse } from "../config";
|
3
|
-
function renderNestCode(entity, dto, apiService
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
4
|
+
function renderNestCode(config, entity, dto, apiService) {
|
5
|
+
setTask(async () => {
|
6
|
+
const api = new RenderNest(config.name, config.path);
|
7
|
+
if (isReverse()) {
|
8
|
+
await Promise.all([api.remove(), api.editAppModule(true)]);
|
9
|
+
} else {
|
10
|
+
await Promise.all([
|
11
|
+
api.editAppModule(),
|
12
|
+
api.genModule(),
|
13
|
+
api.genDto(dto),
|
14
|
+
api.genEntity(entity),
|
15
|
+
api.genApiService(apiService)
|
16
|
+
]);
|
17
|
+
}
|
18
|
+
console.log("lib end>>>");
|
19
|
+
});
|
14
20
|
}
|
15
21
|
export {
|
16
22
|
renderNestCode
|
package/dist/libs.d.ts
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
import { ApiServiceField, DtoField, EntityField, FieldSchema, ModuleConfig, ModuleRoute } from './types';
|
2
|
+
export declare function renderNestCode(config: {
|
3
|
+
name: string;
|
4
|
+
path?: string;
|
5
|
+
}, entity: EntityField[], dto: DtoField[], apiService: ApiServiceField[]): void;
|
6
|
+
type FieldTuple = [string, FieldSchema['type'], string];
|
7
|
+
export declare function renderVueCode(config: ModuleConfig, route: ModuleRoute, fieldList: FieldTuple[], api: ApiServiceField[]): void;
|
8
|
+
export declare function printToNode(info: any): void;
|
9
|
+
export {};
|
package/dist/libs.js
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
import { setTask } from "./task";
|
2
|
+
import { RenderNest } from "./code/nest";
|
3
|
+
import { isReverse } from "./config";
|
4
|
+
import { RenderVue } from "./code/vue";
|
5
|
+
function renderNestCode(config, entity, dto, apiService) {
|
6
|
+
setTask(async () => {
|
7
|
+
const nest = new RenderNest(config.name, config.path);
|
8
|
+
if (isReverse()) {
|
9
|
+
await Promise.all([nest.remove(), nest.editAppModule(true)]);
|
10
|
+
} else {
|
11
|
+
await nest.editAppModule();
|
12
|
+
await Promise.all([
|
13
|
+
nest.genModule(),
|
14
|
+
nest.genDto(dto),
|
15
|
+
nest.genEntity(entity),
|
16
|
+
nest.genApiService(apiService)
|
17
|
+
]);
|
18
|
+
}
|
19
|
+
});
|
20
|
+
}
|
21
|
+
function renderVueCode(config, route, fieldList, api) {
|
22
|
+
setTask(async () => {
|
23
|
+
const fields = fieldList.map(([key, type, comment]) => ({
|
24
|
+
key,
|
25
|
+
type,
|
26
|
+
comment
|
27
|
+
}));
|
28
|
+
const vue = new RenderVue(config.name, config.path);
|
29
|
+
if (isReverse()) {
|
30
|
+
vue.editDir(true);
|
31
|
+
vue.setDatabase(route, true);
|
32
|
+
} else {
|
33
|
+
await vue.editDir();
|
34
|
+
await Promise.all([
|
35
|
+
vue.setDatabase(route),
|
36
|
+
vue.genTsFile(fields, api),
|
37
|
+
vue.genRoute(route),
|
38
|
+
vue.genVueForm(config, fields),
|
39
|
+
vue.genVueTable(config, fields)
|
40
|
+
]);
|
41
|
+
}
|
42
|
+
});
|
43
|
+
}
|
44
|
+
function printToNode(info) {
|
45
|
+
console.log(info);
|
46
|
+
}
|
47
|
+
export {
|
48
|
+
printToNode,
|
49
|
+
renderNestCode,
|
50
|
+
renderVueCode
|
51
|
+
};
|
package/dist/lua_codegen_bg.js
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
import { printToNode } from './libs';
|
2
|
-
import { renderNestCode } from './libs/nest-lib';
|
3
|
-
import { genWebCode } from './libs/vue-lib';
|
1
|
+
import { printToNode, renderNestCode, renderVueCode } from './libs';
|
4
2
|
|
5
3
|
let wasm;
|
6
4
|
export function __wbg_set_wasm(val) {
|
@@ -146,12 +144,12 @@ export function __wbindgen_object_drop_ref(arg0) {
|
|
146
144
|
takeObject(arg0);
|
147
145
|
};
|
148
146
|
|
149
|
-
export function
|
147
|
+
export function __wbg_renderNestCode_786f8dedd18b6a00(arg0, arg1, arg2, arg3) {
|
150
148
|
renderNestCode(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
|
151
149
|
};
|
152
150
|
|
153
|
-
export function
|
154
|
-
|
151
|
+
export function __wbg_renderVueCode_cd8438a75c2a320e(arg0, arg1, arg2, arg3) {
|
152
|
+
renderVueCode(getObject(arg0), getObject(arg1), getObject(arg2), getObject(arg3));
|
155
153
|
};
|
156
154
|
|
157
155
|
export function __wbg_printToNode_f8646f4da26c5023(arg0) {
|
package/dist/lua_codegen_bg.wasm
CHANGED
Binary file
|
package/dist/render.js
CHANGED
@@ -2,10 +2,7 @@ import { XiuTemplate } from "@biuxiu/template";
|
|
2
2
|
import { resolve } from "path";
|
3
3
|
const basePath = resolve(__dirname, "..");
|
4
4
|
const xiu = new XiuTemplate(basePath);
|
5
|
-
xiu.install(() => (
|
6
|
-
name: "up",
|
7
|
-
fn: (val) => val[0].toUpperCase() + val.slice(1)
|
8
|
-
}));
|
5
|
+
xiu.install(["up", (val) => val[0].toUpperCase() + val.slice(1)]);
|
9
6
|
var render_default = xiu;
|
10
7
|
export {
|
11
8
|
render_default as default
|
package/dist/task.d.ts
ADDED
package/dist/task.js
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
const TaskQueue = [];
|
2
|
+
function setTask(fn) {
|
3
|
+
TaskQueue.push(fn);
|
4
|
+
}
|
5
|
+
function runTask() {
|
6
|
+
const currentTask = [];
|
7
|
+
for (let i = 0; i < TaskQueue.length; i++) {
|
8
|
+
const fn = TaskQueue[i];
|
9
|
+
currentTask.push(fn);
|
10
|
+
}
|
11
|
+
return Promise.all(currentTask.map((f) => f()));
|
12
|
+
}
|
13
|
+
export {
|
14
|
+
runTask,
|
15
|
+
setTask
|
16
|
+
};
|
package/dist/types.d.ts
CHANGED
@@ -1,7 +1,18 @@
|
|
1
|
-
type FieldSchema = {
|
1
|
+
export type FieldSchema = {
|
2
2
|
key: string;
|
3
|
+
comment: string;
|
3
4
|
type: 'string' | 'number' | 'bool';
|
4
5
|
};
|
6
|
+
export interface ModuleConfig {
|
7
|
+
name: string;
|
8
|
+
comment: string;
|
9
|
+
path?: string;
|
10
|
+
}
|
11
|
+
export interface ModuleRoute {
|
12
|
+
path: string;
|
13
|
+
icon: string;
|
14
|
+
title: string;
|
15
|
+
}
|
5
16
|
export type DtoField = FieldSchema & {
|
6
17
|
isOptional?: boolean;
|
7
18
|
limit?: {
|
@@ -15,7 +26,6 @@ export type DtoField = FieldSchema & {
|
|
15
26
|
};
|
16
27
|
export type EntityField = FieldSchema & {
|
17
28
|
isExclude?: true;
|
18
|
-
comment?: string;
|
19
29
|
length?: number;
|
20
30
|
nullable?: true;
|
21
31
|
name?: string;
|
@@ -24,5 +34,5 @@ export type EntityField = FieldSchema & {
|
|
24
34
|
export type ApiServiceField = {
|
25
35
|
key: 'get' | 'all' | 'delete' | 'update' | 'add';
|
26
36
|
interceptor?: true;
|
37
|
+
noAuth?: true;
|
27
38
|
};
|
28
|
-
export {};
|
package/dist/util.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
|
2
|
-
export declare const writeFormatFile: (filePath: string, content: string,
|
1
|
+
import { BuiltInParserName, LiteralUnion } from 'prettier';
|
2
|
+
export declare const writeFormatFile: (filePath: string, content: string, parser?: LiteralUnion<BuiltInParserName>) => Promise<undefined>;
|
package/dist/util.js
CHANGED
@@ -1,23 +1,22 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
};
|
7
|
-
const writeFormatFile = async (filePath, content,
|
1
|
+
import { writeFile } from "fs/promises";
|
2
|
+
import {
|
3
|
+
format,
|
4
|
+
resolveConfig,
|
5
|
+
resolveConfigFile
|
6
|
+
} from "prettier";
|
7
|
+
const writeFormatFile = async (filePath, content, parser = "typescript") => {
|
8
8
|
try {
|
9
9
|
const file = await resolveConfigFile(filePath);
|
10
10
|
const config = file ? await resolveConfig(file) : {};
|
11
11
|
const formatText = await format(content, {
|
12
12
|
...config,
|
13
|
-
parser
|
13
|
+
parser
|
14
14
|
});
|
15
15
|
await writeFile(filePath, formatText);
|
16
16
|
} catch (error) {
|
17
|
-
|
17
|
+
return Promise.reject(error);
|
18
18
|
}
|
19
19
|
};
|
20
20
|
export {
|
21
|
-
reFromatFile,
|
22
21
|
writeFormatFile
|
23
22
|
};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@biuxiu/codegen",
|
3
|
-
"version": "0.2.
|
3
|
+
"version": "0.2.14",
|
4
4
|
"description": "代码生成工具",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"scripts": {
|
@@ -19,6 +19,7 @@
|
|
19
19
|
"license": "ISC",
|
20
20
|
"devDependencies": {
|
21
21
|
"@biuxiu/publish": "^1.2.11",
|
22
|
+
"@types/better-sqlite3": "^7.6.11",
|
22
23
|
"@types/node": "^20.14.2",
|
23
24
|
"@types/shelljs": "^0.8.15",
|
24
25
|
"esbuild": "^0.21.5",
|
@@ -28,8 +29,8 @@
|
|
28
29
|
"typescript": "^5.4.5"
|
29
30
|
},
|
30
31
|
"dependencies": {
|
31
|
-
"@biuxiu/template": "^1.2
|
32
|
-
"
|
32
|
+
"@biuxiu/template": "^1.5.2",
|
33
|
+
"better-sqlite3": "^11.1.2",
|
33
34
|
"prettier": "^3.3.2",
|
34
35
|
"ts-morph": "^22.0.0"
|
35
36
|
}
|