@biuxiu/codegen 0.4.0 → 0.4.1
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/nest.d.ts +1 -1
- package/dist/code/nest.js +4 -17
- package/dist/code/vue.d.ts +1 -1
- package/dist/code/vue.js +4 -17
- package/dist/libs.js +3 -2
- package/dist/task.js +5 -4
- package/dist/util.d.ts +1 -0
- package/dist/util.js +18 -0
- package/package.json +1 -1
package/dist/code/nest.d.ts
CHANGED
@@ -2,7 +2,7 @@ import { ApiServiceField, DtoField, EntityField } from '../types';
|
|
2
2
|
export declare class RenderNest {
|
3
3
|
#private;
|
4
4
|
constructor(name: string, path?: string);
|
5
|
-
remove():
|
5
|
+
remove(): void;
|
6
6
|
editAppModule(isDelete?: boolean): Promise<void>;
|
7
7
|
genModule(): Promise<void>;
|
8
8
|
genApiService(apiService: ApiServiceField[]): Promise<void>;
|
package/dist/code/nest.js
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
import xiu from "../render";
|
2
2
|
import { join } from "path";
|
3
|
-
import { writeFormatFile } from "../util";
|
4
|
-
import { existsSync, mkdirSync
|
3
|
+
import { deleteDir, writeFormatFile } from "../util";
|
4
|
+
import { existsSync, mkdirSync } from "fs";
|
5
5
|
import { DTOFromat } from "../format/dto";
|
6
6
|
import { EntityFormat } from "../format/entity";
|
7
7
|
import { ApiFormat } from "../format/api";
|
8
8
|
import { ServiceFormat } from "../format/service";
|
9
9
|
import { getApiDir } from "../config";
|
10
10
|
import { Project, SyntaxKind } from "ts-morph";
|
11
|
-
import { readdir, rmdir, unlink } from "fs/promises";
|
12
11
|
const editFileQueue = [];
|
13
12
|
let isRunning = false;
|
14
13
|
const runEditTask = async () => {
|
@@ -34,21 +33,9 @@ class RenderNest {
|
|
34
33
|
this.#name = name;
|
35
34
|
this.#moduleDir = join(apiDir, this.#path);
|
36
35
|
}
|
37
|
-
|
38
|
-
const files = await readdir(path);
|
39
|
-
for (let i = 0; i < files.length; i++) {
|
40
|
-
const filePath = join(path, files[i]);
|
41
|
-
if (statSync(filePath).isDirectory()) {
|
42
|
-
await this.#deleteDir(filePath);
|
43
|
-
} else {
|
44
|
-
await unlink(filePath);
|
45
|
-
}
|
46
|
-
}
|
47
|
-
await rmdir(path);
|
48
|
-
}
|
49
|
-
async remove() {
|
36
|
+
remove() {
|
50
37
|
if (existsSync(this.#moduleDir)) {
|
51
|
-
|
38
|
+
deleteDir(this.#moduleDir);
|
52
39
|
}
|
53
40
|
}
|
54
41
|
async editAppModule(isDelete = false) {
|
package/dist/code/vue.d.ts
CHANGED
@@ -2,7 +2,7 @@ import { ApiServiceField, FieldSchema, ModuleConfig, ModuleRoute } from '../type
|
|
2
2
|
export declare class RenderVue {
|
3
3
|
#private;
|
4
4
|
constructor(name: string, path?: string);
|
5
|
-
editDir(isDelete?: boolean):
|
5
|
+
editDir(isDelete?: boolean): void;
|
6
6
|
genRoute(route: ModuleRoute): Promise<void>;
|
7
7
|
genVueTable({ name, comment }: ModuleConfig, fields: FieldSchema[]): Promise<void>;
|
8
8
|
genVueForm(config: ModuleConfig, fields: FieldSchema[]): Promise<void>;
|
package/dist/code/vue.js
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
import { getWebDir } from "../config";
|
2
2
|
import xiu from "../render";
|
3
|
-
import { writeFormatFile } from "../util";
|
4
|
-
import { existsSync, mkdirSync
|
5
|
-
import { readdir, rmdir, unlink } from "fs/promises";
|
3
|
+
import { deleteDir, writeFormatFile } from "../util";
|
4
|
+
import { existsSync, mkdirSync } from "fs";
|
6
5
|
import { join } from "path";
|
7
6
|
class RenderVue {
|
8
7
|
#moduleDir;
|
@@ -17,22 +16,10 @@ class RenderVue {
|
|
17
16
|
this.#name = name;
|
18
17
|
this.#moduleDir = join(webDir, this.#path);
|
19
18
|
}
|
20
|
-
|
21
|
-
const files = await readdir(path);
|
22
|
-
for (let i = 0; i < files.length; i++) {
|
23
|
-
const filePath = join(path, files[i]);
|
24
|
-
if (statSync(filePath).isDirectory()) {
|
25
|
-
await this.#deleteDir(filePath);
|
26
|
-
} else {
|
27
|
-
await unlink(filePath);
|
28
|
-
}
|
29
|
-
}
|
30
|
-
await rmdir(path);
|
31
|
-
}
|
32
|
-
async editDir(isDelete = false) {
|
19
|
+
editDir(isDelete = false) {
|
33
20
|
if (isDelete) {
|
34
21
|
if (existsSync(this.#moduleDir)) {
|
35
|
-
|
22
|
+
deleteDir(this.#moduleDir);
|
36
23
|
}
|
37
24
|
} else {
|
38
25
|
let basePath = "";
|
package/dist/libs.js
CHANGED
@@ -6,7 +6,8 @@ function renderNestCode(config, entity, dto, apiService) {
|
|
6
6
|
setTask(async () => {
|
7
7
|
const nest = new RenderNest(config.name, config.path);
|
8
8
|
if (isReverse()) {
|
9
|
-
|
9
|
+
nest.remove();
|
10
|
+
await nest.editAppModule(true);
|
10
11
|
} else {
|
11
12
|
await nest.editAppModule();
|
12
13
|
await Promise.all([
|
@@ -29,7 +30,7 @@ function renderVueCode(config, route, fieldList, api) {
|
|
29
30
|
if (isReverse()) {
|
30
31
|
vue.editDir(true);
|
31
32
|
} else {
|
32
|
-
|
33
|
+
vue.editDir();
|
33
34
|
await Promise.all([
|
34
35
|
vue.genTsFile(fields, api),
|
35
36
|
vue.genRoute(route),
|
package/dist/task.js
CHANGED
@@ -1,13 +1,14 @@
|
|
1
|
-
|
1
|
+
let taskQueue = [];
|
2
2
|
function setTask(fn) {
|
3
|
-
|
3
|
+
taskQueue.push(fn);
|
4
4
|
}
|
5
5
|
function runTask() {
|
6
6
|
const currentTask = [];
|
7
|
-
for (let i = 0; i <
|
8
|
-
const fn =
|
7
|
+
for (let i = 0; i < taskQueue.length; i++) {
|
8
|
+
const fn = taskQueue[i];
|
9
9
|
currentTask.push(fn);
|
10
10
|
}
|
11
|
+
taskQueue = [];
|
11
12
|
return Promise.all(currentTask.map((f) => f()));
|
12
13
|
}
|
13
14
|
export {
|
package/dist/util.d.ts
CHANGED
package/dist/util.js
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
import { readdirSync, rmdirSync, statSync, unlinkSync } from "fs";
|
1
2
|
import { writeFile } from "fs/promises";
|
3
|
+
import { join } from "path";
|
2
4
|
import {
|
3
5
|
format,
|
4
6
|
resolveConfig,
|
@@ -17,6 +19,22 @@ const writeFormatFile = async (filePath, content, parser = "typescript") => {
|
|
17
19
|
return Promise.reject(error);
|
18
20
|
}
|
19
21
|
};
|
22
|
+
function deleteDir(path) {
|
23
|
+
if (!statSync(path).isDirectory()) {
|
24
|
+
return;
|
25
|
+
}
|
26
|
+
const files = readdirSync(path);
|
27
|
+
for (let i = 0; i < files.length; i++) {
|
28
|
+
const filePath = join(path, files[i]);
|
29
|
+
if (statSync(filePath).isDirectory()) {
|
30
|
+
deleteDir(filePath);
|
31
|
+
} else {
|
32
|
+
unlinkSync(filePath);
|
33
|
+
}
|
34
|
+
}
|
35
|
+
rmdirSync(path);
|
36
|
+
}
|
20
37
|
export {
|
38
|
+
deleteDir,
|
21
39
|
writeFormatFile
|
22
40
|
};
|