nodejs-quickstart-structure 1.16.2 ā 1.18.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/CHANGELOG.md +25 -0
- package/LICENSE +15 -0
- package/README.md +144 -135
- package/bin/index.js +92 -89
- package/lib/generator.js +3 -2
- package/lib/modules/app-setup.js +49 -12
- package/lib/modules/caching-setup.js +1 -1
- package/lib/modules/config-files.js +32 -3
- package/lib/modules/database-setup.js +2 -2
- package/lib/modules/kafka-setup.js +8 -8
- package/lib/prompts.js +16 -1
- package/package.json +14 -2
- package/templates/clean-architecture/ts/src/index.ts.ejs +1 -2
- package/templates/common/.cursorrules.ejs +1 -1
- package/templates/common/.env.example.ejs +1 -1
- package/templates/common/.gitlab-ci.yml.ejs +55 -4
- package/templates/common/Dockerfile +12 -2
- package/templates/common/Jenkinsfile.ejs +32 -21
- package/templates/common/README.md.ejs +19 -9
- package/templates/common/SECURITY.md +20 -0
- package/templates/common/_github/workflows/{ci.yml ā ci.yml.ejs} +13 -7
- package/templates/common/_github/workflows/security.yml.ejs +36 -0
- package/templates/common/_husky/pre-commit +4 -0
- package/templates/common/caching/js/redisClient.spec.js.ejs +0 -2
- package/templates/common/docker-compose.yml.ejs +13 -20
- package/templates/common/ecosystem.config.js.ejs +1 -1
- package/templates/common/jest.config.js.ejs +1 -0
- package/templates/common/jest.e2e.config.js.ejs +8 -0
- package/templates/common/kafka/js/config/kafka.js +2 -1
- package/templates/common/kafka/js/config/kafka.spec.js.ejs +6 -0
- package/templates/common/kafka/ts/config/kafka.spec.ts.ejs +6 -0
- package/templates/common/kafka/ts/config/kafka.ts +2 -1
- package/templates/common/package.json.ejs +14 -9
- package/templates/common/prompts/add-feature.md.ejs +1 -1
- package/templates/common/prompts/project-context.md.ejs +1 -1
- package/templates/common/scripts/run-e2e.js.ejs +63 -0
- package/templates/common/sonar-project.properties.ejs +27 -0
- package/templates/common/src/tests/e2e/e2e.users.test.js.ejs +49 -0
- package/templates/common/src/tests/e2e/e2e.users.test.ts.ejs +49 -0
- package/templates/mvc/js/src/index.js.ejs +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,31 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [1.18.0] - 2026-03-25
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- **Enterprise-Grade Security Hardening**: Integrated **Snyk (SCA)** and **SonarQube (SAST)** into the project scaffolding, providing "Big Tech" industry-standard security analysis out of the box.
|
|
12
|
+
- **Automated Security Workflows**: Pre-configured CI/CD stages for security scanning across GitHub Actions, GitLab CI, and Jenkins.
|
|
13
|
+
- **Pre-commit Security Gates**: Integrated **Husky** and **lint-staged** to automatically enforce code quality and security standards locally before every commit.
|
|
14
|
+
- **Security Standard Enforcement**: Added a standardized `SECURITY.md` policy and automated quality gates to ensure code resilience.
|
|
15
|
+
- **Comprehensive Security Guide**: Created a new documentation guide detailing the setup and operational workflows for the enterprise security features.
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
- **Matrix Expansion**: Updated the CLI to support over **1,680+ project combinations** by adding a conditional security hardening layer across all CI/CD providers.
|
|
19
|
+
|
|
20
|
+
### Fixed
|
|
21
|
+
- **Docker Node Version**: Updated Docker node version to 22.22.2-trixie-slim
|
|
22
|
+
|
|
23
|
+
## [1.17.0] - 2026-03-23
|
|
24
|
+
|
|
25
|
+
### Added
|
|
26
|
+
- **Kafka KRaft Mode Integration**: Modernized Kafka setups across all templates (MVC & Clean Architecture) by completely removing the Zookeeper dependency and enabling KRaft mode in `docker-compose.yml`, reducing project orchestration overhead.
|
|
27
|
+
- **End-to-End (E2E) Verification Framework**: Implemented dedicated Docker container targeted end-to-end tests (`tests/e2e/`) utilizing Supertest via dynamic `SERVER_URL` mapping to eliminate port collisions and test the fully assembled container cluster directly.
|
|
28
|
+
- **Enhanced Validation Pipelines**: Automatically executes the `npm run test:e2e` suite at the conclusion of internal validations across the entire platform matrix for improved CI accountability.
|
|
29
|
+
|
|
30
|
+
### Refactored
|
|
31
|
+
- **Test Directory Strict Isolation**: Restructured internal code generation workflows (`lib/modules/`) to pipe all generated `.spec` files strictly into a dedicated `tests/unit/` subdirectory, cleanly abstracting unit specifications from end-to-end specifications.
|
|
32
|
+
|
|
8
33
|
## [1.16.2] - 2026-03-19
|
|
9
34
|
|
|
10
35
|
### Changed
|
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Pau Dang
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,135 +1,144 @@
|
|
|
1
|
-
# Node.js Quickstart Generator
|
|
2
|
-
|
|
3
|
-
[](https://www.npmjs.com/package/nodejs-quickstart-structure)
|
|
4
|
-
[](https://www.npmjs.com/package/nodejs-quickstart-structure)
|
|
6
|
-
[](https://opensource.org/licenses/ISC)
|
|
7
|
-
|
|
8
|
-
A powerful CLI tool to scaffold production-ready Node.js microservices with built-in best practices, allowing you to choose between **MVC** or **Clean Architecture**, **JavaScript** or **TypeScript**, and your preferred database.
|
|
9
|
-
|
|
10
|
-

|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
-
|
|
17
|
-
-
|
|
18
|
-
-
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
#
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
##
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
1
|
+
# Node.js Quickstart Generator
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/nodejs-quickstart-structure)
|
|
4
|
+
[](https://www.npmjs.com/package/nodejs-quickstart-structure)
|
|
5
|
+
[](https://www.npmjs.com/package/nodejs-quickstart-structure)
|
|
6
|
+
[](https://opensource.org/licenses/ISC)
|
|
7
|
+
|
|
8
|
+
A powerful CLI tool to scaffold production-ready Node.js microservices with built-in best practices, allowing you to choose between **MVC** or **Clean Architecture**, **JavaScript** or **TypeScript**, and your preferred database.
|
|
9
|
+
|
|
10
|
+

|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## š Table of Contents
|
|
15
|
+
|
|
16
|
+
- [š Quick Start](#-quick-start)
|
|
17
|
+
- [⨠Key Features](#-key-features)
|
|
18
|
+
- [š”ļø Professional Standards](#-professional-standards)
|
|
19
|
+
- [š§© 1,680+ Project Combinations](#-1680-project-combinations)
|
|
20
|
+
- [āļø Configuration Options](#-configuration-options)
|
|
21
|
+
- [šļø Generated Project Structure](#-generated-project-structure)
|
|
22
|
+
- [š Documentation](#-documentation)
|
|
23
|
+
- [šŗļø Roadmap & Support](#ļø-roadmap--support)
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## š Quick Start
|
|
28
|
+
|
|
29
|
+
Generate your professional Node.js project in seconds without installing anything globally:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npx nodejs-quickstart-structure@latest init
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Installation (Optional)
|
|
36
|
+
|
|
37
|
+
If you prefer to install it globally:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
npm install -g nodejs-quickstart-structure
|
|
41
|
+
# Then run:
|
|
42
|
+
nodejs-quickstart init
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
---
|
|
46
|
+
|
|
47
|
+
## ⨠Key Features
|
|
48
|
+
|
|
49
|
+
- **Interactive CLI**: Smooth, guided configuration process.
|
|
50
|
+
- **Multiple Architectures**: Supports both **MVC** and **Clean Architecture**.
|
|
51
|
+
- **Modern Languages**: Choice of **JavaScript** or **TypeScript**.
|
|
52
|
+
- **Database Ready**: Pre-configured for **MySQL**, **PostgreSQL**, or **MongoDB**.
|
|
53
|
+
- **Communication Patterns**: Supports **REST**, **GraphQL** (Apollo), and **Kafka** (Event-driven).
|
|
54
|
+
- **Multi-layer Caching**: Integrated **Redis** or built-in **Memory Cache**.
|
|
55
|
+
- **AI-Native Optimized**: specifically designed for **Cursor** and AI agents, including built-in `.cursorrules` and Agent Skill prompts. š
|
|
56
|
+
|
|
57
|
+
---
|
|
58
|
+
|
|
59
|
+
## š”ļø Professional Standards
|
|
60
|
+
|
|
61
|
+
We don't just generate boilerplate; we generate **production-ready** foundations. Every project includes:
|
|
62
|
+
|
|
63
|
+
- **š Code Quality**: Pre-configured `Eslint` and `Prettier`.
|
|
64
|
+
- **š”ļø Enterprise Security**: Integrated **Snyk (SCA)**, **SonarCloud (SAST)**, `Helmet`, `HPP`, and Rate-Limiting.
|
|
65
|
+
- **šØ Robust Error Handling**: Centralized global error middleware with custom error classes (`ApiError`, `NotFoundError`, etc.) ā consistent across REST & GraphQL.
|
|
66
|
+
- **š§Ŗ Testing Excellence**: Integrated `Jest` and `Supertest` with **>80% Unit Test coverage** out of the box.
|
|
67
|
+
- **š DevOps & CI/CD**: Optimized **Multi-Stage Dockerfiles**, health checks, infrastructure retry logic, and workflows for **GitHub Actions**, **Jenkins**, and **GitLab CI**.
|
|
68
|
+
- **š Scalable Deployment**: Integrated **PM2 Ecosystem** config for zero-downtime reloads.
|
|
69
|
+
|
|
70
|
+
---
|
|
71
|
+
|
|
72
|
+
## š§© 1,680+ Project Combinations
|
|
73
|
+
|
|
74
|
+
The CLI supports a massive number of configurations to fit your exact needs:
|
|
75
|
+
|
|
76
|
+
- **240 Core Combinations**:
|
|
77
|
+
- **MVC Architecture**: 180 variants (Languages Ć View Engines Ć Databases Ć Communication Patterns Ć Caching)
|
|
78
|
+
- **Clean Architecture**: 60 variants (Languages Ć Databases Ć Communication Patterns Ć Caching)
|
|
79
|
+
- **1,680+ Total Scenarios**:
|
|
80
|
+
- Every combination can be generated across 3 CI/CD providers.
|
|
81
|
+
- Optional **Enterprise-Grade Security Hardening** doubles the scenarios.
|
|
82
|
+
- Every single scenario is verified to be compatible with our **80% Coverage Threshold** policy.
|
|
83
|
+
|
|
84
|
+
---
|
|
85
|
+
|
|
86
|
+
## āļø Configuration Options
|
|
87
|
+
|
|
88
|
+
The CLI will guide you through:
|
|
89
|
+
1. **Project Name**
|
|
90
|
+
2. **Language**: `JavaScript` | `TypeScript`
|
|
91
|
+
3. **Architecture**: `MVC` | `Clean Architecture`
|
|
92
|
+
4. **View Engine**: (MVC only) `None` | `EJS` | `Pug`
|
|
93
|
+
5. **Database**: `MySQL` | `PostgreSQL` | `MongoDB`
|
|
94
|
+
6. **Communication**: `REST` | `GraphQL` | `Kafka`
|
|
95
|
+
7. **Caching**: `None` | `Redis` | `Memory Cache`
|
|
96
|
+
8. **CI/CD**: `GitHub Actions` | `Jenkins` | `GitLab CI`
|
|
97
|
+
9. **Security**: (Optional) Snyk & SonarCloud Hardening
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## šļø Generated Project Structure
|
|
102
|
+
|
|
103
|
+
A typical generated project (TypeScript + Clean Architecture) looks like this:
|
|
104
|
+
|
|
105
|
+
```text
|
|
106
|
+
.
|
|
107
|
+
āāā src/
|
|
108
|
+
ā āāā application/ # Use cases & Business logic
|
|
109
|
+
ā āāā domain/ # Entities & Repository interfaces
|
|
110
|
+
ā āāā infrastructure/ # DB, External services, Repositories
|
|
111
|
+
ā āāā interfaces/ # Controllers, Routes, GraphQL, Kafka
|
|
112
|
+
ā āāā errors/ # Custom Error Classes
|
|
113
|
+
ā āāā index.ts # Entry point
|
|
114
|
+
āāā flyway/sql/ # SQL migrations (if applicable)
|
|
115
|
+
āāā docker-compose.yml # Infrastructure services
|
|
116
|
+
āāā package.json # Scripts and dependencies
|
|
117
|
+
āāā tsconfig.json # TypeScript config
|
|
118
|
+
āāā .cursorrules # AI assistance rules
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
---
|
|
122
|
+
|
|
123
|
+
## š Documentation
|
|
124
|
+
|
|
125
|
+
For full guides, architecture deep-dives, and feature references, visit our **[Official Documentation Site](https://paudang.github.io/nodejs-quickstart-structure/)**.
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
## ā¤ļø Support & šŗļø Roadmap
|
|
130
|
+
|
|
131
|
+
### Support the Project
|
|
132
|
+
We just hit **3,000+ downloads**! If this tool helped you, please:
|
|
133
|
+
- Give us a ā on [GitHub](https://github.com/paudang/nodejs-quickstart-structure).
|
|
134
|
+
- Read our [Medium Article](https://medium.com/@paudang/nodejs-quickstart-generator-93c276d60e0b) for tutorials.
|
|
135
|
+
|
|
136
|
+
### Roadmap
|
|
137
|
+
Track our progress and vote for features on our public board:
|
|
138
|
+
š **[View our Public Roadmap on Trello](https://trello.com/b/TPTo8ylF/nodejs-quickstart-structure-product)**
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
ISC
|
package/bin/index.js
CHANGED
|
@@ -1,89 +1,92 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
import { Command } from 'commander';
|
|
4
|
-
import chalk from 'chalk';
|
|
5
|
-
import { getProjectDetails } from '../lib/prompts.js';
|
|
6
|
-
import { generateProject } from '../lib/generator.js';
|
|
7
|
-
import { readFileSync } from 'fs';
|
|
8
|
-
import { join, dirname } from 'path';
|
|
9
|
-
import { fileURLToPath } from 'url';
|
|
10
|
-
|
|
11
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
12
|
-
const pkg = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf-8'));
|
|
13
|
-
|
|
14
|
-
const program = new Command();
|
|
15
|
-
|
|
16
|
-
program
|
|
17
|
-
.name('nodejs-quickstart')
|
|
18
|
-
.description('š CLI to scaffold production-ready Node.js microservices.\n\nGenerates projects with:\n- MVC or Clean Architecture\n- REST or Kafka\n- MySQL, PostgreSQL, or MongoDB\n- Docker, Flyway & Mongoose support')
|
|
19
|
-
.version(pkg.version, '-v, --version', 'Output the current version')
|
|
20
|
-
.addHelpText('after', `\n${chalk.yellow('Example:')}\n $ nodejs-quickstart init ${chalk.gray('# Start the interactive setup')}\n`);
|
|
21
|
-
|
|
22
|
-
program
|
|
23
|
-
.command('init')
|
|
24
|
-
.description('Initialize a new Node.js project')
|
|
25
|
-
.option('-n, --project-name <name>', 'Project name')
|
|
26
|
-
.option('-l, --language <language>', 'Language (JavaScript, TypeScript)')
|
|
27
|
-
.option('-a, --architecture <architecture>', 'Architecture (MVC, Clean Architecture)')
|
|
28
|
-
.option('--view-engine <view>', 'View Engine (None, EJS, Pug) - MVC only')
|
|
29
|
-
.option('-d, --database <database>', 'Database (MySQL, PostgreSQL)')
|
|
30
|
-
.option('--db-name <name>', 'Database name')
|
|
31
|
-
.option('-c, --communication <communication>', 'Communication (REST APIs, GraphQL, Kafka)')
|
|
32
|
-
.option('--ci-provider <provider>', 'CI/CD Provider (None, GitHub Actions, Jenkins)')
|
|
33
|
-
.option('--
|
|
34
|
-
.
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
console.log(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
console.log(chalk.magenta('
|
|
54
|
-
console.log(chalk.magenta('
|
|
55
|
-
console.log(chalk.magenta(
|
|
56
|
-
console.log(chalk.magenta(`š Use
|
|
57
|
-
console.log(chalk.magenta('
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (answers.
|
|
67
|
-
if (answers.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
manualStartInstructions += `\n npm run dev`;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
import chalk from 'chalk';
|
|
5
|
+
import { getProjectDetails } from '../lib/prompts.js';
|
|
6
|
+
import { generateProject } from '../lib/generator.js';
|
|
7
|
+
import { readFileSync } from 'fs';
|
|
8
|
+
import { join, dirname } from 'path';
|
|
9
|
+
import { fileURLToPath } from 'url';
|
|
10
|
+
|
|
11
|
+
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
12
|
+
const pkg = JSON.parse(readFileSync(join(__dirname, '../package.json'), 'utf-8'));
|
|
13
|
+
|
|
14
|
+
const program = new Command();
|
|
15
|
+
|
|
16
|
+
program
|
|
17
|
+
.name('nodejs-quickstart')
|
|
18
|
+
.description('š CLI to scaffold production-ready Node.js microservices.\n\nGenerates projects with:\n- MVC or Clean Architecture\n- REST or Kafka\n- MySQL, PostgreSQL, or MongoDB\n- Docker, Flyway & Mongoose support')
|
|
19
|
+
.version(pkg.version, '-v, --version', 'Output the current version')
|
|
20
|
+
.addHelpText('after', `\n${chalk.yellow('Example:')}\n $ nodejs-quickstart init ${chalk.gray('# Start the interactive setup')}\n`);
|
|
21
|
+
|
|
22
|
+
program
|
|
23
|
+
.command('init')
|
|
24
|
+
.description('Initialize a new Node.js project')
|
|
25
|
+
.option('-n, --project-name <name>', 'Project name')
|
|
26
|
+
.option('-l, --language <language>', 'Language (JavaScript, TypeScript)')
|
|
27
|
+
.option('-a, --architecture <architecture>', 'Architecture (MVC, Clean Architecture)')
|
|
28
|
+
.option('--view-engine <view>', 'View Engine (None, EJS, Pug) - MVC only')
|
|
29
|
+
.option('-d, --database <database>', 'Database (MySQL, PostgreSQL)')
|
|
30
|
+
.option('--db-name <name>', 'Database name')
|
|
31
|
+
.option('-c, --communication <communication>', 'Communication (REST APIs, GraphQL, Kafka)')
|
|
32
|
+
.option('--ci-provider <provider>', 'CI/CD Provider (None, GitHub Actions, Jenkins, GitLab CI)')
|
|
33
|
+
.option('--include-security', 'Include Enterprise Security Hardening')
|
|
34
|
+
.option('--caching <type>', 'Caching Layer (None/Redis)')
|
|
35
|
+
.action(async (options) => {
|
|
36
|
+
// Fix for Commander camelCase conversion
|
|
37
|
+
if (options.ciProvider) {
|
|
38
|
+
options.ciProvider = options.ciProvider;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
console.log(chalk.blue('Welcome to the Node.js Quickstart Generator!'));
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
const answers = await getProjectDetails(options);
|
|
45
|
+
console.log(chalk.green('\nConfiguration received:'));
|
|
46
|
+
console.log(JSON.stringify(answers, null, 2));
|
|
47
|
+
|
|
48
|
+
console.log(chalk.yellow('\nGenerating project...'));
|
|
49
|
+
await generateProject(answers);
|
|
50
|
+
|
|
51
|
+
console.log(chalk.green('\nā Project generated successfully!'));
|
|
52
|
+
|
|
53
|
+
console.log(chalk.magenta('\nš Project is AI-Ready!'));
|
|
54
|
+
console.log(chalk.magenta('-----------------------------------------'));
|
|
55
|
+
console.log(chalk.magenta('š¤ We detected you are using AI tools.'));
|
|
56
|
+
console.log(chalk.magenta(`š Use Cursor? We've configured '.cursorrules' for you.`));
|
|
57
|
+
console.log(chalk.magenta(`š Use ChatGPT/Gemini? Check the 'prompts/' folder for Agent Skills.`));
|
|
58
|
+
console.log(chalk.magenta('-----------------------------------------'));
|
|
59
|
+
|
|
60
|
+
let manualStartInstructions = `\n${chalk.yellow('Development:')}\n cd ${answers.projectName}\n npm install`;
|
|
61
|
+
|
|
62
|
+
const needsInfrastructure = answers.database !== 'None' || answers.caching === 'Redis' || answers.communication === 'Kafka';
|
|
63
|
+
|
|
64
|
+
if (needsInfrastructure) {
|
|
65
|
+
let servicesToStart = '';
|
|
66
|
+
if (answers.database === 'MongoDB') servicesToStart += ' db';
|
|
67
|
+
else if (answers.database !== 'None') servicesToStart += ' db flyway';
|
|
68
|
+
if (answers.caching === 'Redis') servicesToStart += ' redis';
|
|
69
|
+
if (answers.communication === 'Kafka') servicesToStart += ' kafka';
|
|
70
|
+
|
|
71
|
+
manualStartInstructions += `\n docker-compose up -d${servicesToStart} # Start infrastructure first\n npm run dev`;
|
|
72
|
+
} else {
|
|
73
|
+
manualStartInstructions += `\n npm run dev`;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
console.log(chalk.cyan(`\nNext steps:\n cd ${answers.projectName}\n npm install\n docker-compose up\n-----------------------${manualStartInstructions}\n\n${chalk.yellow('Production (PM2):')}\n npm run build\n npm run deploy\n npx pm2 logs`));
|
|
77
|
+
|
|
78
|
+
} catch (error) {
|
|
79
|
+
if (error.name === 'ExitPromptError') {
|
|
80
|
+
console.log(chalk.yellow('\n\nš Goodbye! Setup cancelled.'));
|
|
81
|
+
process.exit(0);
|
|
82
|
+
}
|
|
83
|
+
console.error(chalk.red('Error generating project:'), error);
|
|
84
|
+
process.exit(1);
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
program.parse(process.argv);
|
|
89
|
+
|
|
90
|
+
if (!process.argv.slice(2).length) {
|
|
91
|
+
program.outputHelp();
|
|
92
|
+
}
|
package/lib/generator.js
CHANGED
|
@@ -16,9 +16,10 @@ export const generateProject = async (config) => {
|
|
|
16
16
|
viewEngine: 'None',
|
|
17
17
|
caching: 'None',
|
|
18
18
|
dbName: 'demo',
|
|
19
|
-
ciProvider: '
|
|
19
|
+
ciProvider: 'GitHub Actions',
|
|
20
20
|
communication: 'REST APIs',
|
|
21
21
|
database: 'None',
|
|
22
|
+
includeSecurity: false,
|
|
22
23
|
...config
|
|
23
24
|
};
|
|
24
25
|
|
|
@@ -112,7 +113,7 @@ export const generateProject = async (config) => {
|
|
|
112
113
|
----------------------------------------------------
|
|
113
114
|
ā
Linting & Formatting: Eslint + Prettier configured
|
|
114
115
|
ā
Git Hooks: Husky + Lint-Staged ready
|
|
115
|
-
ā
Security: Helmet, CORS, Rate-Limiting added
|
|
116
|
+
ā
Security: Helmet, CORS, Rate-Limiting added${config.includeSecurity ? '\n ā
Enterprise Security: Snyk (SCA) & SonarCloud (SAST) integration' : ''}
|
|
116
117
|
ā
Testing: Jest setup for Unit/Integration tests
|
|
117
118
|
ā
Docker: Production-ready multi-stage build
|
|
118
119
|
${config.ciProvider !== 'None' ? `ā
CI/CD: ${config.ciProvider} Workflow ready` : 'ā CI/CD: Skipped (User preferred)'}
|