@nest-extended/cli 0.0.1-beta-3 → 0.0.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 (57) hide show
  1. package/README.md +45 -4
  2. package/package.json +17 -25
  3. package/src/commands/generate.d.ts +2 -0
  4. package/src/commands/generate.js +39 -0
  5. package/src/commands/generate.js.map +1 -0
  6. package/src/index.d.ts +2 -0
  7. package/src/index.js +13 -0
  8. package/src/index.js.map +1 -0
  9. package/src/lib/create-file.d.ts +1 -0
  10. package/src/lib/create-file.js +26 -0
  11. package/src/lib/create-file.js.map +1 -0
  12. package/src/lib/update-app-module.d.ts +1 -0
  13. package/src/lib/update-app-module.js +106 -0
  14. package/src/lib/update-app-module.js.map +1 -0
  15. package/src/templates/controller.spec.template.d.ts +1 -0
  16. package/src/templates/controller.spec.template.js +24 -0
  17. package/src/templates/controller.spec.template.js.map +1 -0
  18. package/src/templates/controller.template.d.ts +1 -0
  19. package/src/templates/controller.template.js +56 -0
  20. package/src/templates/controller.template.js.map +1 -0
  21. package/src/templates/dto.template.d.ts +1 -0
  22. package/src/templates/dto.template.js +59 -0
  23. package/src/templates/dto.template.js.map +1 -0
  24. package/src/templates/module.template.d.ts +1 -0
  25. package/src/templates/module.template.js +23 -0
  26. package/src/templates/module.template.js.map +1 -0
  27. package/src/templates/schema.template.d.ts +1 -0
  28. package/src/templates/schema.template.js +56 -0
  29. package/src/templates/schema.template.js.map +1 -0
  30. package/src/templates/service.spec.template.d.ts +1 -0
  31. package/src/templates/service.spec.template.js +24 -0
  32. package/src/templates/service.spec.template.js.map +1 -0
  33. package/src/templates/service.template.d.ts +1 -0
  34. package/src/templates/service.template.js +19 -0
  35. package/src/templates/service.template.js.map +1 -0
  36. package/bin/cli.js +0 -3
  37. package/dist/config/config-init.d.ts +0 -3
  38. package/dist/config/config-init.d.ts.map +0 -1
  39. package/dist/config/config-init.js +0 -39
  40. package/dist/config/get-config.d.ts +0 -2
  41. package/dist/config/get-config.d.ts.map +0 -1
  42. package/dist/config/get-config.js +0 -18
  43. package/dist/config/packageManager.enum.d.ts +0 -4
  44. package/dist/config/packageManager.enum.d.ts.map +0 -1
  45. package/dist/config/packageManager.enum.js +0 -7
  46. package/dist/index.d.ts +0 -2
  47. package/dist/index.d.ts.map +0 -1
  48. package/dist/index.js +0 -28
  49. package/dist/initializer.d.ts +0 -2
  50. package/dist/initializer.d.ts.map +0 -1
  51. package/dist/initializer.js +0 -7
  52. package/dist/lib/cli.d.ts +0 -2
  53. package/dist/lib/cli.d.ts.map +0 -1
  54. package/dist/lib/cli.js +0 -8
  55. package/dist/service/generate-service.d.ts +0 -2
  56. package/dist/service/generate-service.d.ts.map +0 -1
  57. package/dist/service/generate-service.js +0 -74
package/README.md CHANGED
@@ -1,7 +1,48 @@
1
- # cli
1
+ # @nest-extended/cli
2
2
 
3
- This library was generated with [Nx](https://nx.dev).
3
+ A powerful command-line interface for the **NestExtended** ecosystem. This CLI automates the creation of modules, services, controllers, schemas, and DTOs, ensuring your project follows best practices and maintains consistency.
4
4
 
5
- ## Building
5
+ ## Installation
6
6
 
7
- Run `nx build cli` to build the library.
7
+ ```bash
8
+ yarn add -D @nest-extended/cli
9
+ # or
10
+ npm install -D @nest-extended/cli
11
+ ```
12
+
13
+ ## Commands
14
+
15
+ ### Generate Service (`g service`)
16
+
17
+ Generates a complete resource bundle including:
18
+ - **Module**: Registers the controller and service.
19
+ - **Service**: Extends `NestService` from `@nest-extended/mongoose`.
20
+ - **Controller**: Extends `NestController` from `@nest-extended/core`.
21
+ - **Schema**: Mongoose schema with `timestamps` and soft delete fields.
22
+ - **DTO**: Data Transfer Object with validation.
23
+ - **Specs**: Unit tests for service and controller.
24
+
25
+ It also automatically updates your `src/app.module.ts` to include the new module.
26
+
27
+ **Usage:**
28
+
29
+ ```bash
30
+ nestx-cli g service <name>
31
+ # or
32
+ nestx-cli generate service <name>
33
+ ```
34
+
35
+ **Example:**
36
+
37
+ ```bash
38
+ nestx-cli g service user-profile
39
+ ```
40
+
41
+ This will create:
42
+ - `src/services/userProfile/userProfile.module.ts`
43
+ - `src/services/userProfile/userProfile.service.ts`
44
+ - `src/services/userProfile/userProfile.controller.ts`
45
+ - `src/services/userProfile/dto/userProfile.dto.ts`
46
+ - `src/schemas/userProfile.schema.ts`
47
+ - `src/services/userProfile/userProfile.service.spec.ts`
48
+ - `src/services/userProfile/userProfile.controller.spec.ts`
package/package.json CHANGED
@@ -1,31 +1,23 @@
1
1
  {
2
2
  "name": "@nest-extended/cli",
3
- "version": "0.0.1-beta-3",
4
- "type": "module",
3
+ "version": "0.0.1",
5
4
  "private": false,
6
- "publishConfig": {
7
- "access": "public"
8
- },
9
- "main": "./dist/index.js",
10
- "module": "./dist/index.js",
11
- "types": "./dist/index.d.ts",
5
+ "main": "./src/index.js",
6
+ "types": "./src/index.d.ts",
12
7
  "bin": {
13
- "nest-cli": "bin/cli.js"
14
- },
15
- "exports": {
16
- "./package.json": "./package.json",
17
- ".": {
18
- "types": "./dist/index.d.ts",
19
- "import": "./dist/index.js",
20
- "default": "./dist/index.js"
21
- }
8
+ "nestx-cli": "./src/index.js"
22
9
  },
23
- "files": [
24
- "bin",
25
- "dist",
26
- "!**/*.tsbuildinfo"
27
- ],
28
10
  "dependencies": {
29
- "tslib": "^2.3.0"
30
- }
31
- }
11
+ "tslib": "^2.3.0",
12
+ "commander": "^11.0.0",
13
+ "chalk": "^4.1.2",
14
+ "inquirer": "^8.2.5",
15
+ "fs-extra": "^11.1.1"
16
+ },
17
+ "devDependencies": {
18
+ "@types/node": "^18.16.9",
19
+ "@types/inquirer": "^9.0.3",
20
+ "@types/fs-extra": "^11.0.1"
21
+ },
22
+ "type": "commonjs"
23
+ }
@@ -0,0 +1,2 @@
1
+ import { Command } from 'commander';
2
+ export declare const generateCommand: Command;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.generateCommand = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const commander_1 = require("commander");
6
+ const create_file_1 = require("../lib/create-file");
7
+ const update_app_module_1 = require("../lib/update-app-module");
8
+ const module_template_1 = require("../templates/module.template");
9
+ const service_template_1 = require("../templates/service.template");
10
+ const controller_template_1 = require("../templates/controller.template");
11
+ const dto_template_1 = require("../templates/dto.template");
12
+ const schema_template_1 = require("../templates/schema.template");
13
+ const service_spec_template_1 = require("../templates/service.spec.template");
14
+ const controller_spec_template_1 = require("../templates/controller.spec.template");
15
+ exports.generateCommand = new commander_1.Command('generate')
16
+ .alias('g')
17
+ .description('Generate a new element');
18
+ exports.generateCommand
19
+ .command('service <name>')
20
+ .description('Generate a new service')
21
+ .action((rawName) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
22
+ // if arg have '-' change to camelCase (Logic from original index.js)
23
+ const argArray = rawName.split('-');
24
+ argArray.forEach((arg, index) => {
25
+ argArray[index] = arg[0].toUpperCase() + arg.slice(1).toLowerCase();
26
+ });
27
+ const Name = argArray.join(''); // PascalCase
28
+ const name = Name[0].toLowerCase() + Name.slice(1); // camelCase
29
+ console.log(`Generating service for: ${Name} (${name})`);
30
+ (0, create_file_1.createFileWithContent)(`src/schemas/${name}.schema.ts`, (0, schema_template_1.getSchema)(Name));
31
+ (0, create_file_1.createFileWithContent)(`src/services/${name}/${name}.module.ts`, (0, module_template_1.getModule)(Name, name));
32
+ (0, create_file_1.createFileWithContent)(`src/services/${name}/${name}.service.ts`, (0, service_template_1.getService)(Name, name));
33
+ (0, create_file_1.createFileWithContent)(`src/services/${name}/${name}.controller.ts`, (0, controller_template_1.getController)(Name, name, rawName));
34
+ (0, create_file_1.createFileWithContent)(`src/services/${name}/dto/${name}.dto.ts`, (0, dto_template_1.getDto)(Name));
35
+ (0, create_file_1.createFileWithContent)(`src/services/${name}/${name}.service.spec.ts`, (0, service_spec_template_1.getServiceSpec)(Name, name));
36
+ (0, create_file_1.createFileWithContent)(`src/services/${name}/${name}.controller.spec.ts`, (0, controller_spec_template_1.getControllerSpec)(Name, name));
37
+ yield (0, update_app_module_1.updateAppModule)(Name, name);
38
+ }));
39
+ //# sourceMappingURL=generate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../../../packages/cli/src/commands/generate.ts"],"names":[],"mappings":";;;;AACA,yCAAoC;AACpC,oDAA2D;AAC3D,gEAA2D;AAC3D,kEAAyD;AACzD,oEAA2D;AAC3D,0EAAiE;AACjE,4DAAmD;AACnD,kEAAyD;AACzD,8EAAoE;AACpE,oFAA0E;AAE7D,QAAA,eAAe,GAAG,IAAI,mBAAO,CAAC,UAAU,CAAC;KACjD,KAAK,CAAC,GAAG,CAAC;KACV,WAAW,CAAC,wBAAwB,CAAC,CAAC;AAE3C,uBAAe;KACV,OAAO,CAAC,gBAAgB,CAAC;KACzB,WAAW,CAAC,wBAAwB,CAAC;KACrC,MAAM,CAAC,CAAO,OAAe,EAAE,EAAE;IAC9B,qEAAqE;IACrE,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACpC,QAAQ,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QAC5B,QAAQ,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IACxE,CAAC,CAAC,CAAC;IACH,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,aAAa;IAC7C,MAAM,IAAI,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,YAAY;IAEhE,OAAO,CAAC,GAAG,CAAC,2BAA2B,IAAI,KAAK,IAAI,GAAG,CAAC,CAAC;IAEzD,IAAA,mCAAqB,EAAC,eAAe,IAAI,YAAY,EAAE,IAAA,2BAAS,EAAC,IAAI,CAAC,CAAC,CAAC;IACxE,IAAA,mCAAqB,EAAC,gBAAgB,IAAI,IAAI,IAAI,YAAY,EAAE,IAAA,2BAAS,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IACvF,IAAA,mCAAqB,EAAC,gBAAgB,IAAI,IAAI,IAAI,aAAa,EAAE,IAAA,6BAAU,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC;IACzF,IAAA,mCAAqB,EACjB,gBAAgB,IAAI,IAAI,IAAI,gBAAgB,EAC5C,IAAA,mCAAa,EAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,CACrC,CAAC;IACF,IAAA,mCAAqB,EAAC,gBAAgB,IAAI,QAAQ,IAAI,SAAS,EAAE,IAAA,qBAAM,EAAC,IAAI,CAAC,CAAC,CAAC;IAC/E,IAAA,mCAAqB,EACjB,gBAAgB,IAAI,IAAI,IAAI,kBAAkB,EAC9C,IAAA,sCAAc,EAAC,IAAI,EAAE,IAAI,CAAC,CAC7B,CAAC;IACF,IAAA,mCAAqB,EACjB,gBAAgB,IAAI,IAAI,IAAI,qBAAqB,EACjD,IAAA,4CAAiB,EAAC,IAAI,EAAE,IAAI,CAAC,CAChC,CAAC;IAEF,MAAM,IAAA,mCAAe,EAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACtC,CAAC,CAAA,CAAC,CAAC"}
package/src/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/src/index.js ADDED
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ const commander_1 = require("commander");
5
+ const generate_1 = require("./commands/generate");
6
+ const program = new commander_1.Command();
7
+ program
8
+ .name('nestx-cli')
9
+ .description('CLI for @nest-extended packages')
10
+ .version('0.0.1');
11
+ program.addCommand(generate_1.generateCommand);
12
+ program.parse(process.argv);
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/cli/src/index.ts"],"names":[],"mappings":";;;AACA,yCAAoC;AACpC,kDAAsD;AAEtD,MAAM,OAAO,GAAG,IAAI,mBAAO,EAAE,CAAC;AAE9B,OAAO;KACF,IAAI,CAAC,WAAW,CAAC;KACjB,WAAW,CAAC,iCAAiC,CAAC;KAC9C,OAAO,CAAC,OAAO,CAAC,CAAC;AAEtB,OAAO,CAAC,UAAU,CAAC,0BAAe,CAAC,CAAC;AAEpC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function createFileWithContent(filePath: string, content: string, callback?: (err?: Error) => void): void;
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createFileWithContent = createFileWithContent;
4
+ const fs = require("fs-extra");
5
+ const path = require("path");
6
+ const chalk = require("chalk");
7
+ function createFileWithContent(filePath, content, callback) {
8
+ // Extract the directory path from the file path
9
+ const directory = path.dirname(filePath);
10
+ // Create the directory if it doesn't exist
11
+ fs.mkdirSync(directory, { recursive: true });
12
+ // Write the content to the file
13
+ fs.writeFile(filePath, content, (err) => {
14
+ if (err) {
15
+ console.error(chalk.red('Error creating file:'), err);
16
+ }
17
+ else {
18
+ console.log(chalk.green('File created successfully:'), filePath);
19
+ }
20
+ // Invoke the callback function, if provided
21
+ if (callback) {
22
+ callback(err || undefined);
23
+ }
24
+ });
25
+ }
26
+ //# sourceMappingURL=create-file.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-file.js","sourceRoot":"","sources":["../../../../../packages/cli/src/lib/create-file.ts"],"names":[],"mappings":";;AAKA,sDAwBC;AA5BD,+BAA+B;AAC/B,6BAA6B;AAC7B,+BAA+B;AAE/B,SAAgB,qBAAqB,CACjC,QAAgB,EAChB,OAAe,EACf,QAAgC;IAEhC,gDAAgD;IAChD,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAEzC,2CAA2C;IAC3C,EAAE,CAAC,SAAS,CAAC,SAAS,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAE7C,gCAAgC;IAChC,EAAE,CAAC,SAAS,CAAC,QAAQ,EAAE,OAAO,EAAE,CAAC,GAAiC,EAAE,EAAE;QAClE,IAAI,GAAG,EAAE,CAAC;YACN,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,sBAAsB,CAAC,EAAE,GAAG,CAAC,CAAC;QAC1D,CAAC;aAAM,CAAC;YACJ,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,4BAA4B,CAAC,EAAE,QAAQ,CAAC,CAAC;QACrE,CAAC;QAED,4CAA4C;QAC5C,IAAI,QAAQ,EAAE,CAAC;YACX,QAAQ,CAAC,GAAG,IAAI,SAAS,CAAC,CAAC;QAC/B,CAAC;IACL,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1 @@
1
+ export declare function updateAppModule(Name: string, name: string): Promise<void>;
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateAppModule = updateAppModule;
4
+ const tslib_1 = require("tslib");
5
+ const fs = require("fs-extra");
6
+ const path = require("path");
7
+ const chalk = require("chalk");
8
+ function updateAppModule(Name, name) {
9
+ return tslib_1.__awaiter(this, void 0, void 0, function* () {
10
+ const appModulePath = path.join(process.cwd(), 'src/app.module.ts');
11
+ try {
12
+ if (!fs.existsSync(appModulePath)) {
13
+ console.warn(chalk.yellow(`Warning: ${appModulePath} not found. Skipping app.module.ts update.`));
14
+ return;
15
+ }
16
+ let content = yield fs.readFile(appModulePath, 'utf-8');
17
+ // Check if module is already imported
18
+ const moduleImport = `${Name}Module`;
19
+ if (content.includes(`import { ${moduleImport} }`)) {
20
+ console.log(chalk.yellow(`${moduleImport} is already imported in app.module.ts`));
21
+ return;
22
+ }
23
+ // Find the last module import line (lines importing from './services/')
24
+ const importRegex = /import\s*{\s*\w+Module\s*}\s*from\s*'\.\/services\/[^']+';/g;
25
+ let lastImportMatch = null;
26
+ let match;
27
+ while ((match = importRegex.exec(content)) !== null) {
28
+ lastImportMatch = match;
29
+ }
30
+ // Create the new import statement
31
+ const newImport = `import { ${Name}Module } from './services/${name}/${name}.module';`;
32
+ if (lastImportMatch) {
33
+ // Insert after the last service module import
34
+ const insertPosition = lastImportMatch.index + lastImportMatch[0].length;
35
+ content = content.slice(0, insertPosition) + '\n' + newImport + content.slice(insertPosition);
36
+ }
37
+ else {
38
+ // If no service module imports found, add after the last import statement
39
+ const lastImportIndex = content.lastIndexOf('import');
40
+ if (lastImportIndex !== -1) {
41
+ const lineEnd = content.indexOf('\n', lastImportIndex);
42
+ content = content.slice(0, lineEnd + 1) + newImport + '\n' + content.slice(lineEnd + 1);
43
+ }
44
+ else {
45
+ // Fallback if no imports at all (unlikely)
46
+ content = newImport + '\n' + content;
47
+ }
48
+ }
49
+ // Find the imports array and add the new module at the end
50
+ // Robust bracket matching
51
+ const importsStartIndex = content.search(/imports:\s*\[/);
52
+ if (importsStartIndex !== -1) {
53
+ const openBracketIndex = content.indexOf('[', importsStartIndex);
54
+ let counter = 1;
55
+ let closingBracketIndex = -1;
56
+ for (let i = openBracketIndex + 1; i < content.length; i++) {
57
+ if (content[i] === '[')
58
+ counter++;
59
+ else if (content[i] === ']')
60
+ counter--;
61
+ if (counter === 0) {
62
+ closingBracketIndex = i;
63
+ break;
64
+ }
65
+ }
66
+ if (closingBracketIndex !== -1) {
67
+ // Logic to determine indentation and prefix
68
+ const beforeClosing = content.substring(0, closingBracketIndex);
69
+ const lines = beforeClosing.split('\n');
70
+ const lastLine = lines[lines.length - 1];
71
+ // use 2 spaces as default indent based on observation
72
+ const indentMatch = lastLine.match(/^\s*/);
73
+ const baseIndent = indentMatch ? indentMatch[0] : ' ';
74
+ // Check if we need a comma for previous item
75
+ const contentInside = content.substring(openBracketIndex + 1, closingBracketIndex);
76
+ const trimmedInside = contentInside.trim();
77
+ // If previous content exists and does not end with comma
78
+ const needsComma = trimmedInside.length > 0 && !trimmedInside.endsWith(',');
79
+ const prefix = needsComma ? ',' : '';
80
+ // Standard formatting: add 2 spaces to base indent for item
81
+ const itemIndent = baseIndent + ' ';
82
+ // Adjust insertion point to remove trailing whitespace/indent before closing bracket
83
+ // This allows us to re-insert the closing bracket indentation correctly
84
+ const trailingWhitespaceMatch = beforeClosing.match(/(\r?\n\s*)$/);
85
+ const trailingWhitespaceLength = trailingWhitespaceMatch ? trailingWhitespaceMatch[0].length : 0;
86
+ const insertionPoint = closingBracketIndex - trailingWhitespaceLength;
87
+ // Construct new content:
88
+ // 1. Prefix (comma if needed)
89
+ // 2. Newline + Item Indent + Module Name + Comma
90
+ // 3. Newline + Base Indent (for closing bracket)
91
+ const insertString = `${prefix}\n${itemIndent}${Name}Module,\n${baseIndent}`;
92
+ // Slice until insertion point (excludes original trailing whitespace)
93
+ // Add insertString
94
+ // Slice from closingBracketIndex (includes closing bracket)
95
+ content = content.slice(0, insertionPoint) + insertString + content.slice(closingBracketIndex);
96
+ }
97
+ }
98
+ yield fs.writeFile(appModulePath, content, 'utf-8');
99
+ console.log(chalk.green(`Successfully added ${Name}Module to app.module.ts`));
100
+ }
101
+ catch (err) {
102
+ console.error(chalk.red('Error updating app.module.ts:'), err.message);
103
+ }
104
+ });
105
+ }
106
+ //# sourceMappingURL=update-app-module.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"update-app-module.js","sourceRoot":"","sources":["../../../../../packages/cli/src/lib/update-app-module.ts"],"names":[],"mappings":";;AAKA,0CA6GC;;AAjHD,+BAA+B;AAC/B,6BAA6B;AAC7B,+BAA+B;AAE/B,SAAsB,eAAe,CAAC,IAAY,EAAE,IAAY;;QAC5D,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE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AiD;oBAEjD,MAAM,YAAY,GAAG,GAAG,MAAM,KAAK,UAAU,GAAG,IAAI,YAAY,UAAU,EAAE,CAAC;oBAE7E,sEAAsE;oBACtE,mBAAmB;oBACnB,4DAA4D;oBAC5D,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,cAAc,CAAC,GAAG,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;gBACnG,CAAC;YACL,CAAC;YAED,MAAM,EAAE,CAAC,SAAS,CAAC,aAAa,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC;YACpD,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,sBAAsB,IAAI,yBAAyB,CAAC,CAAC,CAAC;QAClF,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAChB,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,+BAA+B,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;QAC3E,CAAC;IACL,CAAC;CAAA"}
@@ -0,0 +1 @@
1
+ export declare const getControllerSpec: (Name: string, name: string) => string;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getControllerSpec = void 0;
4
+ const getControllerSpec = (Name, name) => `import { Test, TestingModule } from '@nestjs/testing';
5
+ import { ${Name}Controller } from './${name}.controller';
6
+
7
+ describe('${Name}Controller', () => {
8
+ let controller: ${Name}Controller;
9
+
10
+ beforeEach(async () => {
11
+ const module: TestingModule = await Test.createTestingModule({
12
+ controllers: [${Name}Controller],
13
+ }).compile();
14
+
15
+ controller = module.get<${Name}Controller>(${Name}Controller);
16
+ });
17
+
18
+ it('should be defined', () => {
19
+ expect(controller).toBeDefined();
20
+ });
21
+ });
22
+ `;
23
+ exports.getControllerSpec = getControllerSpec;
24
+ //# sourceMappingURL=controller.spec.template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controller.spec.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/controller.spec.template.ts"],"names":[],"mappings":";;;AACO,MAAM,iBAAiB,GAAG,CAAC,IAAY,EAAE,IAAY,EAAU,EAAE,CAAC;WAC9D,IAAI,wBAAwB,IAAI;;YAE/B,IAAI;oBACI,IAAI;;;;sBAIF,IAAI;;;8BAGI,IAAI,eAAe,IAAI;;;;;;;CAOpD,CAAC;AAlBW,QAAA,iBAAiB,qBAkB5B"}
@@ -0,0 +1 @@
1
+ export declare const getController: (Name: string, name: string, url: string) => string;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getController = void 0;
4
+ const getController = (Name, name, url) => `import {
5
+ Body,
6
+ Controller,
7
+ Delete,
8
+ Get,
9
+ Param,
10
+ Patch,
11
+ Post,
12
+ Query,
13
+ } from '@nestjs/common';
14
+ import { ${Name}Service } from './${name}.service';
15
+ import { User } from '@nest-extended/core';
16
+ import { ${Name} } from 'src/schemas/${name}.schema';
17
+ import { ModifyBody, setCreatedBy } from '@nest-extended/core';
18
+
19
+ @Controller('${url}')
20
+ export class ${Name}Controller {
21
+ constructor(private readonly ${name}Service: ${Name}Service) { }
22
+
23
+ @Get()
24
+ async find(@Query() query: Record<string, any>) {
25
+ return await this.${name}Service._find(query);
26
+ }
27
+
28
+ @Get('/:id?')
29
+ async get(@Query() query: Record<string, any>, @Param('id') id: string) {
30
+ return await this.${name}Service._get(id, query);
31
+ }
32
+
33
+ @Post()
34
+ async create(
35
+ @ModifyBody(setCreatedBy()) create${Name}Dto: ${Name}
36
+ ) {
37
+ return await this.${name}Service._create(create${Name}Dto);
38
+ }
39
+
40
+ @Patch('/:id?')
41
+ async patch(
42
+ @Query() query,
43
+ @Body() patch${Name}Dto: Partial<${Name}>,
44
+ @Param('id') id,
45
+ ) {
46
+ return await this.${name}Service._patch(id, patch${Name}Dto, query);
47
+ }
48
+
49
+ @Delete('/:id?')
50
+ async delete(@Param('id') id, @Query() query, @User() user) {
51
+ return await this.${name}Service._remove(id, query, user);
52
+ }
53
+ }
54
+ `;
55
+ exports.getController = getController;
56
+ //# sourceMappingURL=controller.template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"controller.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/controller.template.ts"],"names":[],"mappings":";;;AACO,MAAM,aAAa,GAAG,CAAC,IAAY,EAAE,IAAY,EAAE,GAAW,EAAU,EAAE,CAAC;;;;;;;;;;WAUvE,IAAI,qBAAqB,IAAI;;WAE7B,IAAI,wBAAwB,IAAI;;;eAG5B,GAAG;eACH,IAAI;iCACc,IAAI,YAAY,IAAI;;;;wBAI7B,IAAI;;;;;wBAKJ,IAAI;;;;;wCAKY,IAAI,QAAQ,IAAI;;wBAEhC,IAAI,yBAAyB,IAAI;;;;;;mBAMtC,IAAI,gBAAgB,IAAI;;;wBAGnB,IAAI,2BAA2B,IAAI;;;;;wBAKnC,IAAI;;;CAG3B,CAAC;AAlDW,QAAA,aAAa,iBAkDxB"}
@@ -0,0 +1 @@
1
+ export declare const getDto: (Name: string) => string;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDto = void 0;
4
+ const getDto = (Name) => `import { z } from 'zod';
5
+ import { Types } from 'mongoose';
6
+
7
+ export const Create${Name}Validation = z.object({
8
+ name: z.string().optional(),
9
+ createdBy: z
10
+ .string()
11
+ .refine((val) => Types.ObjectId.isValid(val), {
12
+ message: 'Invalid creator ID',
13
+ })
14
+ .optional(),
15
+ createdAt: z.date().optional(),
16
+ updatedAt: z.date().optional(),
17
+ deleted: z.boolean().optional().default(false),
18
+ deletedBy: z
19
+ .string()
20
+ .refine((val) => Types.ObjectId.isValid(val), {
21
+ message: 'Invalid deleter ID',
22
+ })
23
+ .optional(),
24
+ deletedAt: z.date().optional(),
25
+ });
26
+
27
+ export const Patch${Name}Validation = z.object({
28
+ name: z.string().optional(),
29
+ updatedAt: z.date().optional(),
30
+ createdAt: z.date().optional(),
31
+ deleted: z.boolean().optional(),
32
+ deletedBy: z
33
+ .string()
34
+ .refine((val) => Types.ObjectId.isValid(val), {
35
+ message: 'Invalid deleter ID',
36
+ })
37
+ .optional(),
38
+ deletedAt: z.date().optional(),
39
+ });
40
+
41
+ export const Remove${Name}Validation = z.object({
42
+ id: z.string().refine((val) => Types.ObjectId.isValid(val), {
43
+ message: 'Invalid user ID',
44
+ }),
45
+ deletedBy: z
46
+ .string()
47
+ .refine((val) => Types.ObjectId.isValid(val), {
48
+ message: 'Invalid deleter ID',
49
+ })
50
+ .optional(),
51
+ deletedAt: z.date().optional(),
52
+ });
53
+
54
+ export type Create${Name}DTO = z.infer<typeof Create${Name}Validation>;
55
+ export type Patch${Name}DTO = z.infer<typeof Patch${Name}Validation>;
56
+ export type Remove${Name}DTO = z.infer<typeof Remove${Name}Validation>;
57
+ `;
58
+ exports.getDto = getDto;
59
+ //# sourceMappingURL=dto.template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dto.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/dto.template.ts"],"names":[],"mappings":";;;AACO,MAAM,MAAM,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC;;;qBAG3B,IAAI;;;;;;;;;;;;;;;;;;;;oBAoBL,IAAI;;;;;;;;;;;;;;qBAcH,IAAI;;;;;;;;;;;;;oBAaL,IAAI,8BAA8B,IAAI;mBACvC,IAAI,6BAA6B,IAAI;oBACpC,IAAI,8BAA8B,IAAI;CACzD,CAAC;AArDW,QAAA,MAAM,UAqDjB"}
@@ -0,0 +1 @@
1
+ export declare const getModule: (Name: string, name: string) => string;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getModule = void 0;
4
+ const getModule = (Name, name) => `import { Module } from '@nestjs/common';
5
+ import { MongooseModule } from '@nestjs/mongoose';
6
+ import { ${Name}Controller } from './${name}.controller';
7
+ import { ${Name}Service } from './${name}.service';
8
+ import { ${Name}, ${Name}Schema } from 'src/schemas/${name}.schema';
9
+
10
+ @Module({
11
+ imports: [
12
+ MongooseModule.forFeature([{ name: ${Name}.name, schema: ${Name}Schema }]),
13
+ ],
14
+ controllers: [${Name}Controller],
15
+ providers: [
16
+ ${Name}Service,
17
+ ],
18
+ exports: [${Name}Service],
19
+ })
20
+ export class ${Name}Module {}
21
+ `;
22
+ exports.getModule = getModule;
23
+ //# sourceMappingURL=module.template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"module.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/module.template.ts"],"names":[],"mappings":";;;AACO,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,IAAY,EAAU,EAAE,CAAC;;WAEtD,IAAI,wBAAwB,IAAI;WAChC,IAAI,qBAAqB,IAAI;WAC7B,IAAI,KAAK,IAAI,8BAA8B,IAAI;;;;yCAIjB,IAAI,kBAAkB,IAAI;;kBAEjD,IAAI;;MAEhB,IAAI;;cAEI,IAAI;;eAEH,IAAI;CAClB,CAAC;AAjBW,QAAA,SAAS,aAiBpB"}
@@ -0,0 +1 @@
1
+ export declare const getSchema: (Name: string, UserEntity?: string) => string;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSchema = void 0;
4
+ const getSchema = (Name, UserEntity = 'Users') => `import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
5
+ import { HydratedDocument, Types } from 'mongoose';
6
+ import { ${UserEntity} } from './users.schema';
7
+ import EnsureObjectId from '@nest-extended/core/common/ensureObjectId';
8
+
9
+ export type ${Name}Document = HydratedDocument<${Name}>;
10
+
11
+ @Schema({
12
+ timestamps: true,
13
+ })
14
+ export class ${Name} {
15
+ @Prop({ trim: true })
16
+ name?: string;
17
+
18
+ @Prop({
19
+ type: Types.ObjectId,
20
+ ref: ${UserEntity}.name,
21
+ default: null
22
+ })
23
+ createdBy: Types.ObjectId;
24
+
25
+ @Prop({
26
+ type: Types.ObjectId,
27
+ ref: ${UserEntity}.name,
28
+ default: null
29
+ })
30
+ updatedBy?: Types.ObjectId;
31
+
32
+ @Prop({
33
+ type: Types.ObjectId,
34
+ ref: ${UserEntity}.name,
35
+ default: null
36
+ })
37
+ deletedBy?: Types.ObjectId;
38
+
39
+ @Prop({
40
+ type: Boolean,
41
+ default: null
42
+ })
43
+ deleted?: Boolean;
44
+
45
+ @Prop({
46
+ type: Date,
47
+ default: null
48
+ })
49
+ deletedAt?: Date;
50
+
51
+ }
52
+
53
+ export const ${Name}Schema = SchemaFactory.createForClass(${Name});
54
+ `;
55
+ exports.getSchema = getSchema;
56
+ //# sourceMappingURL=schema.template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"schema.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/schema.template.ts"],"names":[],"mappings":";;;AACO,MAAM,SAAS,GAAG,CAAC,IAAY,EAAE,aAAqB,OAAO,EAAU,EAAE,CAAC;;WAEtE,UAAU;;;cAGP,IAAI,+BAA+B,IAAI;;;;;eAKtC,IAAI;;;;;;WAMR,UAAU;;;;;;;WAOV,UAAU;;;;;;;WAOV,UAAU;;;;;;;;;;;;;;;;;;;eAmBN,IAAI,yCAAyC,IAAI;CAC/D,CAAC;AAlDW,QAAA,SAAS,aAkDpB"}
@@ -0,0 +1 @@
1
+ export declare const getServiceSpec: (Name: string, name: string) => string;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getServiceSpec = void 0;
4
+ const getServiceSpec = (Name, name) => `import { Test, TestingModule } from '@nestjs/testing';
5
+ import { ${Name}Service } from './${name}.service';
6
+
7
+ describe('${Name}Service', () => {
8
+ let service: ${Name}Service;
9
+
10
+ beforeEach(async () => {
11
+ const module: TestingModule = await Test.createTestingModule({
12
+ providers: [${Name}Service],
13
+ }).compile();
14
+
15
+ service = module.get<${Name}Service>(${Name}Service);
16
+ });
17
+
18
+ it('should be defined', () => {
19
+ expect(service).toBeDefined();
20
+ });
21
+ });
22
+ `;
23
+ exports.getServiceSpec = getServiceSpec;
24
+ //# sourceMappingURL=service.spec.template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.spec.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/service.spec.template.ts"],"names":[],"mappings":";;;AACO,MAAM,cAAc,GAAG,CAAC,IAAY,EAAE,IAAY,EAAU,EAAE,CAAC;WAC3D,IAAI,qBAAqB,IAAI;;YAE5B,IAAI;iBACC,IAAI;;;;oBAID,IAAI;;;2BAGG,IAAI,YAAY,IAAI;;;;;;;CAO9C,CAAC;AAlBW,QAAA,cAAc,kBAkBzB"}
@@ -0,0 +1 @@
1
+ export declare const getService: (Name: string, name: string) => string;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getService = void 0;
4
+ const getService = (Name, name) => `import { Model } from 'mongoose';
5
+ import { Injectable } from '@nestjs/common';
6
+ import { InjectModel } from '@nestjs/mongoose';
7
+ import { NestService } from '@nest-extended/mongoose';
8
+ import { ${Name}, ${Name}Document } from 'src/schemas/${name}.schema';
9
+
10
+ @Injectable()
11
+ export class ${Name}Service extends NestService<${Name}, ${Name}Document> {
12
+ constructor(
13
+ @InjectModel(${Name}.name) private readonly ${name}Model: Model<${Name}Document>,
14
+ ) {
15
+ super(${name}Model)
16
+ }
17
+ }`;
18
+ exports.getService = getService;
19
+ //# sourceMappingURL=service.template.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.template.js","sourceRoot":"","sources":["../../../../../packages/cli/src/templates/service.template.ts"],"names":[],"mappings":";;;AACO,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,IAAY,EAAU,EAAE,CAAC;;;;WAIvD,IAAI,KAAK,IAAI,gCAAgC,IAAI;;;eAG7C,IAAI,+BAA+B,IAAI,KAAK,IAAI;;mBAE5C,IAAI,2BAA2B,IAAI,gBAAgB,IAAI;;YAE9D,IAAI;;EAEd,CAAC;AAbU,QAAA,UAAU,cAapB"}
package/bin/cli.js DELETED
@@ -1,3 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- require('../dist/index.js');
@@ -1,3 +0,0 @@
1
- export declare const CONFIG_FILE_NAME = "nest-extended.config.json";
2
- export declare function initializeConfig(): Promise<void>;
3
- //# sourceMappingURL=config-init.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"config-init.d.ts","sourceRoot":"","sources":["../../src/config/config-init.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,gBAAgB,8BAA8B,CAAC;AAe5D,wBAAsB,gBAAgB,kBAqBrC"}
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CONFIG_FILE_NAME = void 0;
4
- exports.initializeConfig = initializeConfig;
5
- const tslib_1 = require("tslib");
6
- const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
7
- const path_1 = tslib_1.__importDefault(require("path"));
8
- const fs_1 = tslib_1.__importDefault(require("fs"));
9
- exports.CONFIG_FILE_NAME = 'nest-extended.config.json';
10
- async function promptPackageManager() {
11
- const { packageManager } = await inquirer_1.default.prompt([
12
- {
13
- type: 'list',
14
- name: 'packageManager',
15
- message: 'Select your preferred package manager:',
16
- choices: ['npm', 'yarn', 'pnpm'],
17
- },
18
- ]);
19
- return packageManager;
20
- }
21
- async function initializeConfig() {
22
- const configFilePath = path_1.default.join(process.cwd(), exports.CONFIG_FILE_NAME);
23
- let config = {};
24
- // Check if the file already exists
25
- if (fs_1.default.existsSync(configFilePath)) {
26
- console.log(`🔄 ${exports.CONFIG_FILE_NAME} already exists. Updating packageManager...`);
27
- const existingContent = fs_1.default.readFileSync(configFilePath, 'utf-8');
28
- config = JSON.parse(existingContent);
29
- }
30
- else {
31
- console.log(`📝 Creating a new ${exports.CONFIG_FILE_NAME}...`);
32
- }
33
- // Prompt user for package manager
34
- const packageManager = await promptPackageManager();
35
- config.packageManager = packageManager;
36
- // Write the updated config to the file
37
- fs_1.default.writeFileSync(configFilePath, JSON.stringify(config, null, 2));
38
- console.log(`✅ ${exports.CONFIG_FILE_NAME} has been updated.`);
39
- }
@@ -1,2 +0,0 @@
1
- export declare function getConfig(): Promise<any>;
2
- //# sourceMappingURL=get-config.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"get-config.d.ts","sourceRoot":"","sources":["../../src/config/get-config.ts"],"names":[],"mappings":"AAKA,wBAAsB,SAAS,iBAU9B"}
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getConfig = getConfig;
4
- const tslib_1 = require("tslib");
5
- const config_init_1 = require("./config-init");
6
- const path_1 = tslib_1.__importDefault(require("path"));
7
- const fs_1 = tslib_1.__importDefault(require("fs"));
8
- async function getConfig() {
9
- const configFilePath = path_1.default.join(process.cwd(), config_init_1.CONFIG_FILE_NAME);
10
- if (fs_1.default.existsSync(configFilePath)) {
11
- const existingContent = fs_1.default.readFileSync(configFilePath, 'utf-8');
12
- return JSON.parse(existingContent);
13
- }
14
- else {
15
- await (0, config_init_1.initializeConfig)();
16
- return await getConfig();
17
- }
18
- }
@@ -1,4 +0,0 @@
1
- export declare enum PackageManagerEnum {
2
- YARN = "yarn"
3
- }
4
- //# sourceMappingURL=packageManager.enum.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"packageManager.enum.d.ts","sourceRoot":"","sources":["../../src/config/packageManager.enum.ts"],"names":[],"mappings":"AAAA,oBAAY,kBAAkB;IAC1B,IAAI,SAAS;CAEhB"}
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.PackageManagerEnum = void 0;
4
- var PackageManagerEnum;
5
- (function (PackageManagerEnum) {
6
- PackageManagerEnum["YARN"] = "yarn";
7
- })(PackageManagerEnum || (exports.PackageManagerEnum = PackageManagerEnum = {}));
package/dist/index.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js DELETED
@@ -1,28 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const commander_1 = require("commander");
4
- const initializer_1 = require("./initializer");
5
- // import { generateCode } from './code-generator';
6
- // import NestService from "@nest-extended/mongoose";
7
- const generate_service_1 = require("./service/generate-service");
8
- const program = new commander_1.Command();
9
- program
10
- .name('@nest-extended/cli')
11
- .description('A CLI for generating NestJS code')
12
- .version('0.0.1');
13
- program
14
- .command('init')
15
- .description('Create or update a nest-extended.config.json file')
16
- .action(() => {
17
- // console.log(NestService);
18
- (0, initializer_1.initializer)();
19
- });
20
- program
21
- .command('g <type> <name>')
22
- .description('Generate a NestJS component (e.g., module, controller, service)')
23
- .action(async (type) => {
24
- // generateCode(type, name);
25
- if (type === 'service')
26
- await (0, generate_service_1.generateService)();
27
- });
28
- program.parse(process.argv);
@@ -1,2 +0,0 @@
1
- export declare function initializer(): Promise<void>;
2
- //# sourceMappingURL=initializer.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"initializer.d.ts","sourceRoot":"","sources":["../src/initializer.ts"],"names":[],"mappings":"AAEA,wBAAsB,WAAW,kBAEhC"}
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.initializer = initializer;
4
- const config_init_1 = require("./config/config-init");
5
- async function initializer() {
6
- await (0, config_init_1.initializeConfig)();
7
- }
package/dist/lib/cli.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export declare function cli(): string;
2
- //# sourceMappingURL=cli.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/lib/cli.ts"],"names":[],"mappings":"AACA,wBAAgB,GAAG,IAAI,MAAM,CAG5B"}
package/dist/lib/cli.js DELETED
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.cli = cli;
4
- const core_1 = require("@nest-extended/core");
5
- function cli() {
6
- (0, core_1.core)();
7
- return 'cli';
8
- }
@@ -1,2 +0,0 @@
1
- export declare function generateService(): Promise<void>;
2
- //# sourceMappingURL=generate-service.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate-service.d.ts","sourceRoot":"","sources":["../../src/service/generate-service.ts"],"names":[],"mappings":"AAuDA,wBAAsB,eAAe,kBAoBpC"}
@@ -1,74 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.generateService = generateService;
4
- const tslib_1 = require("tslib");
5
- const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
6
- // import fs from "fs";
7
- const path_1 = tslib_1.__importDefault(require("path"));
8
- async function promptServiceName() {
9
- const { serviceName } = await inquirer_1.default.prompt([
10
- {
11
- type: 'input',
12
- name: 'serviceName',
13
- message: 'Enter the service name:',
14
- validate: (input) => input.trim() ? true : 'Service name cannot be empty',
15
- },
16
- ]);
17
- return serviceName;
18
- }
19
- function toCamelCase(input) {
20
- return input
21
- .replace(/[-_/](\w)/g, (_, char) => char.toUpperCase()) // Convert after -, _, / to uppercase
22
- .replace(/^./, char => char.toLowerCase()); // Lowercase first character
23
- }
24
- function getPaths(serviceName) {
25
- const normalizedPath = serviceName.split(/[\\/]/).map(toCamelCase).join(path_1.default.sep);
26
- const segments = normalizedPath.split(path_1.default.sep);
27
- const folderPath = path_1.default.join(process.cwd(), ...segments.slice(0, -1), segments.slice(-1)[0]);
28
- const baseName = segments.slice(-1)[0];
29
- return { folderPath, baseName };
30
- }
31
- // function generateFileContent(baseName: string): Record<string, string> {
32
- // return {
33
- // controller: `
34
- // import { Controller } from '@nestjs/common';
35
- //
36
- // @Controller('${baseName.toLowerCase()}')
37
- // export class ${baseName.charAt(0).toUpperCase() + baseName.slice(1)}Controller {}`,
38
- // service: `
39
- // import { Injectable } from '@nestjs/common';
40
- //
41
- // @Injectable()
42
- // export class ${baseName.charAt(0).toUpperCase() + baseName.slice(1)}Service {}`,
43
- // module: `
44
- // import { Module } from '@nestjs/common';
45
- // import { ${baseName.charAt(0).toUpperCase() + baseName.slice(1)}Controller } from './${baseName}.controller';
46
- // import { ${baseName.charAt(0).toUpperCase() + baseName.slice(1)}Service } from './${baseName}.service';
47
- //
48
- // @Module({
49
- // controllers: [${baseName.charAt(0).toUpperCase() + baseName.slice(1)}Controller],
50
- // providers: [${baseName.charAt(0).toUpperCase() + baseName.slice(1)}Service],
51
- // })
52
- // export class ${baseName.charAt(0).toUpperCase() + baseName.slice(1)}Module {}`,
53
- // };
54
- // }
55
- async function generateService() {
56
- const serviceName = await promptServiceName();
57
- const { folderPath, baseName } = getPaths(serviceName);
58
- console.log("::: ", folderPath, baseName);
59
- // if (!fs.existsSync(folderPath)) {
60
- // fs.mkdirSync(folderPath, { recursive: true });
61
- // }
62
- //
63
- // const files = generateFileContent(baseName);
64
- //
65
- // for (const [type, content] of Object.entries(files)) {
66
- // const filePath = path.join(folderPath, `${baseName}.${type}.ts`);
67
- // if (fs.existsSync(filePath)) {
68
- // console.log(`⚠️ File ${filePath} already exists. Skipping.`);
69
- // } else {
70
- // fs.writeFileSync(filePath, content.trim());
71
- // console.log(`✅ Created ${filePath}`);
72
- // }
73
- // }
74
- }