@biuxiu/codegen 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +11 -0
- package/dist/code/nest.d.ts +11 -0
- package/dist/code/nest.js +229 -0
- package/dist/compile.d.ts +1 -0
- package/dist/compile.js +58 -0
- package/dist/config.d.ts +11 -0
- package/dist/config.js +53 -0
- package/dist/format/api.d.ts +8 -0
- package/dist/format/api.js +122 -0
- package/dist/format/base.d.ts +10 -0
- package/dist/format/base.js +56 -0
- package/dist/format/dto.d.ts +8 -0
- package/dist/format/dto.js +116 -0
- package/dist/format/entity.d.ts +7 -0
- package/dist/format/entity.js +68 -0
- package/dist/format/service.d.ts +8 -0
- package/dist/format/service.js +93 -0
- package/dist/gen-type.d.ts +1 -0
- package/dist/gen-type.js +66 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +48 -0
- package/dist/libs/index.d.ts +1 -0
- package/dist/libs/index.js +30 -0
- package/dist/libs/nest-lib.d.ts +5 -0
- package/dist/libs/nest-lib.js +41 -0
- package/dist/libs/vue-lib.d.ts +1 -0
- package/dist/libs/vue-lib.js +30 -0
- package/dist/render.d.ts +3 -0
- package/dist/render.js +32 -0
- package/dist/types.d.ts +28 -0
- package/dist/types.js +16 -0
- package/dist/util.d.ts +2 -0
- package/dist/util.js +48 -0
- package/package.json +39 -0
- package/pkg/README.md +11 -0
- package/sources/base-type.txt +6 -0
- package/sources/controller.btpl +8 -0
- package/sources/create-dto.btpl +4 -0
- package/sources/entity.btpl +8 -0
- package/sources/module.btpl +13 -0
- package/sources/nest-type.txt +88 -0
- package/sources/service.btpl +11 -0
- package/sources/update-dto.btpl +4 -0
- package/sources/vue-type.txt +27 -0
package/README.md
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
import { ApiServiceField, DtoField, EntityField } from '@/types';
|
2
|
+
export declare class RenderNest {
|
3
|
+
#private;
|
4
|
+
constructor(name: string, path?: string);
|
5
|
+
remove(): void;
|
6
|
+
editAppModule(isDelete?: boolean): void;
|
7
|
+
genModule(): Promise<void>;
|
8
|
+
genApiService(apiService: ApiServiceField[]): Promise<void>;
|
9
|
+
genEntity(entity: EntityField[]): Promise<void>;
|
10
|
+
genDto(dto: DtoField[]): Promise<void>;
|
11
|
+
}
|
@@ -0,0 +1,229 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __create = Object.create;
|
3
|
+
var __defProp = Object.defineProperty;
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
8
|
+
var __export = (target, all) => {
|
9
|
+
for (var name in all)
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
11
|
+
};
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
14
|
+
for (let key of __getOwnPropNames(from))
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
17
|
+
}
|
18
|
+
return to;
|
19
|
+
};
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
26
|
+
mod
|
27
|
+
));
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
29
|
+
var nest_exports = {};
|
30
|
+
__export(nest_exports, {
|
31
|
+
RenderNest: () => RenderNest
|
32
|
+
});
|
33
|
+
module.exports = __toCommonJS(nest_exports);
|
34
|
+
var import_render = __toESM(require("@/render"));
|
35
|
+
var import_path = require("path");
|
36
|
+
var import_util = require("@/util");
|
37
|
+
var import_fs = require("fs");
|
38
|
+
var import_dto = require("@/format/dto");
|
39
|
+
var import_entity = require("@/format/entity");
|
40
|
+
var import_api = require("@/format/api");
|
41
|
+
var import_service = require("@/format/service");
|
42
|
+
var import_config = require("@/config");
|
43
|
+
var import_ts_morph = require("ts-morph");
|
44
|
+
var import_shelljs = require("shelljs");
|
45
|
+
const editFileQueue = [];
|
46
|
+
let isRunning = false;
|
47
|
+
const runEditTask = async () => {
|
48
|
+
if (!isRunning) {
|
49
|
+
isRunning = true;
|
50
|
+
while (editFileQueue.length > 0) {
|
51
|
+
const fn = editFileQueue.shift();
|
52
|
+
if (fn) await fn();
|
53
|
+
}
|
54
|
+
isRunning = false;
|
55
|
+
}
|
56
|
+
};
|
57
|
+
class RenderNest {
|
58
|
+
#moduleDir;
|
59
|
+
#name;
|
60
|
+
#path;
|
61
|
+
#formatPath(path) {
|
62
|
+
return path.split("/").filter((p) => p).join("/");
|
63
|
+
}
|
64
|
+
constructor(name, path) {
|
65
|
+
this.#path = path ? path.endsWith("/") ? `${this.#formatPath(path)}/${name}` : this.#formatPath(path) : name;
|
66
|
+
let basePath = "";
|
67
|
+
const apiDir = (0, import_config.getApiDir)();
|
68
|
+
if (this.#path.includes("/")) {
|
69
|
+
const pathArr = this.#path.split("/");
|
70
|
+
for (let i = 0; i < pathArr.length; i++) {
|
71
|
+
const curPath = pathArr[i];
|
72
|
+
if (i === 0) {
|
73
|
+
basePath = (0, import_path.join)(apiDir, curPath);
|
74
|
+
} else {
|
75
|
+
basePath = (0, import_path.join)(basePath, curPath);
|
76
|
+
}
|
77
|
+
if (!(0, import_fs.existsSync)(basePath)) {
|
78
|
+
(0, import_fs.mkdirSync)(basePath);
|
79
|
+
}
|
80
|
+
}
|
81
|
+
} else {
|
82
|
+
basePath = (0, import_path.join)(apiDir, this.#path);
|
83
|
+
if (!(0, import_fs.existsSync)(basePath)) {
|
84
|
+
(0, import_fs.mkdirSync)(basePath);
|
85
|
+
}
|
86
|
+
}
|
87
|
+
this.#name = name;
|
88
|
+
this.#moduleDir = basePath;
|
89
|
+
}
|
90
|
+
remove() {
|
91
|
+
if ((0, import_fs.existsSync)(this.#moduleDir)) {
|
92
|
+
(0, import_shelljs.exec)(`rm -rf ${this.#moduleDir}`);
|
93
|
+
}
|
94
|
+
this.editAppModule(true);
|
95
|
+
}
|
96
|
+
editAppModule(isDelete = false) {
|
97
|
+
editFileQueue.push(async () => {
|
98
|
+
const moudleName = `${this.#name[0].toUpperCase() + this.#name.slice(1)}Module`;
|
99
|
+
const appModuleFile = (0, import_path.join)((0, import_config.getApiDir)(), "app.module.ts");
|
100
|
+
if ((0, import_fs.existsSync)(appModuleFile)) {
|
101
|
+
const source = new import_ts_morph.Project().addSourceFileAtPath(appModuleFile);
|
102
|
+
const moduleImport = source.getImportDeclaration(
|
103
|
+
`./${this.#path}/${this.#name}.module`
|
104
|
+
);
|
105
|
+
const appModuleClass = source.getClassOrThrow("AppModule");
|
106
|
+
const importsArray = appModuleClass.getDecoratorOrThrow("Module").getArguments()[0].asKindOrThrow(import_ts_morph.SyntaxKind.ObjectLiteralExpression).getPropertyOrThrow("imports").getFirstChildByKindOrThrow(
|
107
|
+
import_ts_morph.SyntaxKind.ArrayLiteralExpression
|
108
|
+
);
|
109
|
+
const consumerStatement = appModuleClass.getMethodOrThrow("configure").getStatements()[0];
|
110
|
+
if (isDelete) {
|
111
|
+
if (moduleImport) {
|
112
|
+
moduleImport.remove();
|
113
|
+
}
|
114
|
+
importsArray.getElements().forEach((ele, index) => {
|
115
|
+
if (ele.getText() === moudleName) {
|
116
|
+
importsArray.removeElement(index);
|
117
|
+
}
|
118
|
+
});
|
119
|
+
const text = consumerStatement.getText();
|
120
|
+
if (text.includes(moudleName)) {
|
121
|
+
const newText = text.replace(
|
122
|
+
new RegExp(`,\\s*${moudleName}`),
|
123
|
+
""
|
124
|
+
);
|
125
|
+
consumerStatement.replaceWithText(newText);
|
126
|
+
}
|
127
|
+
} else {
|
128
|
+
if (!moduleImport) {
|
129
|
+
source.addImportDeclaration({
|
130
|
+
namedImports: [moudleName],
|
131
|
+
moduleSpecifier: `./${this.#path}/${this.#name}.module`
|
132
|
+
});
|
133
|
+
}
|
134
|
+
let hasModule = false;
|
135
|
+
importsArray.getElements().forEach((ele) => {
|
136
|
+
if (ele.getText() === moudleName) {
|
137
|
+
hasModule = true;
|
138
|
+
}
|
139
|
+
});
|
140
|
+
if (!hasModule) {
|
141
|
+
importsArray.addElement(moudleName);
|
142
|
+
}
|
143
|
+
const text = consumerStatement.getText();
|
144
|
+
if (!text.includes(moudleName)) {
|
145
|
+
const newText = text.replace(
|
146
|
+
/\.forRoutes\(([^)]+)\)/,
|
147
|
+
`.forRoutes($1, ${moudleName})`
|
148
|
+
);
|
149
|
+
consumerStatement.replaceWithText(newText);
|
150
|
+
}
|
151
|
+
}
|
152
|
+
await source.save();
|
153
|
+
await (0, import_util.reFromatFile)(appModuleFile);
|
154
|
+
}
|
155
|
+
});
|
156
|
+
runEditTask();
|
157
|
+
}
|
158
|
+
async genModule() {
|
159
|
+
const modulePath = (0, import_path.join)(this.#moduleDir, `${this.#name}.module.ts`);
|
160
|
+
const moduleStr = await import_render.default.render("module", { name: this.#name });
|
161
|
+
(0, import_util.writeFormatFile)(modulePath, moduleStr);
|
162
|
+
}
|
163
|
+
async genApiService(apiService) {
|
164
|
+
const controllerPath = (0, import_path.join)(
|
165
|
+
this.#moduleDir,
|
166
|
+
`${this.#name}.controller.ts`
|
167
|
+
);
|
168
|
+
const servicePath = (0, import_path.join)(this.#moduleDir, `${this.#name}.service.ts`);
|
169
|
+
const [apiImport, apiContent] = new import_api.ApiFormat(
|
170
|
+
this.#name,
|
171
|
+
apiService
|
172
|
+
).format();
|
173
|
+
import_render.default.render("controller", {
|
174
|
+
name: this.#name,
|
175
|
+
importInfo: apiImport,
|
176
|
+
content: apiContent
|
177
|
+
}).then((controllerStr) => {
|
178
|
+
(0, import_util.writeFormatFile)(controllerPath, controllerStr);
|
179
|
+
});
|
180
|
+
const [serviceImport, serviceContent] = new import_service.ServiceFormat(
|
181
|
+
this.#name,
|
182
|
+
apiService
|
183
|
+
).format();
|
184
|
+
import_render.default.render("service", {
|
185
|
+
name: this.#name,
|
186
|
+
content: serviceContent,
|
187
|
+
importInfo: serviceImport
|
188
|
+
}).then((serviceStr) => {
|
189
|
+
(0, import_util.writeFormatFile)(servicePath, serviceStr);
|
190
|
+
});
|
191
|
+
}
|
192
|
+
async genEntity(entity) {
|
193
|
+
const entityDir = (0, import_path.join)(this.#moduleDir, "entities");
|
194
|
+
if (!(0, import_fs.existsSync)(entityDir)) {
|
195
|
+
(0, import_fs.mkdirSync)(entityDir);
|
196
|
+
}
|
197
|
+
const entityPath = (0, import_path.join)(entityDir, `${this.#name}.entity.ts`);
|
198
|
+
const [importInfo, content] = new import_entity.EntityFormat(entity).format();
|
199
|
+
const entityStr = await import_render.default.render("entity", {
|
200
|
+
name: this.#name,
|
201
|
+
importInfo,
|
202
|
+
content
|
203
|
+
});
|
204
|
+
(0, import_util.writeFormatFile)(entityPath, entityStr);
|
205
|
+
}
|
206
|
+
async genDto(dto) {
|
207
|
+
const dtoPath = (0, import_path.join)(this.#moduleDir, "dto");
|
208
|
+
if (!(0, import_fs.existsSync)(dtoPath)) {
|
209
|
+
(0, import_fs.mkdirSync)(dtoPath);
|
210
|
+
}
|
211
|
+
const createDtoPath = (0, import_path.join)(dtoPath, `create-${this.#name}.dto.ts`);
|
212
|
+
const updateDtoPath = (0, import_path.join)(dtoPath, `update-${this.#name}.dto.ts`);
|
213
|
+
const [importInfo, content] = new import_dto.DTOFromat(dto).format();
|
214
|
+
const createDtoStr = await import_render.default.render("create-dto", {
|
215
|
+
importInfo,
|
216
|
+
name: this.#name,
|
217
|
+
content
|
218
|
+
});
|
219
|
+
const updateDtoStr = await import_render.default.render("update-dto", {
|
220
|
+
name: this.#name
|
221
|
+
});
|
222
|
+
(0, import_util.writeFormatFile)(createDtoPath, createDtoStr);
|
223
|
+
(0, import_util.writeFormatFile)(updateDtoPath, updateDtoStr);
|
224
|
+
}
|
225
|
+
}
|
226
|
+
// Annotate the CommonJS export names for ESM import in node:
|
227
|
+
0 && (module.exports = {
|
228
|
+
RenderNest
|
229
|
+
});
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function compileToByte(filePath: string): Promise<ArrayBuffer>;
|
package/dist/compile.js
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
var compile_exports = {};
|
20
|
+
__export(compile_exports, {
|
21
|
+
compileToByte: () => compileToByte
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(compile_exports);
|
24
|
+
var import_shelljs = require("shelljs");
|
25
|
+
var import_path = require("path");
|
26
|
+
var import_os = require("os");
|
27
|
+
const getPathName = () => {
|
28
|
+
switch ((0, import_os.platform)()) {
|
29
|
+
case "win32":
|
30
|
+
return "win/luac.exe";
|
31
|
+
case "linux":
|
32
|
+
return "linux/luac";
|
33
|
+
case "darwin":
|
34
|
+
return "mac/luac";
|
35
|
+
default:
|
36
|
+
throw Error("\u4E0D\u652F\u6301\u7684\u64CD\u4F5C\u7CFB\u7EDF");
|
37
|
+
}
|
38
|
+
};
|
39
|
+
function compileToByte(filePath) {
|
40
|
+
const bin = (0, import_path.resolve)(__dirname, "../lua/bin", getPathName());
|
41
|
+
return new Promise((resolve2, reject) => {
|
42
|
+
(0, import_shelljs.exec)(
|
43
|
+
`${bin} -s -o - ${filePath}`,
|
44
|
+
{ silent: true, encoding: "buffer" },
|
45
|
+
(code, out, err) => {
|
46
|
+
if (code === 0) {
|
47
|
+
resolve2(out);
|
48
|
+
} else {
|
49
|
+
reject(err.toString());
|
50
|
+
}
|
51
|
+
}
|
52
|
+
);
|
53
|
+
});
|
54
|
+
}
|
55
|
+
// Annotate the CommonJS export names for ESM import in node:
|
56
|
+
0 && (module.exports = {
|
57
|
+
compileToByte
|
58
|
+
});
|
package/dist/config.d.ts
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
declare const CodegenConfig: {
|
2
|
+
webDir: string;
|
3
|
+
apiDir: string;
|
4
|
+
reverse: boolean;
|
5
|
+
};
|
6
|
+
export type ConfigType = Partial<typeof CodegenConfig>;
|
7
|
+
export declare function setConfig(config: ConfigType): void;
|
8
|
+
export declare const getWebDir: () => string;
|
9
|
+
export declare const getApiDir: () => string;
|
10
|
+
export declare const isReverse: () => boolean;
|
11
|
+
export {};
|
package/dist/config.js
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
var config_exports = {};
|
20
|
+
__export(config_exports, {
|
21
|
+
getApiDir: () => getApiDir,
|
22
|
+
getWebDir: () => getWebDir,
|
23
|
+
isReverse: () => isReverse,
|
24
|
+
setConfig: () => setConfig
|
25
|
+
});
|
26
|
+
module.exports = __toCommonJS(config_exports);
|
27
|
+
var import_path = require("path");
|
28
|
+
const CodegenConfig = {
|
29
|
+
webDir: (0, import_path.resolve)(__dirname, ".."),
|
30
|
+
apiDir: (0, import_path.resolve)(__dirname, ".."),
|
31
|
+
reverse: false
|
32
|
+
};
|
33
|
+
function setConfig(config) {
|
34
|
+
if (config.webDir) {
|
35
|
+
CodegenConfig.webDir = config.webDir;
|
36
|
+
}
|
37
|
+
if (config.apiDir) {
|
38
|
+
CodegenConfig.apiDir = config.apiDir;
|
39
|
+
}
|
40
|
+
if (config.reverse !== void 0) {
|
41
|
+
CodegenConfig.reverse = config.reverse;
|
42
|
+
}
|
43
|
+
}
|
44
|
+
const getWebDir = () => CodegenConfig.webDir;
|
45
|
+
const getApiDir = () => CodegenConfig.apiDir;
|
46
|
+
const isReverse = () => CodegenConfig.reverse;
|
47
|
+
// Annotate the CommonJS export names for ESM import in node:
|
48
|
+
0 && (module.exports = {
|
49
|
+
getApiDir,
|
50
|
+
getWebDir,
|
51
|
+
isReverse,
|
52
|
+
setConfig
|
53
|
+
});
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { ApiServiceField } from '@/types';
|
2
|
+
import { BaseFormat } from './base';
|
3
|
+
export declare class ApiFormat extends BaseFormat<ApiServiceField> {
|
4
|
+
#private;
|
5
|
+
constructor(moduleName: string, apiService: ApiServiceField[]);
|
6
|
+
protected formatOnceStep(): void;
|
7
|
+
protected formatEnd(): void;
|
8
|
+
}
|
@@ -0,0 +1,122 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
var api_exports = {};
|
20
|
+
__export(api_exports, {
|
21
|
+
ApiFormat: () => ApiFormat
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(api_exports);
|
24
|
+
var import_base = require("./base");
|
25
|
+
class ApiFormat extends import_base.BaseFormat {
|
26
|
+
#hasInterceptor = false;
|
27
|
+
#moudleName;
|
28
|
+
#upperName;
|
29
|
+
#apiMap = {};
|
30
|
+
#importCommon = "Controller,";
|
31
|
+
constructor(moduleName, apiService) {
|
32
|
+
super(apiService);
|
33
|
+
this.#moudleName = moduleName;
|
34
|
+
this.#upperName = moduleName[0].toUpperCase() + moduleName.slice(1);
|
35
|
+
}
|
36
|
+
formatOnceStep() {
|
37
|
+
const { key, interceptor } = this.getCurSchema();
|
38
|
+
if (this.#apiMap[key]) {
|
39
|
+
return;
|
40
|
+
}
|
41
|
+
this.#apiMap[key] = true;
|
42
|
+
if (interceptor) {
|
43
|
+
this.#hasInterceptor = true;
|
44
|
+
this.content += "\n@UseInterceptors(ClassSerializerInterceptor)\n";
|
45
|
+
}
|
46
|
+
if (key === "get") {
|
47
|
+
this.content += `
|
48
|
+
@Get(':id')
|
49
|
+
findOne(@Param('id') id: string) {
|
50
|
+
return this.${this.#moudleName}Service.query(+id)
|
51
|
+
}
|
52
|
+
`;
|
53
|
+
} else if (key === "all") {
|
54
|
+
this.content += `
|
55
|
+
@Get()
|
56
|
+
findAll(@Query() pageDto: PageDto) {
|
57
|
+
const { skip, take } = PageDto.setSkipTake(pageDto)
|
58
|
+
return this.${this.#moudleName}Service.table(skip, take, pageDto.search)
|
59
|
+
}
|
60
|
+
`;
|
61
|
+
} else if (key === "delete") {
|
62
|
+
this.content += `
|
63
|
+
@Delete(':id')
|
64
|
+
remove(@Param('id') id: string) {
|
65
|
+
return this.${this.#moudleName}Service.delete(+id)
|
66
|
+
}
|
67
|
+
`;
|
68
|
+
} else if (key === "update") {
|
69
|
+
this.content += `
|
70
|
+
@Patch(':id')
|
71
|
+
update(@Param('id') id: string, @Body() update${this.#upperName}Dto: Update${this.#upperName}Dto) {
|
72
|
+
return this.${this.#moudleName}Service.update(+id, update${this.#upperName}Dto)
|
73
|
+
}
|
74
|
+
`;
|
75
|
+
} else if (key === "add") {
|
76
|
+
this.content += `
|
77
|
+
@Post()
|
78
|
+
create(@Body() create${this.#upperName}Dto: Create${this.#upperName}Dto) {
|
79
|
+
return this.${this.#moudleName}Service.create(create${this.#upperName}Dto)
|
80
|
+
}
|
81
|
+
`;
|
82
|
+
}
|
83
|
+
}
|
84
|
+
formatEnd() {
|
85
|
+
if (this.#apiMap["get"]) {
|
86
|
+
this.#importCommon += "Get,";
|
87
|
+
}
|
88
|
+
if (this.#apiMap["delete"]) {
|
89
|
+
this.#importCommon += "Delete,";
|
90
|
+
}
|
91
|
+
if (this.#apiMap["all"]) {
|
92
|
+
this.#importCommon += "Query,";
|
93
|
+
this.importInfo += `import { PageDto } from '@api/common/dto/page.dto'
|
94
|
+
`;
|
95
|
+
}
|
96
|
+
if (this.#apiMap["add"]) {
|
97
|
+
this.#importCommon += "Post,";
|
98
|
+
this.importInfo += `import { Create${this.#upperName}Dto } from './dto/create-${this.#moudleName}.dto'
|
99
|
+
`;
|
100
|
+
}
|
101
|
+
if (this.#apiMap["update"]) {
|
102
|
+
this.#importCommon += "Patch,";
|
103
|
+
this.importInfo += `import { Update${this.#upperName}Dto } from './dto/update-${this.#moudleName}.dto'
|
104
|
+
`;
|
105
|
+
}
|
106
|
+
if (this.#apiMap["get"] || this.#apiMap["delete"] || this.#apiMap["update"]) {
|
107
|
+
this.#importCommon += "Param,";
|
108
|
+
}
|
109
|
+
if (this.#apiMap["add"] || this.#apiMap["update"]) {
|
110
|
+
this.#importCommon += "Body,";
|
111
|
+
}
|
112
|
+
if (this.#hasInterceptor) {
|
113
|
+
this.#importCommon += "UseInterceptors,ClassSerializerInterceptor,";
|
114
|
+
}
|
115
|
+
this.importInfo += `import { ${this.#importCommon.slice(0, this.#importCommon.length - 1)} } from '@nestjs/common'
|
116
|
+
`;
|
117
|
+
}
|
118
|
+
}
|
119
|
+
// Annotate the CommonJS export names for ESM import in node:
|
120
|
+
0 && (module.exports = {
|
121
|
+
ApiFormat
|
122
|
+
});
|
@@ -0,0 +1,10 @@
|
|
1
|
+
export declare abstract class BaseFormat<T> {
|
2
|
+
#private;
|
3
|
+
protected importInfo: string;
|
4
|
+
protected content: string;
|
5
|
+
constructor(schemas: T[]);
|
6
|
+
protected getCurSchema(): T;
|
7
|
+
protected formatOnceStep(): void;
|
8
|
+
protected formatEnd(): void;
|
9
|
+
format(): string[];
|
10
|
+
}
|
@@ -0,0 +1,56 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __defProp = Object.defineProperty;
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
+
var __export = (target, all) => {
|
7
|
+
for (var name in all)
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
+
};
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
+
for (let key of __getOwnPropNames(from))
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
+
}
|
16
|
+
return to;
|
17
|
+
};
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
+
var base_exports = {};
|
20
|
+
__export(base_exports, {
|
21
|
+
BaseFormat: () => BaseFormat
|
22
|
+
});
|
23
|
+
module.exports = __toCommonJS(base_exports);
|
24
|
+
class BaseFormat {
|
25
|
+
importInfo;
|
26
|
+
content;
|
27
|
+
#schemas;
|
28
|
+
#index = 0;
|
29
|
+
constructor(schemas) {
|
30
|
+
this.#schemas = schemas;
|
31
|
+
this.content = "";
|
32
|
+
this.importInfo = "";
|
33
|
+
}
|
34
|
+
#hasNext() {
|
35
|
+
return this.#schemas.length > this.#index;
|
36
|
+
}
|
37
|
+
getCurSchema() {
|
38
|
+
return this.#schemas[this.#index];
|
39
|
+
}
|
40
|
+
formatOnceStep() {
|
41
|
+
}
|
42
|
+
formatEnd() {
|
43
|
+
}
|
44
|
+
format() {
|
45
|
+
while (this.#hasNext()) {
|
46
|
+
this.formatOnceStep();
|
47
|
+
this.#index++;
|
48
|
+
}
|
49
|
+
this.formatEnd();
|
50
|
+
return [this.importInfo, this.content];
|
51
|
+
}
|
52
|
+
}
|
53
|
+
// Annotate the CommonJS export names for ESM import in node:
|
54
|
+
0 && (module.exports = {
|
55
|
+
BaseFormat
|
56
|
+
});
|