@expressots/cli 1.5.0 → 1.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/bin/@types/config.d.ts +9 -0
  2. package/bin/app.container.js +4 -5
  3. package/bin/cli.d.ts +1 -1
  4. package/bin/cli.js +4 -2
  5. package/bin/commands/project.commands.d.ts +8 -0
  6. package/bin/commands/project.commands.js +136 -0
  7. package/bin/generate/cli.js +5 -2
  8. package/bin/generate/form.d.ts +13 -0
  9. package/bin/generate/form.js +17 -374
  10. package/bin/generate/templates/nonopinionated/controller.tpl +10 -0
  11. package/bin/generate/templates/nonopinionated/dto.tpl +3 -0
  12. package/bin/generate/templates/nonopinionated/entity.tpl +4 -0
  13. package/bin/generate/templates/nonopinionated/middleware.tpl +10 -0
  14. package/bin/generate/templates/nonopinionated/module.tpl +4 -0
  15. package/bin/generate/templates/nonopinionated/provider.tpl +4 -0
  16. package/bin/generate/templates/nonopinionated/usecase.tpl +8 -0
  17. package/bin/generate/templates/{controller-service-delete.tpl → opinionated/controller-service-delete.tpl} +2 -2
  18. package/bin/generate/templates/{controller-service.tpl → opinionated/controller-service-get.tpl} +2 -2
  19. package/bin/generate/templates/{controller-service-patch.tpl → opinionated/controller-service-patch.tpl} +2 -2
  20. package/bin/generate/templates/{controller-service-post.tpl → opinionated/controller-service-post.tpl} +2 -2
  21. package/bin/generate/templates/{controller-service-put.tpl → opinionated/controller-service-put.tpl} +2 -2
  22. package/bin/generate/templates/{entity.tpl → opinionated/entity.tpl} +2 -2
  23. package/bin/generate/templates/opinionated/middleware.tpl +10 -0
  24. package/bin/generate/templates/opinionated/module-service.tpl +5 -0
  25. package/bin/generate/templates/opinionated/module.tpl +4 -0
  26. package/bin/generate/templates/opinionated/usecase-service-delete.tpl +8 -0
  27. package/bin/generate/utils/command-utils.d.ts +123 -0
  28. package/bin/generate/utils/command-utils.js +310 -0
  29. package/bin/generate/utils/nonopininated-cmd.d.ts +9 -0
  30. package/bin/generate/utils/nonopininated-cmd.js +248 -0
  31. package/bin/generate/utils/opinionated-cmd.d.ts +11 -0
  32. package/bin/generate/utils/opinionated-cmd.js +480 -0
  33. package/bin/help/cli.d.ts +4 -0
  34. package/bin/help/cli.js +15 -0
  35. package/bin/help/form.d.ts +2 -0
  36. package/bin/help/form.js +28 -0
  37. package/bin/help/index.d.ts +1 -0
  38. package/bin/help/index.js +2 -0
  39. package/bin/info/form.d.ts +1 -1
  40. package/bin/info/form.js +8 -11
  41. package/bin/new/cli.d.ts +1 -1
  42. package/bin/new/cli.js +33 -31
  43. package/bin/new/form.js +7 -5
  44. package/bin/utils/add-controller-to-module.d.ts +1 -2
  45. package/bin/utils/add-module-to-container.d.ts +2 -1
  46. package/bin/utils/add-module-to-container.js +37 -4
  47. package/bin/utils/cli-ui.d.ts +2 -0
  48. package/bin/utils/cli-ui.js +10 -2
  49. package/bin/utils/verify-file-exists.d.ts +1 -1
  50. package/bin/utils/verify-file-exists.js +6 -4
  51. package/package.json +5 -2
  52. package/bin/generate/templates/dto-op.tpl +0 -7
  53. package/bin/generate/templates/module-default.tpl +0 -3
  54. package/bin/generate/templates/module.tpl +0 -4
  55. package/bin/generate/templates/usecase-post.tpl +0 -9
  56. /package/bin/generate/templates/{controller.tpl → opinionated/controller-service.tpl} +0 -0
  57. /package/bin/generate/templates/{dto.tpl → opinionated/dto.tpl} +0 -0
  58. /package/bin/generate/templates/{provider.tpl → opinionated/provider.tpl} +0 -0
  59. /package/bin/generate/templates/{usecase-op.tpl → opinionated/usecase-service.tpl} +0 -0
  60. /package/bin/generate/templates/{usecase.tpl → opinionated/usecase.tpl} +0 -0
@@ -26,5 +26,14 @@ export interface ExpressoConfig {
26
26
  sourceRoot: string;
27
27
  opinionated: boolean;
28
28
  providers?: IProviders;
29
+ scaffoldSchematics?: {
30
+ entity?: string;
31
+ controller?: string;
32
+ usecase?: string;
33
+ dto?: string;
34
+ module?: string;
35
+ provider?: string;
36
+ middleware?: string;
37
+ };
29
38
  }
30
39
  export {};
@@ -1,9 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- //import { AppContainer } from "@expressots/core";
4
- /*
5
- const appContainer = new AppContainer();
3
+ /* import { AppContainer } from "@expressots/core";
6
4
 
7
- const container = appContainer.create([// Add your modules here, UserModule, UserModule, UserModule]);
5
+ export const appContainer = new AppContainer();
8
6
 
9
- export { container };*/
7
+ export const container = appContainer.create([]);
8
+ */
package/bin/cli.d.ts CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- export declare const CLI_VERSION = "1.3.4";
2
+ export {};
package/bin/cli.js CHANGED
@@ -4,21 +4,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  return (mod && mod.__esModule) ? mod : { "default": mod };
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.CLI_VERSION = void 0;
8
7
  const yargs_1 = __importDefault(require("yargs"));
9
8
  const helpers_1 = require("yargs/helpers");
9
+ const project_commands_1 = require("./commands/project.commands");
10
10
  const generate_1 = require("./generate");
11
+ const cli_1 = require("./help/cli");
11
12
  const info_1 = require("./info");
12
13
  const new_1 = require("./new");
13
14
  const providers_1 = require("./providers");
14
- exports.CLI_VERSION = "1.3.4";
15
15
  console.log(`\n[🐎 Expressots]\n`);
16
16
  (0, yargs_1.default)((0, helpers_1.hideBin)(process.argv))
17
17
  .scriptName("expressots")
18
+ .command(project_commands_1.runCommandModule)
18
19
  .command((0, new_1.createProject)())
19
20
  .command((0, providers_1.generateProviders)())
20
21
  .command((0, generate_1.generateProject)())
21
22
  .command((0, info_1.infoProject)())
23
+ .command((0, cli_1.helpCommand)())
22
24
  .example("$0 new expressots-demo", "Create interactively")
23
25
  .example("$0 new expressots-demo -d ./", "Create interactively with path")
24
26
  .example("$0 new expressots-demo -p yarn -t opinionated", "Create silently")
@@ -0,0 +1,8 @@
1
+ import { CommandModule } from "yargs";
2
+ export declare const runCommandModule: CommandModule<{}, {
3
+ command: string;
4
+ }>;
5
+ declare const runCommand: ({ command }: {
6
+ command: string;
7
+ }) => Promise<void>;
8
+ export { runCommand };
@@ -0,0 +1,136 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.runCommand = exports.runCommandModule = void 0;
7
+ const child_process_1 = require("child_process");
8
+ const fs_1 = require("fs");
9
+ const path_1 = __importDefault(require("path"));
10
+ const compiler_1 = __importDefault(require("../utils/compiler"));
11
+ /**
12
+ * Load the configuration from the compiler
13
+ * @param compiler The compiler to load the configuration from
14
+ * @returns The configuration
15
+ */
16
+ const opinionatedConfig = [
17
+ "--transpile-only",
18
+ "-r",
19
+ "dotenv/config",
20
+ "-r",
21
+ "tsconfig-paths/register",
22
+ "./src/main.ts",
23
+ ];
24
+ const nonOpinionatedConfig = [
25
+ "--transpile-only",
26
+ "-r",
27
+ "dotenv/config",
28
+ "./src/main.ts",
29
+ ];
30
+ /**
31
+ * Helper function to execute a command
32
+ * @param command The command to execute
33
+ * @param args The arguments to pass to the command
34
+ * @param cwd The current working directory to execute the command in
35
+ * @returns A promise that resolves when the command completes successfully
36
+ */
37
+ function execCmd(command, args, cwd = process.cwd()) {
38
+ return new Promise((resolve, reject) => {
39
+ const proc = (0, child_process_1.spawn)(command, args, {
40
+ stdio: "inherit",
41
+ shell: true,
42
+ cwd,
43
+ });
44
+ proc.on("close", (code) => {
45
+ if (code === 0) {
46
+ resolve();
47
+ }
48
+ else {
49
+ reject(new Error(`Command failed with code ${code}`));
50
+ }
51
+ });
52
+ });
53
+ }
54
+ // Helper to delete the dist directory
55
+ const cleanDist = async () => {
56
+ await fs_1.promises.rm("./dist", { recursive: true, force: true });
57
+ };
58
+ // Helper to compile TypeScript
59
+ const compileTypescript = async () => {
60
+ await execCmd("npx", ["tsc", "-p", "tsconfig.build.json"]);
61
+ };
62
+ // Helper to copy files
63
+ const copyFiles = async () => {
64
+ const { opinionated } = await compiler_1.default.loadConfig();
65
+ let filesToCopy = [];
66
+ if (opinionated) {
67
+ filesToCopy = [
68
+ "./register-path.js",
69
+ "tsconfig.build.json",
70
+ "package.json",
71
+ ];
72
+ }
73
+ else {
74
+ filesToCopy = ["tsconfig.json", "package.json"];
75
+ }
76
+ filesToCopy.forEach((file) => {
77
+ fs_1.promises.copyFile(file, path_1.default.join("./dist", path_1.default.basename(file)));
78
+ });
79
+ };
80
+ // eslint-disable-next-line @typescript-eslint/ban-types
81
+ exports.runCommandModule = {
82
+ command: "run <command>",
83
+ describe: "Runs a specified command (dev, build, prod)",
84
+ builder: (yargs) => {
85
+ return yargs.positional("command", {
86
+ describe: "The command to run",
87
+ type: "string",
88
+ choices: ["dev", "build", "prod"],
89
+ });
90
+ },
91
+ handler: async (argv) => {
92
+ const { command } = argv;
93
+ // Now call your original runCommand function with the command
94
+ // Ensure runCommand is properly defined to handle these commands
95
+ await runCommand({ command });
96
+ },
97
+ };
98
+ const runCommand = async ({ command }) => {
99
+ const { opinionated } = await compiler_1.default.loadConfig();
100
+ try {
101
+ switch (command) {
102
+ case "dev":
103
+ // Use execSync or spawn to run ts-node-dev programmatically
104
+ execCmd("tsnd", opinionated ? opinionatedConfig : nonOpinionatedConfig);
105
+ break;
106
+ case "build":
107
+ await cleanDist();
108
+ await compileTypescript();
109
+ await copyFiles();
110
+ break;
111
+ case "prod":
112
+ let config = [];
113
+ if (opinionated) {
114
+ config = [
115
+ "-r",
116
+ "dotenv/config",
117
+ "-r",
118
+ "./dist/register-path.js",
119
+ "./dist/src/main.js",
120
+ ];
121
+ }
122
+ else {
123
+ config = ["-r", "dotenv/config", "./dist/main.js"];
124
+ }
125
+ // Ensure environment variables are set
126
+ execCmd("node", config);
127
+ break;
128
+ default:
129
+ console.log(`Unknown command: ${command}`);
130
+ }
131
+ }
132
+ catch (error) {
133
+ console.error("Error executing command:", error);
134
+ }
135
+ };
136
+ exports.runCommand = runCommand;
@@ -16,15 +16,17 @@ const coerceSchematicAliases = (arg) => {
16
16
  return "provider";
17
17
  case "e":
18
18
  return "entity";
19
- case "m":
19
+ case "mo":
20
20
  return "module";
21
+ case "mi":
22
+ return "middleware";
21
23
  default:
22
24
  return arg;
23
25
  }
24
26
  };
25
27
  const generateProject = () => {
26
28
  return {
27
- command: "generate [schematic] [path]",
29
+ command: "generate [schematic] [path] [method]",
28
30
  describe: "Scaffold a new resource",
29
31
  aliases: ["g"],
30
32
  builder: (yargs) => {
@@ -37,6 +39,7 @@ const generateProject = () => {
37
39
  "provider",
38
40
  "entity",
39
41
  "module",
42
+ "middleware",
40
43
  ],
41
44
  describe: "The schematic to generate",
42
45
  type: "string",
@@ -1,7 +1,20 @@
1
+ /**
2
+ * Create a template props
3
+ * @param schematic
4
+ * @param path
5
+ * @param method
6
+ */
1
7
  type CreateTemplateProps = {
2
8
  schematic: string;
3
9
  path: string;
4
10
  method: string;
5
11
  };
12
+ /**
13
+ * Create a template based on the schematic
14
+ * @param schematic - the schematic to create
15
+ * @param path - the path to create the schematic
16
+ * @param method - the http method
17
+ * @returns the file created
18
+ */
6
19
  export declare const createTemplate: ({ schematic, path: target, method, }: CreateTemplateProps) => Promise<string>;
7
20
  export {};
@@ -1,387 +1,30 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __asyncValues = (this && this.__asyncValues) || function (o) {
26
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
27
- var m = o[Symbol.asyncIterator], i;
28
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
29
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
30
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
31
- };
32
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
33
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
34
4
  };
35
5
  Object.defineProperty(exports, "__esModule", { value: true });
36
6
  exports.createTemplate = void 0;
37
- const nodePath = __importStar(require("path"));
38
- const node_fs_1 = require("node:fs");
39
- const mustache_1 = require("mustache");
40
- const fs_1 = require("fs");
41
- const chalk_1 = __importDefault(require("chalk"));
42
- const boost_ts_1 = require("@expressots/boost-ts");
43
7
  const compiler_1 = __importDefault(require("../utils/compiler"));
44
- const add_controller_to_module_1 = require("../utils/add-controller-to-module");
45
- const verify_file_exists_1 = require("../utils/verify-file-exists");
46
- const add_module_to_container_1 = require("../utils/add-module-to-container");
47
- const cli_ui_1 = require("../utils/cli-ui");
48
- function getFileNameWithoutExtension(filePath) {
49
- return filePath.split(".")[0];
50
- }
8
+ const command_utils_1 = require("./utils/command-utils");
9
+ const nonopininated_cmd_1 = require("./utils/nonopininated-cmd");
10
+ const opinionated_cmd_1 = require("./utils/opinionated-cmd");
11
+ /**
12
+ * Create a template based on the schematic
13
+ * @param schematic - the schematic to create
14
+ * @param path - the path to create the schematic
15
+ * @param method - the http method
16
+ * @returns the file created
17
+ */
51
18
  const createTemplate = async ({ schematic, path: target, method, }) => {
52
- var _a, e_1, _b, _c;
53
- const { opinionated, sourceRoot } = await compiler_1.default.loadConfig();
54
- if (sourceRoot === "") {
55
- (0, cli_ui_1.printError)("You must specify a source root in your expressots.config.ts", "sourceRoot");
56
- process.exit(1);
57
- }
58
- let folderMatch = "";
59
- if (opinionated) {
60
- folderMatch = schematicFolder(schematic);
61
- }
62
- else {
63
- folderMatch = "";
64
- }
65
- const { path, file, className, moduleName, modulePath } = await splitTarget({ target, schematic });
66
- const usecaseDir = `${sourceRoot}/${folderMatch}`;
67
- await (0, verify_file_exists_1.verifyIfFileExists)(`${usecaseDir}/${path}/${file}`);
68
- (0, node_fs_1.mkdirSync)(`${usecaseDir}/${path}`, { recursive: true });
69
- if (schematic !== "service") {
70
- // add to guarantee that the routing will always be the last part of the path
71
- let routeSchema = "";
72
- if (target.includes("/") ||
73
- target.includes("\\") ||
74
- target.includes("//")) {
75
- routeSchema = path.split("/").pop();
76
- }
77
- else {
78
- routeSchema = path.replace(/\/$/, "");
79
- }
80
- let templateBasedSchematic = schematic;
81
- if (schematic === "module") {
82
- templateBasedSchematic = "module-default";
83
- }
84
- writeTemplate({
85
- outputPath: `${usecaseDir}/${path}/${file}`,
86
- template: {
87
- path: `./templates/${templateBasedSchematic}.tpl`,
88
- data: {
89
- className,
90
- moduleName: className,
91
- route: routeSchema,
92
- construct: (0, boost_ts_1.anyCaseToKebabCase)(className),
93
- method: getHttpMethod(method),
94
- },
95
- },
96
- });
97
- }
98
- else {
99
- try {
100
- for (var _d = true, _e = __asyncValues(["controller-service", "usecase", "dto"]), _f; _f = await _e.next(), _a = _f.done, !_a;) {
101
- _c = _f.value;
102
- _d = false;
103
- try {
104
- const resource = _c;
105
- const currentSchematic = resource.replace("controller-service", "controller");
106
- const schematicFile = file.replace(`controller.ts`, `${currentSchematic}.ts`);
107
- console.log(" ", chalk_1.default.greenBright(`[${currentSchematic}]`.padEnd(14)), chalk_1.default.bold.white(`${schematicFile} created! ✔️`));
108
- let templateBasedMethod = "";
109
- if (method) {
110
- if (resource === "controller-service" ||
111
- resource === "controller") {
112
- if (method === "get")
113
- templateBasedMethod = `./templates/${resource}.tpl`;
114
- else
115
- templateBasedMethod = `./templates/${resource}-${method}.tpl`;
116
- }
117
- else {
118
- templateBasedMethod = `./templates/${resource}.tpl`;
119
- }
120
- if (resource === "usecase") {
121
- templateBasedMethod = `./templates/${resource}-op.tpl`;
122
- }
123
- if (resource === "usecase") {
124
- if (method === "get")
125
- templateBasedMethod = `./templates/${resource}.tpl`;
126
- if (method === "post")
127
- templateBasedMethod = `./templates/${resource}-${method}.tpl`;
128
- }
129
- }
130
- else {
131
- templateBasedMethod = `./templates/${resource}.tpl`;
132
- }
133
- // add to guarantee that the routing will always be the last part of the path
134
- let routeSchema = "";
135
- if (target.includes("/") ||
136
- target.includes("\\") ||
137
- target.includes("//")) {
138
- routeSchema = path.split("/").pop();
139
- }
140
- else {
141
- routeSchema = path.replace(/\/$/, "");
142
- }
143
- writeTemplate({
144
- outputPath: `${usecaseDir}/${path}/${schematicFile}`,
145
- template: {
146
- path: templateBasedMethod,
147
- data: {
148
- className,
149
- fileName: getFileNameWithoutExtension(file),
150
- useCase: (0, boost_ts_1.anyCaseToCamelCase)(className),
151
- route: routeSchema,
152
- construct: (0, boost_ts_1.anyCaseToKebabCase)(className),
153
- method: getHttpMethod(method),
154
- },
155
- },
156
- });
157
- }
158
- finally {
159
- _d = true;
160
- }
161
- }
162
- }
163
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
164
- finally {
165
- try {
166
- if (!_d && !_a && (_b = _e.return)) await _b.call(_e);
167
- }
168
- finally { if (e_1) throw e_1.error; }
169
- }
170
- }
171
- // Module generation
172
- if (["controller", "service"].includes(schematic)) {
173
- let moduleExist = false;
174
- let moduleOutPath = "";
175
- if (target.includes("/") ||
176
- target.includes("\\") ||
177
- target.includes("//")) {
178
- if (modulePath === "") {
179
- moduleExist = (0, fs_1.existsSync)(`${usecaseDir}/${moduleName}.module.ts`);
180
- moduleOutPath = `${usecaseDir}/${moduleName}.module.ts`;
181
- }
182
- else {
183
- moduleExist = (0, fs_1.existsSync)(`${usecaseDir}/${modulePath}/${moduleName}.module.ts`);
184
- moduleOutPath = `${usecaseDir}/${modulePath}/${moduleName}.module.ts`;
185
- }
186
- }
187
- else {
188
- moduleExist = (0, fs_1.existsSync)(`${usecaseDir}/${moduleName}/${moduleName}.module.ts`);
189
- if (modulePath === "") {
190
- moduleExist = (0, fs_1.existsSync)(`${usecaseDir}/${moduleName}.module.ts`);
191
- moduleOutPath = `${usecaseDir}/${moduleName}.module.ts`;
192
- }
193
- else {
194
- moduleExist = (0, fs_1.existsSync)(`${usecaseDir}/${moduleName}/${moduleName}.module.ts`);
195
- moduleOutPath = `${usecaseDir}/${moduleName}/${moduleName}.module.ts`;
196
- }
197
- }
198
- let controllerPath = "./";
199
- const pathCount = path.split("/").length;
200
- if (path === "") {
201
- controllerPath += `${file.slice(0, file.lastIndexOf("."))}`;
202
- }
203
- else if (pathCount === 1) {
204
- controllerPath += `${path}/${file.slice(0, file.lastIndexOf("."))}`;
205
- }
206
- else if (pathCount === 2) {
207
- controllerPath += `${path.split("/")[1]}/${file.slice(0, file.lastIndexOf("."))}`;
208
- }
209
- else {
210
- const segments = path
211
- .split("/")
212
- .filter((segment) => segment !== "");
213
- controllerPath += `${segments[segments.length - 1]}/${file.slice(0, file.lastIndexOf("."))}`;
214
- }
215
- if (moduleExist) {
216
- if (target.includes("/") ||
217
- target.includes("\\") ||
218
- target.includes("//")) {
219
- await (0, add_controller_to_module_1.addControllerToModule)(`${usecaseDir}/${modulePath}/${moduleName}.module.ts`, `${className}Controller`, controllerPath);
220
- }
221
- else {
222
- if (modulePath === "") {
223
- await (0, add_controller_to_module_1.addControllerToModule)(`${usecaseDir}/${moduleName}.module.ts`, `${className}Controller`, controllerPath);
224
- }
225
- else {
226
- await (0, add_controller_to_module_1.addControllerToModule)(`${usecaseDir}/${moduleName}/${moduleName}.module.ts`, `${className}Controller`, controllerPath);
227
- }
228
- }
229
- }
230
- else {
231
- writeTemplate({
232
- outputPath: moduleOutPath,
233
- template: {
234
- path: `./templates/module.tpl`,
235
- data: {
236
- moduleName: moduleName[0].toUpperCase() + moduleName.slice(1),
237
- className,
238
- path: controllerPath,
239
- },
240
- },
241
- });
242
- console.log(" ", chalk_1.default.greenBright(`[module]`.padEnd(14)), chalk_1.default.bold.white(`${moduleName}.module created! ✔️`));
243
- if (target.includes("/") ||
244
- target.includes("\\") ||
245
- target.includes("//")) {
246
- await (0, add_module_to_container_1.addModuleToContainer)(moduleName, modulePath, path);
247
- }
248
- else {
249
- await (0, add_module_to_container_1.addModuleToContainer)(moduleName, moduleName, path);
250
- }
251
- }
252
- }
253
- if (schematic === "service") {
254
- console.log(" ", chalk_1.default.greenBright(`[${schematic}]`.padEnd(14)), chalk_1.default.bold.yellow(`${file.split(".")[0]} created! ✔️`));
19
+ const config = await compiler_1.default.loadConfig();
20
+ const pathStyle = (0, command_utils_1.checkPathStyle)(target);
21
+ let returnFile = "";
22
+ if (config.opinionated) {
23
+ returnFile = await (0, opinionated_cmd_1.opinionatedProcess)(schematic, target, method, config, pathStyle);
255
24
  }
256
25
  else {
257
- console.log(" ", chalk_1.default.greenBright(`[${schematic}]`.padEnd(14)), chalk_1.default.bold.white(`${file.split(".")[0]} ${schematic} created! ✔️`));
26
+ returnFile = await (0, nonopininated_cmd_1.nonOpinionatedProcess)(schematic, target, method, config);
258
27
  }
259
- return file;
28
+ return returnFile;
260
29
  };
261
30
  exports.createTemplate = createTemplate;
262
- const splitTarget = async ({ target, schematic, }) => {
263
- const pathContent = target
264
- .split("/")
265
- .filter((item) => item !== "");
266
- const endsWithSlash = target.endsWith("/");
267
- let path = "";
268
- let fileName = "";
269
- let module = "";
270
- let modulePath = "";
271
- if (target.includes("/") ||
272
- target.includes("\\") ||
273
- target.includes("//")) {
274
- //pathContent = target.split("/").filter((item) => item !== "");
275
- if (schematic === "service")
276
- schematic = "controller";
277
- if (schematic === "service" ||
278
- (schematic === "controller" && pathContent.length > 4)) {
279
- (0, cli_ui_1.printError)("Max path depth is 4.", pathContent.join("/"));
280
- process.exit(1);
281
- }
282
- if (endsWithSlash) {
283
- fileName = pathContent[pathContent.length - 1];
284
- path = pathContent.join("/");
285
- module =
286
- pathContent.length == 1
287
- ? pathContent[pathContent.length - 1]
288
- : pathContent[pathContent.length - 2];
289
- modulePath = pathContent.slice(0, -1).join("/");
290
- }
291
- else {
292
- fileName = pathContent[pathContent.length - 1];
293
- path = pathContent.slice(0, -1).join("/");
294
- module =
295
- pathContent.length == 2
296
- ? pathContent[pathContent.length - 2]
297
- : pathContent[pathContent.length - 3];
298
- modulePath = pathContent.slice(0, -2).join("/");
299
- }
300
- return {
301
- path,
302
- file: `${await getNameWithScaffoldPattern(fileName)}.${schematic}.ts`,
303
- className: (0, boost_ts_1.anyCaseToPascalCase)(fileName),
304
- moduleName: module,
305
- modulePath,
306
- };
307
- }
308
- else {
309
- if (schematic === "service")
310
- schematic = "controller";
311
- // 1. Extract the name (first part of the target)
312
- const [name, ...remainingPath] = target.split("/");
313
- // 2. Check if the name is camelCase or kebab-case
314
- const camelCaseRegex = /[A-Z]/;
315
- const kebabCaseRegex = /[_\-\s]+/;
316
- const isCamelCase = camelCaseRegex.test(name);
317
- const isKebabCase = kebabCaseRegex.test(name);
318
- if (isCamelCase || isKebabCase) {
319
- const [wordName, ...path] = name === null || name === void 0 ? void 0 : name.split(isCamelCase ? /(?=[A-Z])/ : kebabCaseRegex).map((word) => word.toLowerCase());
320
- return {
321
- path: `${wordName}/${pathEdgeCase(path)}${pathEdgeCase(remainingPath)}`,
322
- file: `${await getNameWithScaffoldPattern(name)}.${schematic}.ts`,
323
- className: (0, boost_ts_1.anyCaseToPascalCase)(name),
324
- moduleName: wordName,
325
- modulePath: pathContent[0].split("-")[1],
326
- };
327
- }
328
- // 3. Return the base case
329
- return {
330
- path: "",
331
- file: `${await getNameWithScaffoldPattern(name)}.${schematic}.ts`,
332
- className: (0, boost_ts_1.anyCaseToPascalCase)(name),
333
- moduleName: name,
334
- modulePath: "",
335
- };
336
- }
337
- };
338
- const getHttpMethod = (method) => {
339
- switch (method) {
340
- case "put":
341
- return "Put";
342
- case "post":
343
- return "Post";
344
- case "patch":
345
- return "Patch";
346
- case "delete":
347
- return "Delete";
348
- default:
349
- return "Get";
350
- }
351
- };
352
- const writeTemplate = ({ outputPath, template: { path, data }, }) => {
353
- (0, fs_1.writeFileSync)(outputPath, (0, mustache_1.render)((0, node_fs_1.readFileSync)(nodePath.join(__dirname, path), "utf8"), data));
354
- };
355
- const schematicFolder = (schematic) => {
356
- switch (schematic) {
357
- case "usecase":
358
- return "useCases";
359
- case "controller":
360
- return "useCases";
361
- case "dto":
362
- return "useCases";
363
- case "service":
364
- return "useCases";
365
- case "provider":
366
- return "providers";
367
- case "entity":
368
- return "entities";
369
- }
370
- return undefined;
371
- };
372
- const getNameWithScaffoldPattern = async (name) => {
373
- const configObject = await compiler_1.default.loadConfig();
374
- switch (configObject.scaffoldPattern) {
375
- case "lowercase" /* Pattern.LOWER_CASE */:
376
- return (0, boost_ts_1.anyCaseToLowerCase)(name);
377
- case "kebab-case" /* Pattern.KEBAB_CASE */:
378
- return (0, boost_ts_1.anyCaseToKebabCase)(name);
379
- case "PascalCase" /* Pattern.PASCAL_CASE */:
380
- return (0, boost_ts_1.anyCaseToPascalCase)(name);
381
- case "camelCase" /* Pattern.CAMEL_CASE */:
382
- return (0, boost_ts_1.anyCaseToCamelCase)(name);
383
- }
384
- };
385
- const pathEdgeCase = (path) => {
386
- return `${path.join("/")}${path.length > 0 ? "/" : ""}`;
387
- };
@@ -0,0 +1,10 @@
1
+ import { BaseController } from "@expressots/core";
2
+ import { controller, {{method}} } from "@expressots/adapter-express";
3
+
4
+ @controller("/{{{route}}}")
5
+ export class {{className}}{{schematic}} {
6
+ @{{method}}("/")
7
+ execute() {
8
+ return "{{schematic}}";
9
+ }
10
+ }
@@ -0,0 +1,3 @@
1
+ export interface I{{className}}Request{{schematic}} {}
2
+
3
+ export interface I{{className}}Response{{schematic}} {}