@bogomolcompany/bogo 0.1.1 → 0.2.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/LICENSE +21 -0
- package/README.md +178 -35
- package/README.ru.md +266 -0
- package/dist/cli.js +148 -15
- package/dist/cli.js.map +1 -1
- package/dist/commands/add-method.d.ts +3 -0
- package/dist/commands/add-method.d.ts.map +1 -0
- package/dist/commands/add-method.js +47 -0
- package/dist/commands/add-method.js.map +1 -0
- package/dist/commands/create-app.d.ts +2 -1
- package/dist/commands/create-app.d.ts.map +1 -1
- package/dist/commands/create-app.js +2 -2
- package/dist/commands/create-app.js.map +1 -1
- package/dist/commands/doctor.d.ts +2 -0
- package/dist/commands/doctor.d.ts.map +1 -0
- package/dist/commands/doctor.js +53 -0
- package/dist/commands/doctor.js.map +1 -0
- package/dist/commands/generate-module.d.ts +2 -1
- package/dist/commands/generate-module.d.ts.map +1 -1
- package/dist/commands/generate-module.js +41 -26
- package/dist/commands/generate-module.js.map +1 -1
- package/dist/commands/interactive.d.ts +3 -0
- package/dist/commands/interactive.d.ts.map +1 -0
- package/dist/commands/interactive.js +65 -0
- package/dist/commands/interactive.js.map +1 -0
- package/dist/commands/list-modules.d.ts +2 -0
- package/dist/commands/list-modules.d.ts.map +1 -0
- package/dist/commands/list-modules.js +36 -0
- package/dist/commands/list-modules.js.map +1 -0
- package/dist/commands/remove-module.d.ts +5 -0
- package/dist/commands/remove-module.d.ts.map +1 -0
- package/dist/commands/remove-module.js +99 -0
- package/dist/commands/remove-module.js.map +1 -0
- package/dist/templates/module.d.ts +15 -7
- package/dist/templates/module.d.ts.map +1 -1
- package/dist/templates/module.js +51 -74
- package/dist/templates/module.js.map +1 -1
- package/dist/templates/project.d.ts +2 -1
- package/dist/templates/project.d.ts.map +1 -1
- package/dist/templates/project.js +85 -17
- package/dist/templates/project.js.map +1 -1
- package/dist/templates/render-helpers.d.ts +9 -0
- package/dist/templates/render-helpers.d.ts.map +1 -0
- package/dist/templates/render-helpers.js +78 -0
- package/dist/templates/render-helpers.js.map +1 -0
- package/dist/utils/config.d.ts.map +1 -1
- package/dist/utils/config.js +6 -2
- package/dist/utils/config.js.map +1 -1
- package/dist/utils/http.d.ts +5 -0
- package/dist/utils/http.d.ts.map +1 -0
- package/dist/utils/http.js +13 -0
- package/dist/utils/http.js.map +1 -0
- package/dist/utils/index-path.d.ts +7 -0
- package/dist/utils/index-path.d.ts.map +1 -0
- package/dist/utils/index-path.js +25 -0
- package/dist/utils/index-path.js.map +1 -0
- package/dist/utils/io.d.ts +8 -0
- package/dist/utils/io.d.ts.map +1 -0
- package/dist/utils/io.js +31 -0
- package/dist/utils/io.js.map +1 -0
- package/dist/utils/method-spec.d.ts +4 -0
- package/dist/utils/method-spec.d.ts.map +1 -0
- package/dist/utils/method-spec.js +49 -0
- package/dist/utils/method-spec.js.map +1 -0
- package/dist/utils/parts.d.ts +4 -0
- package/dist/utils/parts.d.ts.map +1 -0
- package/dist/utils/parts.js +9 -0
- package/dist/utils/parts.js.map +1 -0
- package/dist/utils/patch-index.d.ts +8 -3
- package/dist/utils/patch-index.d.ts.map +1 -1
- package/dist/utils/patch-index.js +45 -25
- package/dist/utils/patch-index.js.map +1 -1
- package/dist/utils/patch-method.d.ts +14 -0
- package/dist/utils/patch-method.d.ts.map +1 -0
- package/dist/utils/patch-method.js +128 -0
- package/dist/utils/patch-method.js.map +1 -0
- package/dist/utils/template-loader.d.ts +3 -0
- package/dist/utils/template-loader.d.ts.map +1 -0
- package/dist/utils/template-loader.js +17 -0
- package/dist/utils/template-loader.js.map +1 -0
- package/package.json +28 -4
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.renderControllerMethod = renderControllerMethod;
|
|
4
|
+
exports.renderServiceMethod = renderServiceMethod;
|
|
5
|
+
exports.renderDtoBlock = renderDtoBlock;
|
|
6
|
+
exports.renderValidatorBlock = renderValidatorBlock;
|
|
7
|
+
exports.renderRouteLine = renderRouteLine;
|
|
8
|
+
exports.renderMiddlewareImports = renderMiddlewareImports;
|
|
9
|
+
exports.applyTemplate = applyTemplate;
|
|
10
|
+
const http_1 = require("../utils/http");
|
|
11
|
+
const naming_1 = require("../utils/naming");
|
|
12
|
+
function renderControllerMethod(names, method) {
|
|
13
|
+
return `
|
|
14
|
+
async ${method.name}(req: e.Request, res: e.Response) {
|
|
15
|
+
try {
|
|
16
|
+
const result = await ${names.pascal}Service.${method.name}({
|
|
17
|
+
body: req.body,
|
|
18
|
+
query: req.query,
|
|
19
|
+
params: req.params,
|
|
20
|
+
});
|
|
21
|
+
return res.success(result);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
return res.error(error);
|
|
24
|
+
}
|
|
25
|
+
}`;
|
|
26
|
+
}
|
|
27
|
+
function renderServiceMethod(names, method) {
|
|
28
|
+
return `
|
|
29
|
+
async ${method.name}(dto: ${method.name}DTO) {
|
|
30
|
+
throw new Error("${names.pascal}Service.${method.name} is not implemented");
|
|
31
|
+
}`;
|
|
32
|
+
}
|
|
33
|
+
function renderDtoBlock(method) {
|
|
34
|
+
return `export interface ${method.name}DTO {
|
|
35
|
+
params?: Record<string, string>;
|
|
36
|
+
query?: Record<string, string | undefined>;
|
|
37
|
+
body?: Record<string, unknown>;
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
40
|
+
}
|
|
41
|
+
function renderValidatorBlock(method) {
|
|
42
|
+
return `export const ${method.name} = z.object({
|
|
43
|
+
params: z.object({}).optional(),
|
|
44
|
+
query: z.object({}).optional(),
|
|
45
|
+
body: z.object({}).optional(),
|
|
46
|
+
});
|
|
47
|
+
`;
|
|
48
|
+
}
|
|
49
|
+
function renderRouteLine(method, middleware) {
|
|
50
|
+
const routePath = (0, naming_1.methodToRoutePath)(method.name, method.route);
|
|
51
|
+
const chain = [...middleware, `validate(${method.name})`, `(req: Request, res: Response) => controller.${method.name}(req, res)`];
|
|
52
|
+
return `router.${(0, http_1.routerFn)(method.httpMethod)}("${routePath}", ${chain.join(", ")});`;
|
|
53
|
+
}
|
|
54
|
+
function renderMiddlewareImports(middleware) {
|
|
55
|
+
if (middleware.length === 0) {
|
|
56
|
+
return "";
|
|
57
|
+
}
|
|
58
|
+
return `${middleware.map(name => `import ${name} from "../../middlewares/${name}";`).join("\n")}\n`;
|
|
59
|
+
}
|
|
60
|
+
function applyTemplate(template, ctx, part) {
|
|
61
|
+
const { names, methods, middleware } = ctx;
|
|
62
|
+
const methodsCode = part === "controller"
|
|
63
|
+
? methods.map(method => renderControllerMethod(names, method)).join("\n")
|
|
64
|
+
: part === "service"
|
|
65
|
+
? methods.map(method => renderServiceMethod(names, method)).join("\n")
|
|
66
|
+
: "";
|
|
67
|
+
return template
|
|
68
|
+
.replaceAll("{{pascalName}}", names.pascal)
|
|
69
|
+
.replaceAll("{{kebabName}}", names.kebab)
|
|
70
|
+
.replaceAll("{{camelName}}", names.camel)
|
|
71
|
+
.replaceAll("{{methodsCode}}", methodsCode)
|
|
72
|
+
.replaceAll("{{dtoBlocks}}", methods.map(renderDtoBlock).join("\n"))
|
|
73
|
+
.replaceAll("{{validatorBlocks}}", methods.map(renderValidatorBlock).join("\n"))
|
|
74
|
+
.replaceAll("{{routes}}", methods.map(method => renderRouteLine(method, middleware)).join("\n"))
|
|
75
|
+
.replaceAll("{{validatorImports}}", methods.map(method => method.name).join(", "))
|
|
76
|
+
.replaceAll("{{middlewareImports}}", renderMiddlewareImports(middleware));
|
|
77
|
+
}
|
|
78
|
+
//# sourceMappingURL=render-helpers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-helpers.js","sourceRoot":"","sources":["../../src/templates/render-helpers.ts"],"names":[],"mappings":";;AAIA,wDAcC;AAED,kDAKC;AAED,wCAOC;AAED,oDAOC;AAED,0CAIC;AAED,0DAMC;AAED,sCAmBC;AA7ED,wCAAyC;AACzC,4CAAoD;AAEpD,SAAgB,sBAAsB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,IAAI,CAAC,CAAC;SACjF,UAAU,CAAC,uBAAuB,EAAE,uBAAuB,CAAC,UAAU,CAAC,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAQ3C,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAQ3C,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAmBlD;AAED,wBAAgB,uBAAuB,IAAI,MAAM,CAEhD"}
|
package/dist/utils/config.js
CHANGED
|
@@ -12,14 +12,18 @@ const DEFAULT_CONFIG = {
|
|
|
12
12
|
function loadConfig(cwd) {
|
|
13
13
|
const configPath = (0, path_1.join)(cwd, ".bogorc.json");
|
|
14
14
|
if (!(0, fs_1.existsSync)(configPath)) {
|
|
15
|
-
return DEFAULT_CONFIG;
|
|
15
|
+
return { ...DEFAULT_CONFIG };
|
|
16
16
|
}
|
|
17
17
|
const raw = (0, fs_1.readFileSync)(configPath, "utf-8");
|
|
18
18
|
const parsed = JSON.parse(raw);
|
|
19
|
-
|
|
19
|
+
const config = {
|
|
20
20
|
...DEFAULT_CONFIG,
|
|
21
21
|
...parsed,
|
|
22
22
|
};
|
|
23
|
+
if (config.templatesDir) {
|
|
24
|
+
config.templatesDir = (0, path_1.join)(cwd, config.templatesDir);
|
|
25
|
+
}
|
|
26
|
+
return config;
|
|
23
27
|
}
|
|
24
28
|
function getDefaultConfigContent() {
|
|
25
29
|
return `${JSON.stringify(DEFAULT_CONFIG, null, 2)}\n`;
|
package/dist/utils/config.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":";;AAUA,
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":";;AAUA,gCAmBC;AAED,0DAEC;AAjCD,2BAA8C;AAC9C,+BAA4B;AAG5B,MAAM,cAAc,GAAe;IACjC,MAAM,EAAE,SAAS;IACjB,SAAS,EAAE,cAAc;IACzB,WAAW,EAAE,MAAM;CACpB,CAAC;AAEF,SAAgB,UAAU,CAAC,GAAW;IACpC,MAAM,UAAU,GAAG,IAAA,WAAI,EAAC,GAAG,EAAE,cAAc,CAAC,CAAC;IAE7C,IAAI,CAAC,IAAA,eAAU,EAAC,UAAU,CAAC,EAAE,CAAC;QAC5B,OAAO,EAAE,GAAG,cAAc,EAAE,CAAC;IAC/B,CAAC;IAED,MAAM,GAAG,GAAG,IAAA,iBAAY,EAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAwB,CAAC;IACtD,MAAM,MAAM,GAAe;QACzB,GAAG,cAAc;QACjB,GAAG,MAAM;KACV,CAAC;IAEF,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;QACxB,MAAM,CAAC,YAAY,GAAG,IAAA,WAAI,EAAC,GAAG,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC;IACvD,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAgB,uBAAuB;IACrC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;AACxD,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { HttpMethod } from "../interfaces";
|
|
2
|
+
export declare const HTTP_METHODS: HttpMethod[];
|
|
3
|
+
export declare function isHttpMethod(value: string): value is HttpMethod;
|
|
4
|
+
export declare function routerFn(httpMethod: HttpMethod): string;
|
|
5
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/utils/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,eAAO,MAAM,YAAY,EAAE,UAAU,EAA8C,CAAC;AAEpF,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,UAAU,CAE/D;AAED,wBAAgB,QAAQ,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,CAEvD"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HTTP_METHODS = void 0;
|
|
4
|
+
exports.isHttpMethod = isHttpMethod;
|
|
5
|
+
exports.routerFn = routerFn;
|
|
6
|
+
exports.HTTP_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE"];
|
|
7
|
+
function isHttpMethod(value) {
|
|
8
|
+
return exports.HTTP_METHODS.includes(value.toUpperCase());
|
|
9
|
+
}
|
|
10
|
+
function routerFn(httpMethod) {
|
|
11
|
+
return httpMethod.toLowerCase();
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/utils/http.ts"],"names":[],"mappings":";;;AAIA,oCAEC;AAED,4BAEC;AARY,QAAA,YAAY,GAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC;AAEpF,SAAgB,YAAY,CAAC,KAAa;IACxC,OAAO,oBAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,WAAW,EAAgB,CAAC,CAAC;AAClE,CAAC;AAED,SAAgB,QAAQ,CAAC,UAAsB;IAC7C,OAAO,UAAU,CAAC,WAAW,EAAE,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ModuleNames } from "../interfaces";
|
|
2
|
+
export declare function routesImportPath(indexFile: string, apiDir: string, names: ModuleNames): string;
|
|
3
|
+
export declare function buildIndexLines(indexFile: string, apiDir: string, names: ModuleNames, routePrefix: string): {
|
|
4
|
+
importLine: string;
|
|
5
|
+
useLine: string;
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=index-path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-path.d.ts","sourceRoot":"","sources":["../../src/utils/index-path.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAU5C,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAI9F;AAED,wBAAgB,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM;;;EAMzG"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.routesImportPath = routesImportPath;
|
|
4
|
+
exports.buildIndexLines = buildIndexLines;
|
|
5
|
+
const path_1 = require("path");
|
|
6
|
+
function normalizeRelativePath(fromDir, toPath) {
|
|
7
|
+
let rel = (0, path_1.relative)(fromDir, toPath).replace(/\\/g, "/");
|
|
8
|
+
if (!rel.startsWith(".")) {
|
|
9
|
+
rel = `./${rel}`;
|
|
10
|
+
}
|
|
11
|
+
return rel;
|
|
12
|
+
}
|
|
13
|
+
function routesImportPath(indexFile, apiDir, names) {
|
|
14
|
+
const indexDir = (0, path_1.dirname)(indexFile);
|
|
15
|
+
const routesFile = (0, path_1.join)(apiDir, names.kebab, `${names.kebab}.routes`);
|
|
16
|
+
return normalizeRelativePath(indexDir, routesFile);
|
|
17
|
+
}
|
|
18
|
+
function buildIndexLines(indexFile, apiDir, names, routePrefix) {
|
|
19
|
+
const importPath = routesImportPath(indexFile, apiDir, names);
|
|
20
|
+
return {
|
|
21
|
+
importLine: `import ${names.pascal}Routes from "${importPath}";`,
|
|
22
|
+
useLine: `app.use("${routePrefix}/${names.kebab}", ${names.pascal}Routes);`,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=index-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-path.js","sourceRoot":"","sources":["../../src/utils/index-path.ts"],"names":[],"mappings":";;AAWA,4CAIC;AAED,0CAMC;AAvBD,+BAA+C;AAG/C,SAAS,qBAAqB,CAAC,OAAe,EAAE,MAAc;IAC5D,IAAI,GAAG,GAAG,IAAA,eAAQ,EAAC,OAAO,EAAE,MAAM,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;IACxD,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACzB,GAAG,GAAG,KAAK,GAAG,EAAE,CAAC;IACnB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAgB,gBAAgB,CAAC,SAAiB,EAAE,MAAc,EAAE,KAAkB;IACpF,MAAM,QAAQ,GAAG,IAAA,cAAO,EAAC,SAAS,CAAC,CAAC;IACpC,MAAM,UAAU,GAAG,IAAA,WAAI,EAAC,MAAM,EAAE,KAAK,CAAC,KAAK,EAAE,GAAG,KAAK,CAAC,KAAK,SAAS,CAAC,CAAC;IACtE,OAAO,qBAAqB,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;AACrD,CAAC;AAED,SAAgB,eAAe,CAAC,SAAiB,EAAE,MAAc,EAAE,KAAkB,EAAE,WAAmB;IACxG,MAAM,UAAU,GAAG,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAC9D,OAAO;QACL,UAAU,EAAE,UAAU,KAAK,CAAC,MAAM,gBAAgB,UAAU,IAAI;QAChE,OAAO,EAAE,YAAY,WAAW,IAAI,KAAK,CAAC,KAAK,MAAM,KAAK,CAAC,MAAM,UAAU;KAC5E,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export interface WriteOptions {
|
|
2
|
+
dryRun?: boolean;
|
|
3
|
+
force?: boolean;
|
|
4
|
+
}
|
|
5
|
+
export declare function writeTextFile(filePath: string, content: string, options?: WriteOptions): void;
|
|
6
|
+
export declare function ensureDir(dirPath: string, options?: WriteOptions): void;
|
|
7
|
+
export declare function removePath(_path: string, options?: WriteOptions): void;
|
|
8
|
+
//# sourceMappingURL=io.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"io.d.ts","sourceRoot":"","sources":["../../src/utils/io.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,IAAI,CAWjG;AAED,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,IAAI,CAS3E;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,YAAiB,GAAG,IAAI,CAI1E"}
|
package/dist/utils/io.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writeTextFile = writeTextFile;
|
|
4
|
+
exports.ensureDir = ensureDir;
|
|
5
|
+
exports.removePath = removePath;
|
|
6
|
+
const fs_1 = require("fs");
|
|
7
|
+
function writeTextFile(filePath, content, options = {}) {
|
|
8
|
+
if (options.dryRun) {
|
|
9
|
+
console.log(`[dry-run] write ${filePath}`);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if ((0, fs_1.existsSync)(filePath) && !options.force) {
|
|
13
|
+
throw new Error(`File already exists: ${filePath}`);
|
|
14
|
+
}
|
|
15
|
+
(0, fs_1.writeFileSync)(filePath, content, "utf-8");
|
|
16
|
+
}
|
|
17
|
+
function ensureDir(dirPath, options = {}) {
|
|
18
|
+
if (options.dryRun) {
|
|
19
|
+
console.log(`[dry-run] mkdir ${dirPath}`);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (!(0, fs_1.existsSync)(dirPath)) {
|
|
23
|
+
(0, fs_1.mkdirSync)(dirPath, { recursive: true });
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function removePath(_path, options = {}) {
|
|
27
|
+
if (options.dryRun) {
|
|
28
|
+
console.log(`[dry-run] remove ${_path}`);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=io.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"io.js","sourceRoot":"","sources":["../../src/utils/io.ts"],"names":[],"mappings":";;AAOA,sCAWC;AAED,8BASC;AAED,gCAIC;AAnCD,2BAA0D;AAO1D,SAAgB,aAAa,CAAC,QAAgB,EAAE,OAAe,EAAE,UAAwB,EAAE;IACzF,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACnB,OAAO,CAAC,GAAG,CAAC,mBAAmB,QAAQ,EAAE,CAAC,CAAC;QAC3C,OAAO;IACT,CAAC;IAED,IAAI,IAAA,eAAU,EAAC,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;QAC3C,MAAM,IAAI,KAAK,CAAC,wBAAwB,QAAQ,EAAE,CAAC,CAAC;IACtD,CAAC;IAED,IAAA,kBAAa,EAAC,QAAQ,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;AAC5C,CAAC;AAED,SAAgB,SAAS,CAAC,OAAe,EAAE,UAAwB,EAAE;IACnE,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACnB,OAAO,CAAC,GAAG,CAAC,mBAAmB,OAAO,EAAE,CAAC,CAAC;QAC1C,OAAO;IACT,CAAC;IAED,IAAI,CAAC,IAAA,eAAU,EAAC,OAAO,CAAC,EAAE,CAAC;QACzB,IAAA,cAAS,EAAC,OAAO,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC1C,CAAC;AACH,CAAC;AAED,SAAgB,UAAU,CAAC,KAAa,EAAE,UAAwB,EAAE;IAClE,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACnB,OAAO,CAAC,GAAG,CAAC,oBAAoB,KAAK,EAAE,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"method-spec.d.ts","sourceRoot":"","sources":["../../src/utils/method-spec.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAI3C,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CA+BvD;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAchG"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseMethodSpec = parseMethodSpec;
|
|
4
|
+
exports.methodExistsInContent = methodExistsInContent;
|
|
5
|
+
const http_1 = require("./http");
|
|
6
|
+
const naming_1 = require("./naming");
|
|
7
|
+
function parseMethodSpec(raw) {
|
|
8
|
+
const match = raw.match(/^([a-zA-Z][a-zA-Z0-9]*)(?::(.*))?$/);
|
|
9
|
+
if (!match) {
|
|
10
|
+
throw new Error(`Invalid method name: "${raw}". Examples: getList, getList:GET, getOrder:GET:/:id`);
|
|
11
|
+
}
|
|
12
|
+
const name = match[1];
|
|
13
|
+
const rest = match[2];
|
|
14
|
+
if (!rest) {
|
|
15
|
+
return { name, httpMethod: "POST" };
|
|
16
|
+
}
|
|
17
|
+
if ((0, http_1.isHttpMethod)(rest)) {
|
|
18
|
+
return { name, httpMethod: rest.toUpperCase() };
|
|
19
|
+
}
|
|
20
|
+
const verbMatch = rest.match(/^(GET|POST|PUT|PATCH|DELETE):(.+)$/i);
|
|
21
|
+
if (verbMatch) {
|
|
22
|
+
return {
|
|
23
|
+
name,
|
|
24
|
+
httpMethod: verbMatch[1].toUpperCase(),
|
|
25
|
+
route: (0, naming_1.methodToRoutePath)(name, verbMatch[2]),
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
name,
|
|
30
|
+
httpMethod: "POST",
|
|
31
|
+
route: (0, naming_1.methodToRoutePath)(name, rest),
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
function methodExistsInContent(content, methodName, part) {
|
|
35
|
+
switch (part) {
|
|
36
|
+
case "controller":
|
|
37
|
+
case "service":
|
|
38
|
+
return new RegExp(`async ${methodName}\\(`).test(content);
|
|
39
|
+
case "dto":
|
|
40
|
+
return new RegExp(`interface ${methodName}DTO`).test(content);
|
|
41
|
+
case "validator":
|
|
42
|
+
return new RegExp(`export const ${methodName} =`).test(content);
|
|
43
|
+
case "routes":
|
|
44
|
+
return content.includes(`controller.${methodName}(`);
|
|
45
|
+
default:
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=method-spec.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"method-spec.js","sourceRoot":"","sources":["../../src/utils/method-spec.ts"],"names":[],"mappings":";;AAIA,0CA+BC;AAED,sDAcC;AAlDD,iCAAsC;AACtC,qCAA6C;AAE7C,SAA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O,IAAI,MAAM,CAAC,aAAa,UAAU,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAChE,KAAK,WAAW;YACd,OAAO,IAAI,MAAM,CAAC,gBAAgB,UAAU,IAAI,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAClE,KAAK,QAAQ;YACX,OAAO,OAAO,CAAC,QAAQ,CAAC,cAAc,UAAU,GAAG,CAAC,CAAC;QACvD;YACE,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parts.d.ts","sourceRoot":"","sources":["../../src/utils/parts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C,eAAO,MAAM,YAAY,EAAE,UAAU,EAA4D,CAAC;AAElG,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,UAAU,CAE/D"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MODULE_PARTS = void 0;
|
|
4
|
+
exports.isModulePart = isModulePart;
|
|
5
|
+
exports.MODULE_PARTS = ["controller", "service", "dto", "validator", "routes"];
|
|
6
|
+
function isModulePart(value) {
|
|
7
|
+
return exports.MODULE_PARTS.includes(value);
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=parts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parts.js","sourceRoot":"","sources":["../../src/utils/parts.ts"],"names":[],"mappings":";;;AAIA,oCAEC;AAJY,QAAA,YAAY,GAAiB,CAAC,YAAY,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC;AAElG,SAAgB,YAAY,CAAC,KAAa;IACxC,OAAO,oBAAY,CAAC,QAAQ,CAAC,KAAmB,CAAC,CAAC;AACpD,CAAC"}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import { ModuleNames } from "../interfaces";
|
|
2
|
-
export declare function patchIndexFile(
|
|
3
|
-
|
|
1
|
+
import { BogoConfig, ModuleNames } from "../interfaces";
|
|
2
|
+
export declare function patchIndexFile(cwd: string, config: BogoConfig, names: ModuleNames, options?: {
|
|
3
|
+
dryRun?: boolean;
|
|
4
|
+
}): boolean;
|
|
5
|
+
export declare function suggestIndexPatch(config: BogoConfig, names: ModuleNames): string;
|
|
6
|
+
export declare function unpatchIndexFile(cwd: string, config: BogoConfig, names: ModuleNames, options?: {
|
|
7
|
+
dryRun?: boolean;
|
|
8
|
+
}): boolean;
|
|
4
9
|
//# sourceMappingURL=patch-index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch-index.d.ts","sourceRoot":"","sources":["../../src/utils/patch-index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"patch-index.d.ts","sourceRoot":"","sources":["../../src/utils/patch-index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAGxD,wBAAgB,cAAc,CAC5B,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,WAAW,EAClB,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GACjC,OAAO,CAiDT;AAED,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,GAAG,MAAM,CAMhF;AAED,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,WAAW,EAClB,OAAO,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,CAAA;CAAO,GACjC,OAAO,CAqBT"}
|
|
@@ -2,57 +2,77 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.patchIndexFile = patchIndexFile;
|
|
4
4
|
exports.suggestIndexPatch = suggestIndexPatch;
|
|
5
|
+
exports.unpatchIndexFile = unpatchIndexFile;
|
|
5
6
|
const fs_1 = require("fs");
|
|
6
|
-
|
|
7
|
+
const path_1 = require("path");
|
|
8
|
+
const index_path_1 = require("./index-path");
|
|
9
|
+
function patchIndexFile(cwd, config, names, options = {}) {
|
|
10
|
+
const indexPath = (0, path_1.join)(cwd, config.indexFile);
|
|
7
11
|
if (!(0, fs_1.existsSync)(indexPath)) {
|
|
8
12
|
return false;
|
|
9
13
|
}
|
|
10
|
-
const importLine =
|
|
11
|
-
const useLine = `app.use("${routePrefix}/${names.kebab}", ${names.pascal}Routes);`;
|
|
14
|
+
const { importLine, useLine } = (0, index_path_1.buildIndexLines)(config.indexFile, config.apiDir, names, config.routePrefix);
|
|
12
15
|
let content = (0, fs_1.readFileSync)(indexPath, "utf-8");
|
|
13
16
|
if (content.includes(importLine) || content.includes(useLine)) {
|
|
14
17
|
return false;
|
|
15
18
|
}
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
if (/^import .+ from .+;$/.test(lines[i])) {
|
|
22
|
-
lastImportIndex = i;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
if (lastImportIndex >= 0) {
|
|
26
|
-
lines.splice(lastImportIndex + 1, 0, importLine);
|
|
27
|
-
content = lines.join("\n");
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
content = `${importLine}\n${content}`;
|
|
19
|
+
const lines = content.split("\n");
|
|
20
|
+
let lastImportIndex = -1;
|
|
21
|
+
for (let i = 0; i < lines.length; i++) {
|
|
22
|
+
if (/^import .+ from .+;$/.test(lines[i])) {
|
|
23
|
+
lastImportIndex = i;
|
|
31
24
|
}
|
|
32
25
|
}
|
|
26
|
+
if (lastImportIndex >= 0) {
|
|
27
|
+
lines.splice(lastImportIndex + 1, 0, importLine);
|
|
28
|
+
}
|
|
33
29
|
else {
|
|
34
|
-
|
|
30
|
+
lines.unshift(importLine);
|
|
35
31
|
}
|
|
36
|
-
|
|
37
|
-
|
|
32
|
+
content = lines.join("\n");
|
|
33
|
+
const useAnchor = content.match(/app\.use\("[^"]+", .+Routes\);/);
|
|
34
|
+
if (useAnchor) {
|
|
38
35
|
content = content.replace(useAnchor[0], `${useAnchor[0]}\n${useLine}`);
|
|
39
36
|
}
|
|
40
37
|
else {
|
|
41
38
|
const listenAnchor = content.match(/app\.listen\(/);
|
|
42
|
-
if (listenAnchor
|
|
39
|
+
if (listenAnchor) {
|
|
43
40
|
content = content.replace(listenAnchor[0], `${useLine}\n\n${listenAnchor[0]}`);
|
|
44
41
|
}
|
|
45
42
|
else {
|
|
46
43
|
content = `${content.trimEnd()}\n${useLine}\n`;
|
|
47
44
|
}
|
|
48
45
|
}
|
|
46
|
+
if (options.dryRun) {
|
|
47
|
+
console.log(`[dry-run] patch ${indexPath}`);
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
49
50
|
(0, fs_1.writeFileSync)(indexPath, content, "utf-8");
|
|
50
51
|
return true;
|
|
51
52
|
}
|
|
52
|
-
function suggestIndexPatch(
|
|
53
|
+
function suggestIndexPatch(config, names) {
|
|
54
|
+
const { importLine, useLine } = (0, index_path_1.buildIndexLines)(config.indexFile, config.apiDir, names, config.routePrefix);
|
|
53
55
|
return `Add to index manually:
|
|
54
56
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
+
${importLine}
|
|
58
|
+
${useLine}`;
|
|
59
|
+
}
|
|
60
|
+
function unpatchIndexFile(cwd, config, names, options = {}) {
|
|
61
|
+
const indexPath = (0, path_1.join)(cwd, config.indexFile);
|
|
62
|
+
if (!(0, fs_1.existsSync)(indexPath)) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
const { importLine, useLine } = (0, index_path_1.buildIndexLines)(config.indexFile, config.apiDir, names, config.routePrefix);
|
|
66
|
+
const lines = (0, fs_1.readFileSync)(indexPath, "utf-8").split("\n");
|
|
67
|
+
const filtered = lines.filter(line => line !== importLine && line !== useLine);
|
|
68
|
+
if (filtered.length === lines.length) {
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
if (options.dryRun) {
|
|
72
|
+
console.log(`[dry-run] unpatch ${indexPath}`);
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
(0, fs_1.writeFileSync)(indexPath, filtered.join("\n"), "utf-8");
|
|
76
|
+
return true;
|
|
57
77
|
}
|
|
58
78
|
//# sourceMappingURL=patch-index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"patch-index.js","sourceRoot":"","sources":["../../src/utils/patch-index.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"patch-index.js","sourceRoot":"","sources":["../../src/utils/patch-index.ts"],"names":[],"mappings":";;AAKA,wCAsDC;AAED,8CAMC;AAED,4CA0BC;AA/FD,2BAA6D;AAC7D,+BAA4B;AAE5B,6CAA+C;AAE/C,SAAgB,cAAc,CAC5B,GAAW,EACX,MAAkB,EAClB,KAAkB,EAClB,UAAgC,EAAE;IAElC,MAAM,SAAS,GAAG,IAAA,WAAI,EAAC,GAAG,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;IAC9C,IAAI,CAAC,IAAA,eAAU,EAAC,SAAS,CAAC,EAAE,CAAC;QAC3B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,MAAM,EAAE,UAAU,EAAE,OAAO,EAAE,GAAG,IAAA,4BAAe,EAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC;IAC5G,IAAI,OAAO,GAAG,IAAA,iBAAY,EAAC,SAAS,EAAE,OAAO,CAAC,CAAC;IAE/C,IAAI,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,IAAI,OAAO,CAAC,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,CAAC,MAAM,KAAK,KAAK,CAAC,MAAM,EAAE,CAAC;QACrC,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC;QACnB,OAAO,CAAC,GAAG,CAAC,qBAAqB,SAAS,EAAE,CAAC,CAAC;QAC9C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAA,kBAAa,EAAC,SAAS,EAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC;IACvD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MethodSpec, ModuleTemplateContext, ModulePart } from "../interfaces";
|
|
2
|
+
export declare function patchControllerMethod(content: string, ctx: ModuleTemplateContext, method: MethodSpec): string;
|
|
3
|
+
export declare function patchServiceMethod(content: string, ctx: ModuleTemplateContext, method: MethodSpec): string;
|
|
4
|
+
export declare function patchDtoMethod(content: string, _ctx: ModuleTemplateContext, method: MethodSpec): string;
|
|
5
|
+
export declare function patchValidatorMethod(content: string, _ctx: ModuleTemplateContext, method: MethodSpec): string;
|
|
6
|
+
export declare function patchRoutesMethod(content: string, ctx: ModuleTemplateContext, method: MethodSpec): string;
|
|
7
|
+
export declare function removeControllerMethod(content: string, methodName: string): string;
|
|
8
|
+
export declare function removeServiceMethod(content: string, ctx: ModuleTemplateContext, methodName: string): string;
|
|
9
|
+
export declare function removeDtoMethod(content: string, methodName: string): string;
|
|
10
|
+
export declare function removeValidatorMethod(content: string, methodName: string): string;
|
|
11
|
+
export declare function removeRoutesMethod(content: string, ctx: ModuleTemplateContext, method: MethodSpec): string;
|
|
12
|
+
export declare const PATCHERS: Record<ModulePart, (content: string, ctx: ModuleTemplateContext, method: MethodSpec) => string>;
|
|
13
|
+
export declare const REMOVERS: Record<ModulePart, (content: string, ctx: ModuleTemplateContext, method: MethodSpec) => string>;
|
|
14
|
+
//# sourceMappingURL=patch-method.d.ts.map
|
|
@@ -0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AAG,MAAM,CAc1G;AAED,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,qBAAqB,EAAE,MAAM,EAAE,UAAU,KAAK,MAAM,CAMpH,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,qBAAqB,EAAE,MAAM,EAAE,UAAU,KAAK,MAAM,CAMpH,CAAC"}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.REMOVERS = exports.PATCHERS = void 0;
|
|
4
|
+
exports.patchControllerMethod = patchControllerMethod;
|
|
5
|
+
exports.patchServiceMethod = patchServiceMethod;
|
|
6
|
+
exports.patchDtoMethod = patchDtoMethod;
|
|
7
|
+
exports.patchValidatorMethod = patchValidatorMethod;
|
|
8
|
+
exports.patchRoutesMethod = patchRoutesMethod;
|
|
9
|
+
exports.removeControllerMethod = removeControllerMethod;
|
|
10
|
+
exports.removeServiceMethod = removeServiceMethod;
|
|
11
|
+
exports.removeDtoMethod = removeDtoMethod;
|
|
12
|
+
exports.removeValidatorMethod = removeValidatorMethod;
|
|
13
|
+
exports.removeRoutesMethod = removeRoutesMethod;
|
|
14
|
+
const render_helpers_1 = require("../templates/render-helpers");
|
|
15
|
+
const http_1 = require("./http");
|
|
16
|
+
const naming_1 = require("./naming");
|
|
17
|
+
function addImportSymbol(content, importPattern, symbol) {
|
|
18
|
+
const match = content.match(importPattern);
|
|
19
|
+
if (!match) {
|
|
20
|
+
return content;
|
|
21
|
+
}
|
|
22
|
+
const symbols = match[1].split(",").map(value => value.trim()).filter(Boolean);
|
|
23
|
+
if (symbols.includes(symbol)) {
|
|
24
|
+
return content;
|
|
25
|
+
}
|
|
26
|
+
return content.replace(match[0], match[0].replace(match[1], `${match[1]}, ${symbol}`));
|
|
27
|
+
}
|
|
28
|
+
function removeImportSymbol(content, importPattern, symbol) {
|
|
29
|
+
const match = content.match(importPattern);
|
|
30
|
+
if (!match) {
|
|
31
|
+
return content;
|
|
32
|
+
}
|
|
33
|
+
const symbols = match[1]
|
|
34
|
+
.split(",")
|
|
35
|
+
.map(value => value.trim())
|
|
36
|
+
.filter(Boolean)
|
|
37
|
+
.filter(value => value !== symbol);
|
|
38
|
+
if (symbols.length === 0) {
|
|
39
|
+
return content.replace(`${match[0]}\n`, "");
|
|
40
|
+
}
|
|
41
|
+
return content.replace(match[0], match[0].replace(match[1], symbols.join(", ")));
|
|
42
|
+
}
|
|
43
|
+
function patchControllerMethod(content, ctx, method) {
|
|
44
|
+
if (new RegExp(`async ${method.name}\\(`).test(content)) {
|
|
45
|
+
throw new Error(`Method "${method.name}" already exists in controller`);
|
|
46
|
+
}
|
|
47
|
+
const snippet = (0, render_helpers_1.renderControllerMethod)(ctx.names, method);
|
|
48
|
+
const updated = content.replace(/(\n}\n\nexport default new .+Controller\(\);)/, `${snippet}$1`);
|
|
49
|
+
if (updated === content) {
|
|
50
|
+
throw new Error("Could not patch controller file");
|
|
51
|
+
}
|
|
52
|
+
return updated;
|
|
53
|
+
}
|
|
54
|
+
function patchServiceMethod(content, ctx, method) {
|
|
55
|
+
if (new RegExp(`async ${method.name}\\(`).test(content)) {
|
|
56
|
+
throw new Error(`Method "${method.name}" already exists in service`);
|
|
57
|
+
}
|
|
58
|
+
let updated = addImportSymbol(content, new RegExp(`import \\{ (.+) \\} from "\\./${ctx.names.kebab}\\.dto";`), `${method.name}DTO`);
|
|
59
|
+
const snippet = (0, render_helpers_1.renderServiceMethod)(ctx.names, method);
|
|
60
|
+
updated = updated.replace(/(\n}\n\nexport default new .+Service\(\);)/, `${snippet}$1`);
|
|
61
|
+
if (updated === content) {
|
|
62
|
+
throw new Error("Could not patch service file");
|
|
63
|
+
}
|
|
64
|
+
return updated;
|
|
65
|
+
}
|
|
66
|
+
function patchDtoMethod(content, _ctx, method) {
|
|
67
|
+
if (new RegExp(`interface ${method.name}DTO`).test(content)) {
|
|
68
|
+
throw new Error(`Method "${method.name}" already exists in dto`);
|
|
69
|
+
}
|
|
70
|
+
return `${content.trimEnd()}\n${(0, render_helpers_1.renderDtoBlock)(method)}`;
|
|
71
|
+
}
|
|
72
|
+
function patchValidatorMethod(content, _ctx, method) {
|
|
73
|
+
if (new RegExp(`export const ${method.name} =`).test(content)) {
|
|
74
|
+
throw new Error(`Method "${method.name}" already exists in validator`);
|
|
75
|
+
}
|
|
76
|
+
return `${content.trimEnd()}\n${(0, render_helpers_1.renderValidatorBlock)(method)}`;
|
|
77
|
+
}
|
|
78
|
+
function patchRoutesMethod(content, ctx, method) {
|
|
79
|
+
if (content.includes(`controller.${method.name}(`)) {
|
|
80
|
+
throw new Error(`Method "${method.name}" already exists in routes`);
|
|
81
|
+
}
|
|
82
|
+
let updated = addImportSymbol(content, new RegExp(`import \\{ (.+) \\} from "\\./${ctx.names.kebab}\\.validator";`), method.name);
|
|
83
|
+
const snippet = (0, render_helpers_1.renderRouteLine)(method, ctx.middleware);
|
|
84
|
+
updated = updated.replace(/(\n\nexport default router;\n?)$/, `\n${snippet}$1`);
|
|
85
|
+
if (updated === content) {
|
|
86
|
+
throw new Error("Could not patch routes file");
|
|
87
|
+
}
|
|
88
|
+
return updated;
|
|
89
|
+
}
|
|
90
|
+
function removeBlock(content, pattern) {
|
|
91
|
+
return content.replace(pattern, "");
|
|
92
|
+
}
|
|
93
|
+
function removeControllerMethod(content, methodName) {
|
|
94
|
+
return removeBlock(content, new RegExp(`\\n async ${methodName}\\(req: e\\.Request, res: e\\.Response\\) \\{[\\s\\S]*?\\n \\}`, "m"));
|
|
95
|
+
}
|
|
96
|
+
function removeServiceMethod(content, ctx, methodName) {
|
|
97
|
+
let updated = removeBlock(content, new RegExp(`\\n async ${methodName}\\(dto: ${methodName}DTO\\) \\{[\\s\\S]*?\\n \\}`, "m"));
|
|
98
|
+
updated = removeImportSymbol(updated, new RegExp(`import \\{ (.+) \\} from "\\./${ctx.names.kebab}\\.dto";`), `${methodName}DTO`);
|
|
99
|
+
return updated;
|
|
100
|
+
}
|
|
101
|
+
function removeDtoMethod(content, methodName) {
|
|
102
|
+
return removeBlock(content, new RegExp(`\\nexport interface ${methodName}DTO \\{[\\s\\S]*?\\}\\n`, "m")).trimEnd() + "\n";
|
|
103
|
+
}
|
|
104
|
+
function removeValidatorMethod(content, methodName) {
|
|
105
|
+
return removeBlock(content, new RegExp(`\\nexport const ${methodName} = z\\.object\\(\\{[\\s\\S]*?\\}\\);\\n`, "m")).trimEnd() + "\n";
|
|
106
|
+
}
|
|
107
|
+
function removeRoutesMethod(content, ctx, method) {
|
|
108
|
+
const routePath = (0, naming_1.methodToRoutePath)(method.name, method.route);
|
|
109
|
+
const pattern = new RegExp(`\\nrouter\\.${(0, http_1.routerFn)(method.httpMethod)}\\("${routePath.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}"[\\s\\S]*?controller\\.${method.name}\\(req, res\\)\\);`, "m");
|
|
110
|
+
let updated = removeBlock(content, pattern);
|
|
111
|
+
updated = removeImportSymbol(updated, new RegExp(`import \\{ (.+) \\} from "\\./${ctx.names.kebab}\\.validator";`), method.name);
|
|
112
|
+
return updated;
|
|
113
|
+
}
|
|
114
|
+
exports.PATCHERS = {
|
|
115
|
+
controller: patchControllerMethod,
|
|
116
|
+
service: patchServiceMethod,
|
|
117
|
+
dto: patchDtoMethod,
|
|
118
|
+
validator: patchValidatorMethod,
|
|
119
|
+
routes: patchRoutesMethod,
|
|
120
|
+
};
|
|
121
|
+
exports.REMOVERS = {
|
|
122
|
+
controller: (content, _ctx, method) => removeControllerMethod(content, method.name),
|
|
123
|
+
service: (content, ctx, method) => removeServiceMethod(content, ctx, method.name),
|
|
124
|
+
dto: (content, _ctx, method) => removeDtoMethod(content, method.name),
|
|
125
|
+
validator: (content, _ctx, method) => removeValidatorMethod(content, method.name),
|
|
126
|
+
routes: (content, ctx, method) => removeRoutesMethod(content, ctx, method),
|
|
127
|
+
};
|
|
128
|
+
//# sourceMappingURL=patch-method.js.map
|