nest-combo 1.0.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.
- package/LICENSE +21 -0
- package/README.MD +160 -0
- package/bin/cli.js +159 -0
- package/lib/generate.js +54 -0
- package/package.json +30 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 ViniBr
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.MD
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# NestJS Combo CLI
|
|
2
|
+
|
|
3
|
+
 
|
|
4
|
+
|
|
5
|
+
A CLI tool to generate NestJS modules, controllers, services, and other components in a single line command.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Table of Contents
|
|
10
|
+
|
|
11
|
+
- [How it works](#how-it-works)
|
|
12
|
+
- [Features](#features)
|
|
13
|
+
- [Installation](#installation)
|
|
14
|
+
- [Usage](#usage)
|
|
15
|
+
- [Options](#options)
|
|
16
|
+
- [Examples](#examples)
|
|
17
|
+
- [Contributing](#contributing)
|
|
18
|
+
- [License](#license)
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## How it works {#howitworks}
|
|
23
|
+
|
|
24
|
+
How Nest-Combo Works with NestJS CLI
|
|
25
|
+
|
|
26
|
+
If you have the NestJS CLI installed globally , nest-combo will automatically detect and use it to execute commands. This ensures compatibility with your existing global setup.
|
|
27
|
+
|
|
28
|
+
If the NestJS CLI is not installed globally, don't worry! nest-combo comes bundled with its own local version of the NestJS CLI. It will seamlessly fall back to this cached version to ensure smooth operation without requiring any additional setup from you.
|
|
29
|
+
WIth Nest-Combo you will be able to speed you development process with single line commands.
|
|
30
|
+
|
|
31
|
+
---
|
|
32
|
+
|
|
33
|
+
## Features
|
|
34
|
+
|
|
35
|
+
- Generate NestJS modules, controllers, services, gateways, middleware, and interceptors with single line command.
|
|
36
|
+
- Support for optional flags like `--no-spec` and `--dry-run`.
|
|
37
|
+
- Colorful and user-friendly output using `chalk`.
|
|
38
|
+
- Easy-to-use command-line interface.
|
|
39
|
+
|
|
40
|
+
---
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
Install the package globally using npm:
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
npm install -g nest-combo
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Verify the installation by checking the version:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
nest-combo --version
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Usage
|
|
59
|
+
|
|
60
|
+
Run the CLI tool with the desired module name and options:
|
|
61
|
+
|
|
62
|
+
```bash
|
|
63
|
+
nest-combo <module-name> [options]
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### Example:
|
|
67
|
+
|
|
68
|
+
To create a module, controller and a service in a single line command:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
nest-combo users -m -c -s
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
---
|
|
75
|
+
|
|
76
|
+
## Options
|
|
77
|
+
|
|
78
|
+
| Flag | Description |
|
|
79
|
+
| --------------------- | -------------------------------------------------------------- |
|
|
80
|
+
| `-m, --module` | Generate a module |
|
|
81
|
+
| `-c, --controller` | Generate a controller |
|
|
82
|
+
| `-s, --service` | Generate a service |
|
|
83
|
+
| `-g, --gateway` | Generate a gateway |
|
|
84
|
+
| `-mw, --middleware` | Generate middleware |
|
|
85
|
+
| `-itc, --interceptor` | Generate an interceptor |
|
|
86
|
+
| `-ns, --no-spec` | Do not generate `.spec.ts` test files |
|
|
87
|
+
| `-dr, --dry-run` | Report actions that would be taken without writing out results |
|
|
88
|
+
|
|
89
|
+
---
|
|
90
|
+
|
|
91
|
+
## Examples
|
|
92
|
+
|
|
93
|
+
### Generate a Module, Controller, and Service
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
nest-combo users -m -c -s
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
### Generate a Module and Service Without Spec Files
|
|
100
|
+
|
|
101
|
+
```bash
|
|
102
|
+
nest-combo auth -m -s --no-spec
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Dry Run: Check What Would Be Generated
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
nest-combo products -m -c --dry-run
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Contributing
|
|
114
|
+
|
|
115
|
+
We welcome contributions! Here’s how you can help:
|
|
116
|
+
|
|
117
|
+
1. **Fork the repository** and clone it locally.
|
|
118
|
+
2. Create a new branch for your feature or bug fix:
|
|
119
|
+
```bash
|
|
120
|
+
git checkout -b feature/your-feature-name
|
|
121
|
+
```
|
|
122
|
+
3. Make your changes and ensure everything works as expected.
|
|
123
|
+
4. Commit your changes with a clear message:
|
|
124
|
+
```bash
|
|
125
|
+
git commit -m "Add feature: description of your changes"
|
|
126
|
+
```
|
|
127
|
+
5. Push your branch to GitHub:
|
|
128
|
+
```bash
|
|
129
|
+
git push origin feature/your-feature-name
|
|
130
|
+
```
|
|
131
|
+
6. Open a pull request on GitHub.
|
|
132
|
+
|
|
133
|
+
### Development Setup
|
|
134
|
+
|
|
135
|
+
1. Install dependencies:
|
|
136
|
+
```bash
|
|
137
|
+
npm install
|
|
138
|
+
```
|
|
139
|
+
2. Test your changes locally:
|
|
140
|
+
```bash
|
|
141
|
+
npm link
|
|
142
|
+
nest-combo users -m -c -s
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## License
|
|
148
|
+
|
|
149
|
+
This project is licensed under the **MIT License**. See the [LICENSE](LICENSE) file for details.
|
|
150
|
+
|
|
151
|
+
---
|
|
152
|
+
|
|
153
|
+
## Acknowledgments
|
|
154
|
+
|
|
155
|
+
- Built with ❤️ using [NestJS](https://nestjs.com/) and [Chalk](https://github.com/chalk/chalk).
|
|
156
|
+
- Inspired by the need for a faster and more efficient way to scaffold NestJS projects.
|
|
157
|
+
|
|
158
|
+
---
|
|
159
|
+
|
|
160
|
+
Feel free to customize this `README.md` further to match your project's specific details or add additional sections (e.g., FAQs, roadmap). Let me know if you need any modifications! 🚀
|
package/bin/cli.js
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import {
|
|
4
|
+
generateModule,
|
|
5
|
+
generateController,
|
|
6
|
+
generateService,
|
|
7
|
+
generateInterceptor,
|
|
8
|
+
generateGateway,
|
|
9
|
+
generateMiddlware,
|
|
10
|
+
} from "../lib/generate.js";
|
|
11
|
+
import { createRequire } from "module";
|
|
12
|
+
const require = createRequire(import.meta.url);
|
|
13
|
+
|
|
14
|
+
const args = process.argv.slice(2);
|
|
15
|
+
const resources = [
|
|
16
|
+
{
|
|
17
|
+
name: "module",
|
|
18
|
+
flag: "-m",
|
|
19
|
+
longFlag: "--module",
|
|
20
|
+
generator: generateModule,
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: "controller",
|
|
24
|
+
flag: "-c",
|
|
25
|
+
longFlag: "--controller",
|
|
26
|
+
generator: generateController,
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: "service",
|
|
30
|
+
flag: "-s",
|
|
31
|
+
longFlag: "--service",
|
|
32
|
+
generator: generateService,
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: "gateway",
|
|
36
|
+
flag: "-g",
|
|
37
|
+
longFlag: "--gateway",
|
|
38
|
+
generator: generateGateway,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: "middleware",
|
|
42
|
+
flag: "-mw",
|
|
43
|
+
longFlag: "--middleware",
|
|
44
|
+
generator: generateMiddlware,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
name: "interceptor",
|
|
48
|
+
flag: "-itc",
|
|
49
|
+
longFlag: "--interceptor",
|
|
50
|
+
generator: generateInterceptor,
|
|
51
|
+
},
|
|
52
|
+
];
|
|
53
|
+
|
|
54
|
+
function main() {
|
|
55
|
+
const { askForHelp, askForVersion, moduleName, hasDryRun, hasNoSpec } =
|
|
56
|
+
getArgs();
|
|
57
|
+
|
|
58
|
+
if (askForVersion) {
|
|
59
|
+
showVersion();
|
|
60
|
+
process.exit(0);
|
|
61
|
+
}
|
|
62
|
+
if (askForHelp) {
|
|
63
|
+
showUsage();
|
|
64
|
+
process.exit(0);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
validate(moduleName);
|
|
68
|
+
|
|
69
|
+
resources.forEach((component) => {
|
|
70
|
+
if (args.includes(component.flag) || args.includes(component.longFlag)) {
|
|
71
|
+
console.log(
|
|
72
|
+
chalk.green(`Generating ${component.name} for module ${moduleName}`)
|
|
73
|
+
);
|
|
74
|
+
if (component.generator) {
|
|
75
|
+
component.generator(moduleName, [
|
|
76
|
+
hasNoSpec ? "--no-spec" : null,
|
|
77
|
+
hasDryRun ? "--dry-run" : null,
|
|
78
|
+
]);
|
|
79
|
+
} else {
|
|
80
|
+
console.warn(
|
|
81
|
+
chalk.yellow(`Warning:`) +
|
|
82
|
+
` Generator not implemented for ${component.name}`
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
console.log(
|
|
86
|
+
chalk.green("---------------------------------------------------")
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function getArgs() {
|
|
93
|
+
const moduleName = args[0];
|
|
94
|
+
const askForVersion = args.includes("-v") || args.includes("--version");
|
|
95
|
+
const askForHelp = args.includes("-h") || args.includes("--help");
|
|
96
|
+
const hasNoSpec = args.includes("-ns") || args.includes("--no-spec");
|
|
97
|
+
const hasDryRun = args.includes("-dr") || args.includes("--dry-run");
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
moduleName,
|
|
101
|
+
askForVersion,
|
|
102
|
+
askForHelp,
|
|
103
|
+
hasNoSpec,
|
|
104
|
+
hasDryRun,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function showUsage() {
|
|
109
|
+
console.log(`
|
|
110
|
+
${chalk.yellow("Usage:")} nest-combo <module-name> [options]
|
|
111
|
+
|
|
112
|
+
${chalk.yellow("Options:")}
|
|
113
|
+
${chalk.cyan("-m, --module")} Generate a Module
|
|
114
|
+
${chalk.cyan("-c, --controller")} Generate a Controller
|
|
115
|
+
${chalk.cyan("-s, --service")} Generate a Service
|
|
116
|
+
${chalk.cyan("-g, --gateway")} Generate a Gateway
|
|
117
|
+
${chalk.cyan("-mw, --middleware")} Generate Middleware
|
|
118
|
+
${chalk.cyan("-itc, --interceptor")} Generate an Interceptor
|
|
119
|
+
|
|
120
|
+
${chalk.bgMagenta("Optional:")}
|
|
121
|
+
${chalk.cyan("-ns, --no-spec")} Do not generate spec (test) files
|
|
122
|
+
${chalk.cyan(
|
|
123
|
+
"-dr, --dry-run"
|
|
124
|
+
)} Report actions that would be taken without writing out results.
|
|
125
|
+
|
|
126
|
+
${chalk.yellow("Example:")}
|
|
127
|
+
nest-combo users -m -c -s
|
|
128
|
+
`);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function showVersion() {
|
|
132
|
+
const { name, version } = require("../package.json");
|
|
133
|
+
console.log(chalk.green(`${name} - version: ${version}`));
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
function validate(moduleName) {
|
|
137
|
+
if (!moduleName) {
|
|
138
|
+
console.error(chalk.red("Error:") + " Module name is required.");
|
|
139
|
+
showUsage();
|
|
140
|
+
process.exit(1);
|
|
141
|
+
}
|
|
142
|
+
const hasComponentFlags = resources.some(
|
|
143
|
+
(component) =>
|
|
144
|
+
args.includes(component.flag) || args.includes(component.longFlag)
|
|
145
|
+
);
|
|
146
|
+
|
|
147
|
+
if (!hasComponentFlags) {
|
|
148
|
+
console.error(
|
|
149
|
+
chalk.red("Error:") +
|
|
150
|
+
` At least one flag (${resources
|
|
151
|
+
.map((resource) => resource.flag)
|
|
152
|
+
.join(",")}) is required.`
|
|
153
|
+
);
|
|
154
|
+
showUsage();
|
|
155
|
+
process.exit(1);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
main();
|
package/lib/generate.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { execSync } from "child_process";
|
|
2
|
+
import { fileURLToPath } from "url";
|
|
3
|
+
import path from "path";
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
|
|
6
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
7
|
+
const __dirname = path.dirname(__filename);
|
|
8
|
+
|
|
9
|
+
const getNestBinary = () => {
|
|
10
|
+
try {
|
|
11
|
+
execSync("nest --version", { stdio: "ignore" });
|
|
12
|
+
console.log(
|
|
13
|
+
chalk.bgMagenta("*** Using global Nest CLI Installation *** \n")
|
|
14
|
+
);
|
|
15
|
+
return "nest";
|
|
16
|
+
} catch (error) {
|
|
17
|
+
console.log(
|
|
18
|
+
chalk.bgBlueBright("*** Using local Nest CLI Installation *** \n")
|
|
19
|
+
);
|
|
20
|
+
return path.join(__dirname, "../node_modules/.bin/nest");
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Generates a NestJS component (module, controller, service, etc.).
|
|
26
|
+
* @param {string} type - The type of component to generate (e.g., "mo", "co", "s").
|
|
27
|
+
* @param {string} moduleName - The name of the module to generate.
|
|
28
|
+
* @param {Object} options - Additional options for the command.
|
|
29
|
+
*/
|
|
30
|
+
const generateComponent = (type, moduleName, options) => {
|
|
31
|
+
const command = `${nest} g ${type} ${moduleName} ${options.join(" ")}`;
|
|
32
|
+
// console.log(`Running command: ${command}`);
|
|
33
|
+
execSync(command, { stdio: "inherit" });
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export const generateModule = (moduleName, options) =>
|
|
37
|
+
generateComponent("mo", moduleName, options);
|
|
38
|
+
|
|
39
|
+
export const generateController = (moduleName, options) =>
|
|
40
|
+
generateComponent("co", moduleName, options);
|
|
41
|
+
|
|
42
|
+
export const generateService = (moduleName, options) =>
|
|
43
|
+
generateComponent("s", moduleName, options);
|
|
44
|
+
|
|
45
|
+
export const generateGateway = (moduleName, options) =>
|
|
46
|
+
generateComponent("ga", moduleName, options);
|
|
47
|
+
|
|
48
|
+
export const generateInterceptor = (moduleName, options) =>
|
|
49
|
+
generateComponent("itc", moduleName, options);
|
|
50
|
+
|
|
51
|
+
export const generateMiddlware = (moduleName, options) =>
|
|
52
|
+
generateComponent("mi", moduleName, options);
|
|
53
|
+
|
|
54
|
+
const nest = getNestBinary();
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "nest-combo",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "lib/generate.js",
|
|
5
|
+
"description": "A CLI tool to generate NestJS modules, controllers, and services, etc in horizontal.",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"nest-combo": "bin/cli.js"
|
|
9
|
+
},
|
|
10
|
+
"directories": {
|
|
11
|
+
"lib": "lib"
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"nestjs",
|
|
18
|
+
"cli",
|
|
19
|
+
"generator",
|
|
20
|
+
"module",
|
|
21
|
+
"controller",
|
|
22
|
+
"service"
|
|
23
|
+
],
|
|
24
|
+
"author": "ViniBr",
|
|
25
|
+
"license": "MIT",
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@nestjs/cli": "^11.0.5",
|
|
28
|
+
"chalk": "^5.4.1"
|
|
29
|
+
}
|
|
30
|
+
}
|