@nest-extended/cli 0.0.1-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,7 @@
1
+ # cli
2
+
3
+ This library was generated with [Nx](https://nx.dev).
4
+
5
+ ## Building
6
+
7
+ Run `nx build cli` to build the library.
@@ -0,0 +1,3 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,39 @@
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
+ }
@@ -0,0 +1,2 @@
1
+ export declare function getConfig(): Promise<any>;
2
+ //# sourceMappingURL=get-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-config.d.ts","sourceRoot":"","sources":["../../src/config/get-config.ts"],"names":[],"mappings":"AAKA,wBAAsB,SAAS,iBAU9B"}
@@ -0,0 +1,18 @@
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
+ }
@@ -0,0 +1,4 @@
1
+ export declare enum PackageManagerEnum {
2
+ YARN = "yarn"
3
+ }
4
+ //# sourceMappingURL=packageManager.enum.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"packageManager.enum.d.ts","sourceRoot":"","sources":["../../src/config/packageManager.enum.ts"],"names":[],"mappings":"AAAA,oBAAY,kBAAkB;IAC1B,IAAI,SAAS;CAEhB"}
@@ -0,0 +1,7 @@
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 = {}));
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":""}
package/dist/index.js ADDED
@@ -0,0 +1,28 @@
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);
@@ -0,0 +1,2 @@
1
+ export declare function initializer(): Promise<void>;
2
+ //# sourceMappingURL=initializer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initializer.d.ts","sourceRoot":"","sources":["../src/initializer.ts"],"names":[],"mappings":"AAEA,wBAAsB,WAAW,kBAEhC"}
@@ -0,0 +1,7 @@
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
+ }
@@ -0,0 +1,2 @@
1
+ export declare function cli(): string;
2
+ //# sourceMappingURL=cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/lib/cli.ts"],"names":[],"mappings":"AACA,wBAAgB,GAAG,IAAI,MAAM,CAG5B"}
@@ -0,0 +1,8 @@
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
+ }
@@ -0,0 +1,2 @@
1
+ export declare function generateService(): Promise<void>;
2
+ //# sourceMappingURL=generate-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-service.d.ts","sourceRoot":"","sources":["../../src/service/generate-service.ts"],"names":[],"mappings":"AAuDA,wBAAsB,eAAe,kBAoBpC"}
@@ -0,0 +1,74 @@
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
+ }
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@nest-extended/cli",
3
+ "version": "0.0.1-beta",
4
+ "type": "module",
5
+ "private": false,
6
+ "publishConfig": {
7
+ "access": "public"
8
+ },
9
+ "main": "./dist/index.js",
10
+ "module": "./dist/index.js",
11
+ "types": "./dist/index.d.ts",
12
+ "bin": {
13
+ "@nest-extended/cli": "./dist/index.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
+ }
22
+ },
23
+ "files": [
24
+ "dist",
25
+ "!**/*.tsbuildinfo"
26
+ ],
27
+ "dependencies": {
28
+ "tslib": "^2.3.0"
29
+ }
30
+ }