nest-combo 1.1.1 → 1.2.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/README.MD +114 -10
- package/bin/cli.js +2 -5
- package/demo.mp4 +0 -0
- package/index.html +27 -0
- package/lib/install.js +11 -5
- package/lib/utils.js +0 -9
- package/package.json +1 -1
- package/project.example.yml +5 -5
package/README.MD
CHANGED
|
@@ -19,20 +19,57 @@ A CLI tool to generate NestJS modules, controllers, services, and other componen
|
|
|
19
19
|
|
|
20
20
|
---
|
|
21
21
|
|
|
22
|
-
## How
|
|
22
|
+
## How It Works
|
|
23
23
|
|
|
24
|
-
How Nest-Combo Works with NestJS CLI
|
|
24
|
+
### How Nest-Combo Works with NestJS CLI
|
|
25
25
|
|
|
26
|
-
If you have the NestJS CLI installed globally
|
|
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
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
|
-
|
|
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
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
### Key Features of Nest-Combo
|
|
33
|
+
|
|
34
|
+
#### 1. **Importing a YAML File for Project Scaffolding**
|
|
35
|
+
|
|
36
|
+
With **nest-combo**, you can define an entire project structure in a `project.yml` file and let **nest-combo** handle the scaffolding process for you. Simply specify your modules, resources, dependencies, and optional flags in the YAML file, and **nest-combo** will generate the entire project automatically.
|
|
37
|
+
|
|
38
|
+
This feature encourages thoughtful planning and allows you to automate repetitive tasks, saving you time and effort. Additionally, **nest-combo** supports **recursive logic** for creating nested modules, ensuring that even complex project structures are generated accurately.
|
|
39
|
+
|
|
40
|
+
For example, you can define deeply nested modules like this:
|
|
41
|
+
|
|
42
|
+
```yaml
|
|
43
|
+
modules:
|
|
44
|
+
- name: core
|
|
45
|
+
resources:
|
|
46
|
+
- module
|
|
47
|
+
modules:
|
|
48
|
+
- name: user
|
|
49
|
+
resources:
|
|
50
|
+
- module
|
|
51
|
+
- controller
|
|
52
|
+
- service
|
|
53
|
+
options:
|
|
54
|
+
- --no-spec
|
|
55
|
+
modules:
|
|
56
|
+
- name: subUsers
|
|
57
|
+
resources:
|
|
58
|
+
- module
|
|
59
|
+
- controller
|
|
60
|
+
- service
|
|
61
|
+
options:
|
|
62
|
+
- --no-spec
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
This recursive approach ensures that all parent and child modules are created with proper imports and dependencies.
|
|
30
66
|
|
|
31
67
|
---
|
|
32
68
|
|
|
33
69
|
## Features
|
|
34
70
|
|
|
35
|
-
-
|
|
71
|
+
- Load a full project from a YAML file.
|
|
72
|
+
- Generate NestJS modules, controllers, services, gateways, middleware, and interceptors with a single-line command.
|
|
36
73
|
- Support for optional flags like `--no-spec` and `--dry-run`.
|
|
37
74
|
- Colorful and user-friendly output using `chalk`.
|
|
38
75
|
- Easy-to-use command-line interface.
|
|
@@ -63,14 +100,20 @@ Run the CLI tool with the desired module name and options:
|
|
|
63
100
|
nest-combo <module-name> [options]
|
|
64
101
|
```
|
|
65
102
|
|
|
66
|
-
### Example
|
|
103
|
+
### Example Commands
|
|
67
104
|
|
|
68
|
-
|
|
105
|
+
#### Create a Module, Controller, and Service in a Single Line
|
|
69
106
|
|
|
70
107
|
```bash
|
|
71
108
|
nest-combo users -m -c -s
|
|
72
109
|
```
|
|
73
110
|
|
|
111
|
+
#### Create a Full Project from a YAML File
|
|
112
|
+
|
|
113
|
+
```bash
|
|
114
|
+
nest-combo -f project.yml
|
|
115
|
+
```
|
|
116
|
+
|
|
74
117
|
---
|
|
75
118
|
|
|
76
119
|
## Options
|
|
@@ -85,11 +128,72 @@ nest-combo users -m -c -s
|
|
|
85
128
|
| `-itc, --interceptor` | Generate an interceptor |
|
|
86
129
|
| `-ns, --no-spec` | Do not generate `.spec.ts` test files |
|
|
87
130
|
| `-dr, --dry-run` | Report actions that would be taken without writing out results |
|
|
131
|
+
| `-f, --file` | Create a project from a YAML file |
|
|
132
|
+
|
|
133
|
+
---
|
|
134
|
+
|
|
135
|
+
### YAML Example for Loading a Full Project from Scratch
|
|
136
|
+
|
|
137
|
+
```yaml
|
|
138
|
+
# YML example for loading a full project from scratch
|
|
139
|
+
nest-combo:
|
|
140
|
+
project-name: my-new-project
|
|
141
|
+
open-vscode: true # Open VSCode when the process is finished
|
|
142
|
+
package-manager: npm # npm | yarn | pnpm
|
|
143
|
+
dependencies:
|
|
144
|
+
- "@nestjs/config"
|
|
145
|
+
- "@nestjs/bull"
|
|
146
|
+
- "class-transformer"
|
|
147
|
+
- "class-validator"
|
|
148
|
+
- "nestjs-twilio"
|
|
149
|
+
modules:
|
|
150
|
+
- name: core
|
|
151
|
+
resources:
|
|
152
|
+
- module
|
|
153
|
+
modules:
|
|
154
|
+
- name: user
|
|
155
|
+
resources:
|
|
156
|
+
- module
|
|
157
|
+
- controller
|
|
158
|
+
- service
|
|
159
|
+
options:
|
|
160
|
+
- --no-spec
|
|
161
|
+
modules:
|
|
162
|
+
- name: subUsers
|
|
163
|
+
resources:
|
|
164
|
+
- module
|
|
165
|
+
- controller
|
|
166
|
+
- service
|
|
167
|
+
options:
|
|
168
|
+
- --no-spec
|
|
169
|
+
- name: auth
|
|
170
|
+
resources:
|
|
171
|
+
- module
|
|
172
|
+
- controller
|
|
173
|
+
- service
|
|
174
|
+
- interceptor
|
|
175
|
+
- name: product
|
|
176
|
+
resources:
|
|
177
|
+
- module
|
|
178
|
+
- controller
|
|
179
|
+
- service
|
|
180
|
+
- name: payment
|
|
181
|
+
resources:
|
|
182
|
+
- module
|
|
183
|
+
- controller
|
|
184
|
+
- service
|
|
185
|
+
```
|
|
88
186
|
|
|
89
187
|
---
|
|
90
188
|
|
|
91
189
|
## Examples
|
|
92
190
|
|
|
191
|
+
### Create a Full Project from a YAML File
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
nest-combo -f project.yml
|
|
195
|
+
```
|
|
196
|
+
|
|
93
197
|
### Generate a Module, Controller, and Service
|
|
94
198
|
|
|
95
199
|
```bash
|
|
@@ -99,13 +203,13 @@ nest-combo users -m -c -s
|
|
|
99
203
|
### Generate a Module and Service Without Spec Files
|
|
100
204
|
|
|
101
205
|
```bash
|
|
102
|
-
nest-combo auth -m -s --
|
|
206
|
+
nest-combo auth -m -s --ns
|
|
103
207
|
```
|
|
104
208
|
|
|
105
209
|
### Dry Run: Check What Would Be Generated
|
|
106
210
|
|
|
107
211
|
```bash
|
|
108
|
-
nest-combo products -m -c --
|
|
212
|
+
nest-combo products -m -c --dr
|
|
109
213
|
```
|
|
110
214
|
|
|
111
215
|
---
|
package/bin/cli.js
CHANGED
|
@@ -124,8 +124,6 @@ function getArgs() {
|
|
|
124
124
|
const hasNoSpec = args.includes("-ns") || args.includes("--no-spec");
|
|
125
125
|
const hasDryRun = args.includes("-dr") || args.includes("--dry-run");
|
|
126
126
|
const hasYmlFile = args.includes("-f") || args.includes("--file");
|
|
127
|
-
const validateYmlFile =
|
|
128
|
-
args.includes("-vf") || args.includes("--validate-yml");
|
|
129
127
|
|
|
130
128
|
return {
|
|
131
129
|
moduleName,
|
|
@@ -149,8 +147,7 @@ ${chalk.yellow("Options:")}
|
|
|
149
147
|
${chalk.cyan("-g, --gateway")} Generate a Gateway
|
|
150
148
|
${chalk.cyan("-mw, --middleware")} Generate Middleware
|
|
151
149
|
${chalk.cyan("-itc, --interceptor")} Generate an Interceptor
|
|
152
|
-
${chalk.cyan("-f, --file")} Generate project from yml file
|
|
153
|
-
${chalk.cyan("-vf, --validate-yml")} Validate Yml File
|
|
150
|
+
${chalk.cyan("-f, --file")} Generate project from yml file
|
|
154
151
|
|
|
155
152
|
${chalk.bgMagenta("Optional:")}
|
|
156
153
|
${chalk.cyan("-ns, --no-spec")} Do not generate spec (test) files
|
|
@@ -212,7 +209,7 @@ function loadFromYml(file) {
|
|
|
212
209
|
generateProject(projectName, [`-p ${packageManager}`]);
|
|
213
210
|
|
|
214
211
|
if (dependencies.length > 0) {
|
|
215
|
-
console.log(chalk.
|
|
212
|
+
console.log(chalk.cyan("Installing dependencies..."));
|
|
216
213
|
installDependencies(projectName, dependencies);
|
|
217
214
|
} else {
|
|
218
215
|
console.log(chalk.yellow("No dependencies to install."));
|
package/demo.mp4
ADDED
|
Binary file
|
package/index.html
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>Video Demo</title>
|
|
7
|
+
<style>
|
|
8
|
+
body {
|
|
9
|
+
font-family: Arial, sans-serif;
|
|
10
|
+
text-align: center;
|
|
11
|
+
margin-top: 50px;
|
|
12
|
+
}
|
|
13
|
+
video {
|
|
14
|
+
max-width: 100%;
|
|
15
|
+
height: auto;
|
|
16
|
+
}
|
|
17
|
+
</style>
|
|
18
|
+
</head>
|
|
19
|
+
<body>
|
|
20
|
+
<h1>Video Demo</h1>
|
|
21
|
+
<video controls>
|
|
22
|
+
<source src="./demo.mp4" type="video/mp4" />
|
|
23
|
+
Your browser does not support the video tag.
|
|
24
|
+
</video>
|
|
25
|
+
<p>Watch the demo video above.</p>
|
|
26
|
+
</body>
|
|
27
|
+
</html>
|
package/lib/install.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import chalk from "chalk";
|
|
1
2
|
import { execSync } from "child_process";
|
|
2
3
|
import path from "path";
|
|
3
4
|
function installDependencies(projectName, dependencies) {
|
|
@@ -5,11 +6,16 @@ function installDependencies(projectName, dependencies) {
|
|
|
5
6
|
const workingDirectory = path.join(process.cwd(), projectName);
|
|
6
7
|
|
|
7
8
|
execSync(cdCommand, { stdio: "inherit" });
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
try {
|
|
10
|
+
if (Array.isArray(dependencies)) {
|
|
11
|
+
for (const depency of dependencies) {
|
|
12
|
+
chalk.cyan(`- ${depency}`);
|
|
13
|
+
}
|
|
14
|
+
const command = `npm i ${dependencies.join(" ")}`;
|
|
15
|
+
execSync(command, { stdio: "inherit", cwd: workingDirectory });
|
|
16
|
+
}
|
|
17
|
+
} catch (error) {
|
|
18
|
+
chalk.red(`Error installing dependencies`);
|
|
13
19
|
}
|
|
14
20
|
}
|
|
15
21
|
|
package/lib/utils.js
CHANGED
|
@@ -28,15 +28,6 @@ export function validateYml(ymlData) {
|
|
|
28
28
|
if (nestCombo.dependencies && !Array.isArray(nestCombo.dependencies)) {
|
|
29
29
|
throw new Error("Invalid 'dependencies'. Must be an array.");
|
|
30
30
|
}
|
|
31
|
-
if (nestCombo.dependencies) {
|
|
32
|
-
nestCombo.dependencies.forEach((dep, index) => {
|
|
33
|
-
if (!dep.name || typeof dep.name !== "string") {
|
|
34
|
-
throw new Error(
|
|
35
|
-
`Invalid dependency at index ${index}. Each dependency must have a 'name' field as a string.`
|
|
36
|
-
);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
31
|
|
|
41
32
|
if (nestCombo.modules && !Array.isArray(nestCombo.modules)) {
|
|
42
33
|
throw new Error("Invalid 'modules'. Must be an array.");
|
package/package.json
CHANGED
package/project.example.yml
CHANGED
|
@@ -4,11 +4,11 @@ nest-combo:
|
|
|
4
4
|
open-vscode: true # open vscode when process is finished
|
|
5
5
|
package-manager: npm # npm | yarn | pnmp
|
|
6
6
|
dependencies:
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
7
|
+
- "@nestjs/config"
|
|
8
|
+
- "@nestjs/bull"
|
|
9
|
+
- "class-transformer"
|
|
10
|
+
- "class-validator"
|
|
11
|
+
- "nestjs-twilio"
|
|
12
12
|
modules:
|
|
13
13
|
- name: core
|
|
14
14
|
resources:
|