@biuxiu/codegen 0.3.2 → 0.4.0
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/dist/code/vue.d.ts +0 -1
- package/dist/code/vue.js +1 -73
- package/dist/config.d.ts +0 -2
- package/dist/config.js +0 -6
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -1
- package/dist/libs.js +1 -2
- package/dist/task.d.ts +3 -2
- package/package.json +1 -5
package/dist/code/vue.d.ts
CHANGED
@@ -3,7 +3,6 @@ export declare class RenderVue {
|
|
3
3
|
#private;
|
4
4
|
constructor(name: string, path?: string);
|
5
5
|
editDir(isDelete?: boolean): Promise<void>;
|
6
|
-
setDatabase(route: ModuleRoute, isDelete?: boolean): Promise<undefined>;
|
7
6
|
genRoute(route: ModuleRoute): Promise<void>;
|
8
7
|
genVueTable({ name, comment }: ModuleConfig, fields: FieldSchema[]): Promise<void>;
|
9
8
|
genVueForm(config: ModuleConfig, fields: FieldSchema[]): Promise<void>;
|
package/dist/code/vue.js
CHANGED
@@ -1,10 +1,9 @@
|
|
1
|
-
import {
|
1
|
+
import { getWebDir } from "../config";
|
2
2
|
import xiu from "../render";
|
3
3
|
import { writeFormatFile } from "../util";
|
4
4
|
import { existsSync, mkdirSync, statSync } from "fs";
|
5
5
|
import { readdir, rmdir, unlink } from "fs/promises";
|
6
6
|
import { join } from "path";
|
7
|
-
import Database from "better-sqlite3";
|
8
7
|
class RenderVue {
|
9
8
|
#moduleDir;
|
10
9
|
#name;
|
@@ -59,77 +58,6 @@ class RenderVue {
|
|
59
58
|
}
|
60
59
|
}
|
61
60
|
}
|
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
61
|
async genRoute(route) {
|
134
62
|
const filePath = join(this.#moduleDir, "meta.json");
|
135
63
|
const source = await xiu.render("route-mata", route);
|
package/dist/config.d.ts
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
declare const CodegenConfig: {
|
2
2
|
webDir: string;
|
3
3
|
apiDir: string;
|
4
|
-
sqliteFile: string;
|
5
4
|
reverse: boolean;
|
6
5
|
};
|
7
6
|
export type ConfigType = Omit<Partial<typeof CodegenConfig>, 'reverse'>;
|
@@ -9,6 +8,5 @@ export declare function setConfig(config: ConfigType): void;
|
|
9
8
|
export declare const setReverse: (reverse: boolean) => boolean;
|
10
9
|
export declare const getWebDir: () => string;
|
11
10
|
export declare const getApiDir: () => string;
|
12
|
-
export declare const getSqliteFile: () => string;
|
13
11
|
export declare const isReverse: () => boolean;
|
14
12
|
export {};
|
package/dist/config.js
CHANGED
@@ -2,7 +2,6 @@ import { resolve } from "path";
|
|
2
2
|
const CodegenConfig = {
|
3
3
|
webDir: resolve(__dirname, ".."),
|
4
4
|
apiDir: resolve(__dirname, ".."),
|
5
|
-
sqliteFile: resolve(__dirname, "..", "admin.db"),
|
6
5
|
reverse: false
|
7
6
|
};
|
8
7
|
function setConfig(config) {
|
@@ -12,18 +11,13 @@ function setConfig(config) {
|
|
12
11
|
if (config.apiDir) {
|
13
12
|
CodegenConfig.apiDir = config.apiDir;
|
14
13
|
}
|
15
|
-
if (config.sqliteFile) {
|
16
|
-
CodegenConfig.sqliteFile = config.sqliteFile;
|
17
|
-
}
|
18
14
|
}
|
19
15
|
const setReverse = (reverse) => CodegenConfig.reverse = reverse;
|
20
16
|
const getWebDir = () => CodegenConfig.webDir;
|
21
17
|
const getApiDir = () => CodegenConfig.apiDir;
|
22
|
-
const getSqliteFile = () => CodegenConfig.sqliteFile;
|
23
18
|
const isReverse = () => CodegenConfig.reverse;
|
24
19
|
export {
|
25
20
|
getApiDir,
|
26
|
-
getSqliteFile,
|
27
21
|
getWebDir,
|
28
22
|
isReverse,
|
29
23
|
setConfig,
|
package/dist/index.d.ts
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
import { ConfigType } from './config';
|
2
|
+
import { ModuleRoute } from './types';
|
2
3
|
declare const _default: {
|
3
|
-
startGen: (filePath: string, config?: ConfigType | undefined) => Promise<
|
4
|
-
startRemove: (filePath: string, config?: ConfigType | undefined) => Promise<
|
4
|
+
startGen: (filePath: string, config?: ConfigType | undefined) => Promise<ModuleRoute[]>;
|
5
|
+
startRemove: (filePath: string, config?: ConfigType | undefined) => Promise<ModuleRoute[]>;
|
5
6
|
genLuaTypes: (path: string) => Promise<void>;
|
6
7
|
};
|
7
8
|
export default _default;
|
package/dist/index.js
CHANGED
@@ -12,7 +12,7 @@ function startRun(isDelete) {
|
|
12
12
|
const data = await compileToByte(filePath);
|
13
13
|
const { run } = await import("./lua_codegen");
|
14
14
|
run(new Uint8Array(data), filePath);
|
15
|
-
await runTask();
|
15
|
+
return (await runTask()).filter((c) => !!c);
|
16
16
|
} catch (error) {
|
17
17
|
return Promise.reject(error);
|
18
18
|
}
|
package/dist/libs.js
CHANGED
@@ -28,17 +28,16 @@ function renderVueCode(config, route, fieldList, api) {
|
|
28
28
|
const vue = new RenderVue(config.name, config.path);
|
29
29
|
if (isReverse()) {
|
30
30
|
vue.editDir(true);
|
31
|
-
vue.setDatabase(route, true);
|
32
31
|
} else {
|
33
32
|
await vue.editDir();
|
34
33
|
await Promise.all([
|
35
|
-
vue.setDatabase(route),
|
36
34
|
vue.genTsFile(fields, api),
|
37
35
|
vue.genRoute(route),
|
38
36
|
vue.genVueForm(config, fields),
|
39
37
|
vue.genVueTable(config, fields)
|
40
38
|
]);
|
41
39
|
}
|
40
|
+
return route;
|
42
41
|
});
|
43
42
|
}
|
44
43
|
function printToNode(info) {
|
package/dist/task.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
|
+
import { ModuleRoute } from './types';
|
1
2
|
type TaskFn = {
|
2
|
-
(): Promise<void>;
|
3
|
+
(): Promise<void | ModuleRoute>;
|
3
4
|
};
|
4
5
|
export declare function setTask(fn: TaskFn): void;
|
5
|
-
export declare function runTask(): Promise<void[]>;
|
6
|
+
export declare function runTask(): Promise<(void | ModuleRoute)[]>;
|
6
7
|
export {};
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@biuxiu/codegen",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.4.0",
|
4
4
|
"description": "代码生成工具",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"scripts": {
|
@@ -19,7 +19,6 @@
|
|
19
19
|
"license": "ISC",
|
20
20
|
"devDependencies": {
|
21
21
|
"@biuxiu/publish": "^1.2.11",
|
22
|
-
"@types/better-sqlite3": "^7.6.11",
|
23
22
|
"@types/node": "^20.14.2",
|
24
23
|
"@types/shelljs": "^0.8.15",
|
25
24
|
"esbuild": "^0.21.5",
|
@@ -28,9 +27,6 @@
|
|
28
27
|
"tsx": "^4.15.1",
|
29
28
|
"typescript": "^5.4.5"
|
30
29
|
},
|
31
|
-
"peerDependencies": {
|
32
|
-
"better-sqlite3": "^11.1.2"
|
33
|
-
},
|
34
30
|
"dependencies": {
|
35
31
|
"@biuxiu/template": "^1.5.2",
|
36
32
|
"prettier": "^3.3.2",
|