@bogomolcompany/bogo 0.1.2 → 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.
Files changed (74) hide show
  1. package/README.md +60 -10
  2. package/README.ru.md +60 -17
  3. package/dist/cli.js +92 -20
  4. package/dist/cli.js.map +1 -1
  5. package/dist/commands/add-method.d.ts.map +1 -1
  6. package/dist/commands/add-method.js +10 -11
  7. package/dist/commands/add-method.js.map +1 -1
  8. package/dist/commands/create-app.d.ts +2 -1
  9. package/dist/commands/create-app.d.ts.map +1 -1
  10. package/dist/commands/create-app.js +2 -2
  11. package/dist/commands/create-app.js.map +1 -1
  12. package/dist/commands/doctor.d.ts +2 -0
  13. package/dist/commands/doctor.d.ts.map +1 -0
  14. package/dist/commands/doctor.js +53 -0
  15. package/dist/commands/doctor.js.map +1 -0
  16. package/dist/commands/generate-module.d.ts.map +1 -1
  17. package/dist/commands/generate-module.js +21 -16
  18. package/dist/commands/generate-module.js.map +1 -1
  19. package/dist/commands/interactive.d.ts +3 -0
  20. package/dist/commands/interactive.d.ts.map +1 -0
  21. package/dist/commands/interactive.js +65 -0
  22. package/dist/commands/interactive.js.map +1 -0
  23. package/dist/commands/list-modules.d.ts +2 -0
  24. package/dist/commands/list-modules.d.ts.map +1 -0
  25. package/dist/commands/list-modules.js +36 -0
  26. package/dist/commands/list-modules.js.map +1 -0
  27. package/dist/commands/remove-module.d.ts +2 -1
  28. package/dist/commands/remove-module.d.ts.map +1 -1
  29. package/dist/commands/remove-module.js +61 -10
  30. package/dist/commands/remove-module.js.map +1 -1
  31. package/dist/templates/module.d.ts +14 -7
  32. package/dist/templates/module.d.ts.map +1 -1
  33. package/dist/templates/module.js +38 -63
  34. package/dist/templates/module.js.map +1 -1
  35. package/dist/templates/project.d.ts +2 -1
  36. package/dist/templates/project.d.ts.map +1 -1
  37. package/dist/templates/project.js +85 -17
  38. package/dist/templates/project.js.map +1 -1
  39. package/dist/templates/render-helpers.d.ts +9 -0
  40. package/dist/templates/render-helpers.d.ts.map +1 -0
  41. package/dist/templates/render-helpers.js +78 -0
  42. package/dist/templates/render-helpers.js.map +1 -0
  43. package/dist/utils/config.d.ts.map +1 -1
  44. package/dist/utils/config.js +6 -2
  45. package/dist/utils/config.js.map +1 -1
  46. package/dist/utils/http.d.ts +5 -0
  47. package/dist/utils/http.d.ts.map +1 -0
  48. package/dist/utils/http.js +13 -0
  49. package/dist/utils/http.js.map +1 -0
  50. package/dist/utils/index-path.d.ts +7 -0
  51. package/dist/utils/index-path.d.ts.map +1 -0
  52. package/dist/utils/index-path.js +25 -0
  53. package/dist/utils/index-path.js.map +1 -0
  54. package/dist/utils/io.d.ts +8 -0
  55. package/dist/utils/io.d.ts.map +1 -0
  56. package/dist/utils/io.js +31 -0
  57. package/dist/utils/io.js.map +1 -0
  58. package/dist/utils/method-spec.d.ts +4 -0
  59. package/dist/utils/method-spec.d.ts.map +1 -0
  60. package/dist/utils/method-spec.js +49 -0
  61. package/dist/utils/method-spec.js.map +1 -0
  62. package/dist/utils/patch-index.d.ts +8 -4
  63. package/dist/utils/patch-index.d.ts.map +1 -1
  64. package/dist/utils/patch-index.js +33 -28
  65. package/dist/utils/patch-index.js.map +1 -1
  66. package/dist/utils/patch-method.d.ts +13 -20
  67. package/dist/utils/patch-method.d.ts.map +1 -1
  68. package/dist/utils/patch-method.js +66 -37
  69. package/dist/utils/patch-method.js.map +1 -1
  70. package/dist/utils/template-loader.d.ts +3 -0
  71. package/dist/utils/template-loader.d.ts.map +1 -0
  72. package/dist/utils/template-loader.js +17 -0
  73. package/dist/utils/template-loader.js.map +1 -0
  74. package/package.json +4 -2
@@ -4,15 +4,17 @@ exports.writeProjectFiles = writeProjectFiles;
4
4
  const fs_1 = require("fs");
5
5
  const path_1 = require("path");
6
6
  const config_1 = require("../utils/config");
7
+ const io_1 = require("../utils/io");
7
8
  const PROJECT_FILES = {
8
9
  "package.json": `{
9
10
  "name": "express-api",
10
11
  "version": "0.1.0",
11
12
  "private": true,
12
13
  "scripts": {
13
- "dev": "ts-node src/index.ts",
14
+ "dev": "nodemon --watch src --exec ts-node src/index.ts",
14
15
  "build": "tsc",
15
- "start": "node dist/index.js"
16
+ "start": "node dist/index.js",
17
+ "lint": "eslint src --ext .ts"
16
18
  },
17
19
  "dependencies": {
18
20
  "body-parser": "^1.20.3",
@@ -26,6 +28,7 @@ const PROJECT_FILES = {
26
28
  "@types/body-parser": "^1.19.5",
27
29
  "@types/express": "^4.17.21",
28
30
  "@types/node": "^22.5.0",
31
+ "nodemon": "^3.1.4",
29
32
  "ts-node": "^10.9.2",
30
33
  "typescript": "^5.5.4"
31
34
  },
@@ -67,8 +70,10 @@ import "log-timestamp";
67
70
  import { formatResponse } from "./middlewares/formatResponse";
68
71
  import { logger } from "./middlewares/logger";
69
72
  import { getAllowedIps } from "./utils/getAllowedIps";
73
+ import { validateEnv } from "./utils/env";
70
74
 
71
75
  config.config();
76
+ validateEnv();
72
77
 
73
78
  const app = express();
74
79
 
@@ -173,32 +178,95 @@ export function validate(schema: ZodSchema) {
173
178
  "src/utils/getAllowedIps.ts": `export function getAllowedIps(raw: string): string[] {
174
179
  return raw.split(",").map(ip => ip.trim()).filter(Boolean);
175
180
  }
181
+ `,
182
+ "src/utils/env.ts": `import { z } from "zod";
183
+
184
+ const envSchema = z.object({
185
+ PORT: z.coerce.number().default(3000),
186
+ ALLOWED_IPS: z.string().optional(),
187
+ });
188
+
189
+ export function validateEnv() {
190
+ const parsed = envSchema.safeParse(process.env);
191
+ if (!parsed.success) {
192
+ throw new Error(parsed.error.message);
193
+ }
194
+ return parsed.data;
195
+ }
196
+ `,
197
+ };
198
+ const ESLINT_FILES = {
199
+ ".eslintrc.json": `{
200
+ "env": { "es2022": true, "node": true },
201
+ "parser": "@typescript-eslint/parser",
202
+ "plugins": ["@typescript-eslint"],
203
+ "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended"],
204
+ "ignorePatterns": ["dist"]
205
+ }
176
206
  `,
177
207
  };
178
- function renderPackageJson(projectName) {
179
- const content = PROJECT_FILES["package.json"];
180
- return content.replace('"name": "express-api"', `"name": "${projectName}"`);
208
+ const DOCKER_FILES = {
209
+ Dockerfile: `FROM node:22-alpine
210
+ WORKDIR /app
211
+ COPY package*.json ./
212
+ RUN npm install
213
+ COPY . .
214
+ RUN npm run build
215
+ EXPOSE 3000
216
+ CMD ["npm", "start"]
217
+ `,
218
+ "docker-compose.yml": `services:
219
+ api:
220
+ build: .
221
+ ports:
222
+ - "3000:3000"
223
+ env_file:
224
+ - .env
225
+ `,
226
+ };
227
+ function renderPackageJson(projectName, options) {
228
+ let content = PROJECT_FILES["package.json"].replace('"name": "express-api"', `"name": "${projectName}"`);
229
+ if (options.withEslint) {
230
+ content = content.replace(`"typescript": "^5.5.4"\n }`, `"typescript": "^5.5.4",\n "@typescript-eslint/eslint-plugin": "^8.3.0",\n "@typescript-eslint/parser": "^8.3.0",\n "eslint": "^8.57.0"\n }`);
231
+ }
232
+ if (!options.withEslint) {
233
+ content = content.replace(` "lint": "eslint src --ext .ts"\n`, "");
234
+ }
235
+ return content;
181
236
  }
182
- function writeProjectFiles(targetDir, projectName) {
183
- if ((0, fs_1.existsSync)((0, path_1.join)(targetDir, "package.json"))) {
237
+ function writeProjectFiles(targetDir, projectName, options) {
238
+ if ((0, fs_1.existsSync)((0, path_1.join)(targetDir, "package.json")) && !options.force) {
184
239
  throw new Error(`Directory already contains package.json: ${targetDir}`);
185
240
  }
186
- if (!(0, fs_1.existsSync)(targetDir)) {
187
- (0, fs_1.mkdirSync)(targetDir, { recursive: true });
188
- }
189
- (0, fs_1.mkdirSync)((0, path_1.join)(targetDir, "src", "api"), { recursive: true });
190
- (0, fs_1.mkdirSync)((0, path_1.join)(targetDir, "src", "middlewares"), { recursive: true });
191
- (0, fs_1.mkdirSync)((0, path_1.join)(targetDir, "src", "utils"), { recursive: true });
192
- (0, fs_1.mkdirSync)((0, path_1.join)(targetDir, "src", "types"), { recursive: true });
241
+ (0, io_1.ensureDir)(targetDir, options);
242
+ (0, io_1.ensureDir)((0, path_1.join)(targetDir, "src", "api"), options);
243
+ (0, io_1.ensureDir)((0, path_1.join)(targetDir, "src", "middlewares"), options);
244
+ (0, io_1.ensureDir)((0, path_1.join)(targetDir, "src", "utils"), options);
245
+ (0, io_1.ensureDir)((0, path_1.join)(targetDir, "src", "types"), options);
193
246
  const written = [];
247
+ const io = { dryRun: options.dryRun, force: options.force };
194
248
  for (const [relativePath, content] of Object.entries(PROJECT_FILES)) {
195
249
  const filePath = (0, path_1.join)(targetDir, relativePath);
196
- const fileContent = relativePath === "package.json" ? renderPackageJson(projectName) : content;
197
- (0, fs_1.writeFileSync)(filePath, fileContent, "utf-8");
250
+ const fileContent = relativePath === "package.json" ? renderPackageJson(projectName, options) : content;
251
+ (0, io_1.writeTextFile)(filePath, fileContent, io);
198
252
  written.push(filePath);
199
253
  }
254
+ if (options.withEslint) {
255
+ for (const [relativePath, content] of Object.entries(ESLINT_FILES)) {
256
+ const filePath = (0, path_1.join)(targetDir, relativePath);
257
+ (0, io_1.writeTextFile)(filePath, content, io);
258
+ written.push(filePath);
259
+ }
260
+ }
261
+ if (options.withDocker) {
262
+ for (const [relativePath, content] of Object.entries(DOCKER_FILES)) {
263
+ const filePath = (0, path_1.join)(targetDir, relativePath);
264
+ (0, io_1.writeTextFile)(filePath, content, io);
265
+ written.push(filePath);
266
+ }
267
+ }
200
268
  const configPath = (0, path_1.join)(targetDir, ".bogorc.json");
201
- (0, fs_1.writeFileSync)(configPath, (0, config_1.getDefaultConfigContent)(), "utf-8");
269
+ (0, io_1.writeTextFile)(configPath, (0, config_1.getDefaultConfigContent)(), io);
202
270
  written.push(configPath);
203
271
  return written;
204
272
  }
@@ -1 +1 @@
1
- {"version":3,"file":"project.js","sourceRoot":"","sources":["../../src/templates/project.ts"],"names":[],"mappings":";;AAqLA,8CA4BC;AAjND,2BAA0D;AAC1D,+BAA4B;AAC5B,4CAA0D;AAE1D,MAAM,aAAa,GA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AAO,CAAC,YAAY,CAAC,EAAE,CAAC;YACnE,MAAM,QAAQ,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,YAAY,CAAC,CAAC;YAC/C,IAAA,kBAAa,EAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;YACrC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IAED,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;QACvB,KAAK,MAAM,CAAC,YAAY,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;YACnE,MAAM,QAAQ,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,YAAY,CAAC,CAAC;YAC/C,IAAA,kBAAa,EAAC,QAAQ,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;YACrC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IAED,MAAM,UAAU,GAAG,IAAA,WAAI,EAAC,SAAS,EAAE,cAAc,CAAC,CAAC;IACnD,IAAA,kBAAa,EAAC,UAAU,EAAE,IAAA,gCAAuB,GAAE,EAAE,EAAE,CAAC,CAAC;IACzD,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAEzB,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { MethodSpec, ModuleNames, ModuleTemplateContext } from "../interfaces";
2
+ export declare function renderControllerMethod(names: ModuleNames, method: MethodSpec): string;
3
+ export declare function renderServiceMethod(names: ModuleNames, method: MethodSpec): string;
4
+ export declare function renderDtoBlock(method: MethodSpec): string;
5
+ export declare function renderValidatorBlock(method: MethodSpec): string;
6
+ export declare function renderRouteLine(method: MethodSpec, middleware: string[]): string;
7
+ export declare function renderMiddlewareImports(middleware: string[]): string;
8
+ export declare function applyTemplate(template: string, ctx: ModuleTemplateContext, part: string): string;
9
+ //# sourceMappingURL=render-helpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render-helpers.d.ts","sourceRoot":"","sources":["../../src/templates/render-helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAI/E,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,GAAG,MAAM,CAcrF;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,UAAU,GAAG,MAAM,CAKlF;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAOzD;AAED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,UAAU,GAAG,MAAM,CAO/D;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,GAAG,MAAM,CAIhF;AAED,wBAAgB,uBAAuB,CAAC,UAAU,EAAE,MAAM,EAAE,GAAG,MAAM,CAMpE;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,qBAAqB,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAmBhG"}
@@ -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,CAAC,KAAkB,EAAE,MAAkB;IAC3E,OAAO;UACC,MAAM,CAAC,IAAI;;6BAEQ,KAAK,CAAC,MAAM,WAAW,MAAM,CAAC,IAAI;;;;;;;;;IAS3D,CAAC;AACL,CAAC;AAED,SAAgB,mBAAmB,CAAC,KAAkB,EAAE,MAAkB;IACxE,OAAO;UACC,MAAM,CAAC,IAAI,SAAS,MAAM,CAAC,IAAI;uBAClB,KAAK,CAAC,MAAM,WAAW,MAAM,CAAC,IAAI;IACrD,CAAC;AACL,CAAC;AAED,SAAgB,cAAc,CAAC,MAAkB;IAC/C,OAAO,oBAAoB,MAAM,CAAC,IAAI;;;;;CAKvC,CAAC;AACF,CAAC;AAED,SAAgB,oBAAoB,CAAC,MAAkB;IACrD,OAAO,gBAAgB,MAAM,CAAC,IAAI;;;;;CAKnC,CAAC;AACF,CAAC;AAED,SAAgB,eAAe,CAAC,MAAkB,EAAE,UAAoB;IACtE,MAAM,SAAS,GAAG,IAAA,0BAAiB,EAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,CAAC,CAAC;IAC/D,MAAM,KAAK,GAAG,CAAC,GAAG,UAAU,EAAE,YAAY,MAAM,CAAC,IAAI,GAAG,EAAE,+CAA+C,MAAM,CAAC,IAAI,YAAY,CAAC,CAAC;IAClI,OAAO,UAAU,I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CAAC,IAAI,CAAC,CAAC;SACnE,UAAU,CAAC,qBAAqB,EAAE,OAAO,CAAC,GAAG,CAAC,oBAAoB,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SAC/E,UAAU,CAAC,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,eAAe,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SAC/F,UAAU,CAAC,sBAAsB,EAAE,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,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,CAclD;AAED,wBAAgB,uBAAuB,IAAI,MAAM,CAEhD"}
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"}
@@ -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
- return {
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`;
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/utils/config.ts"],"names":[],"mappings":";;AAUA,gCAcC;AAED,0DAEC;AA5BD,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,cAAc,CAAC;IACxB,CAAC;IAED,MAAM,GAAG,GAAG,IAAA,iBAAY,EAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IAC9C,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAwB,CAAC;IAEtD,OAAO;QACL,GAAG,cAAc;QACjB,GAAG,MAAM;KACV,CAAC;AACJ,CAAC;AAED,SAAgB,uBAAuB;IACrC,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC;AACxD,CAAC"}
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"}
@@ -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,4 @@
1
+ import { MethodSpec } from "../interfaces";
2
+ export declare function parseMethodSpec(raw: string): MethodSpec;
3
+ export declare function methodExistsInContent(content: string, methodName: string, part: string): boolean;
4
+ //# sourceMappingURL=method-spec.d.ts.map
@@ -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,SAAgB,eAAe,CAAC,GAAW;IACzC,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAC;IA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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"}
@@ -1,5 +1,9 @@
1
- import { ModuleNames } from "../interfaces";
2
- export declare function patchIndexFile(indexPath: string, names: ModuleNames, routePrefix: string): boolean;
3
- export declare function suggestIndexPatch(names: ModuleNames, routePrefix: string): string;
4
- export declare function unpatchIndexFile(indexPath: string, names: ModuleNames, routePrefix: string): boolean;
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;
5
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;AAE5C,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAiDlG;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAKjF;AAED,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,GAAG,OAAO,CAiBpG"}
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"}
@@ -4,69 +4,74 @@ exports.patchIndexFile = patchIndexFile;
4
4
  exports.suggestIndexPatch = suggestIndexPatch;
5
5
  exports.unpatchIndexFile = unpatchIndexFile;
6
6
  const fs_1 = require("fs");
7
- function patchIndexFile(indexPath, names, routePrefix) {
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);
8
11
  if (!(0, fs_1.existsSync)(indexPath)) {
9
12
  return false;
10
13
  }
11
- const importLine = `import ${names.pascal}Routes from "./api/${names.kebab}/${names.kebab}.routes";`;
12
- 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);
13
15
  let content = (0, fs_1.readFileSync)(indexPath, "utf-8");
14
16
  if (content.includes(importLine) || content.includes(useLine)) {
15
17
  return false;
16
18
  }
17
- const importAnchor = content.match(/^import .+ from .+;$/m);
18
- if (importAnchor && importAnchor.index !== undefined) {
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;
24
- }
25
- }
26
- if (lastImportIndex >= 0) {
27
- lines.splice(lastImportIndex + 1, 0, importLine);
28
- content = lines.join("\n");
29
- }
30
- else {
31
- 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;
32
24
  }
33
25
  }
26
+ if (lastImportIndex >= 0) {
27
+ lines.splice(lastImportIndex + 1, 0, importLine);
28
+ }
34
29
  else {
35
- content = `${importLine}\n${content}`;
30
+ lines.unshift(importLine);
36
31
  }
37
- const useAnchor = content.match(/app\.use\("\/api\/.+", .+Routes\);/);
38
- if (useAnchor && useAnchor.index !== undefined) {
32
+ content = lines.join("\n");
33
+ const useAnchor = content.match(/app\.use\("[^"]+", .+Routes\);/);
34
+ if (useAnchor) {
39
35
  content = content.replace(useAnchor[0], `${useAnchor[0]}\n${useLine}`);
40
36
  }
41
37
  else {
42
38
  const listenAnchor = content.match(/app\.listen\(/);
43
- if (listenAnchor && listenAnchor.index !== undefined) {
39
+ if (listenAnchor) {
44
40
  content = content.replace(listenAnchor[0], `${useLine}\n\n${listenAnchor[0]}`);
45
41
  }
46
42
  else {
47
43
  content = `${content.trimEnd()}\n${useLine}\n`;
48
44
  }
49
45
  }
46
+ if (options.dryRun) {
47
+ console.log(`[dry-run] patch ${indexPath}`);
48
+ return true;
49
+ }
50
50
  (0, fs_1.writeFileSync)(indexPath, content, "utf-8");
51
51
  return true;
52
52
  }
53
- function suggestIndexPatch(names, routePrefix) {
53
+ function suggestIndexPatch(config, names) {
54
+ const { importLine, useLine } = (0, index_path_1.buildIndexLines)(config.indexFile, config.apiDir, names, config.routePrefix);
54
55
  return `Add to index manually:
55
56
 
56
- import ${names.pascal}Routes from "./api/${names.kebab}/${names.kebab}.routes";
57
- app.use("${routePrefix}/${names.kebab}", ${names.pascal}Routes);`;
57
+ ${importLine}
58
+ ${useLine}`;
58
59
  }
59
- function unpatchIndexFile(indexPath, names, routePrefix) {
60
+ function unpatchIndexFile(cwd, config, names, options = {}) {
61
+ const indexPath = (0, path_1.join)(cwd, config.indexFile);
60
62
  if (!(0, fs_1.existsSync)(indexPath)) {
61
63
  return false;
62
64
  }
63
- const importLine = `import ${names.pascal}Routes from "./api/${names.kebab}/${names.kebab}.routes";`;
64
- const useLine = `app.use("${routePrefix}/${names.kebab}", ${names.pascal}Routes);`;
65
+ const { importLine, useLine } = (0, index_path_1.buildIndexLines)(config.indexFile, config.apiDir, names, config.routePrefix);
65
66
  const lines = (0, fs_1.readFileSync)(indexPath, "utf-8").split("\n");
66
67
  const filtered = lines.filter(line => line !== importLine && line !== useLine);
67
68
  if (filtered.length === lines.length) {
68
69
  return false;
69
70
  }
71
+ if (options.dryRun) {
72
+ console.log(`[dry-run] unpatch ${indexPath}`);
73
+ return true;
74
+ }
70
75
  (0, fs_1.writeFileSync)(indexPath, filtered.join("\n"), "utf-8");
71
76
  return true;
72
77
  }