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.
Files changed (40) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/LICENSE +15 -0
  3. package/README.md +144 -135
  4. package/bin/index.js +92 -89
  5. package/lib/generator.js +3 -2
  6. package/lib/modules/app-setup.js +49 -12
  7. package/lib/modules/caching-setup.js +1 -1
  8. package/lib/modules/config-files.js +32 -3
  9. package/lib/modules/database-setup.js +2 -2
  10. package/lib/modules/kafka-setup.js +8 -8
  11. package/lib/prompts.js +16 -1
  12. package/package.json +14 -2
  13. package/templates/clean-architecture/ts/src/index.ts.ejs +1 -2
  14. package/templates/common/.cursorrules.ejs +1 -1
  15. package/templates/common/.env.example.ejs +1 -1
  16. package/templates/common/.gitlab-ci.yml.ejs +55 -4
  17. package/templates/common/Dockerfile +12 -2
  18. package/templates/common/Jenkinsfile.ejs +32 -21
  19. package/templates/common/README.md.ejs +19 -9
  20. package/templates/common/SECURITY.md +20 -0
  21. package/templates/common/_github/workflows/{ci.yml → ci.yml.ejs} +13 -7
  22. package/templates/common/_github/workflows/security.yml.ejs +36 -0
  23. package/templates/common/_husky/pre-commit +4 -0
  24. package/templates/common/caching/js/redisClient.spec.js.ejs +0 -2
  25. package/templates/common/docker-compose.yml.ejs +13 -20
  26. package/templates/common/ecosystem.config.js.ejs +1 -1
  27. package/templates/common/jest.config.js.ejs +1 -0
  28. package/templates/common/jest.e2e.config.js.ejs +8 -0
  29. package/templates/common/kafka/js/config/kafka.js +2 -1
  30. package/templates/common/kafka/js/config/kafka.spec.js.ejs +6 -0
  31. package/templates/common/kafka/ts/config/kafka.spec.ts.ejs +6 -0
  32. package/templates/common/kafka/ts/config/kafka.ts +2 -1
  33. package/templates/common/package.json.ejs +14 -9
  34. package/templates/common/prompts/add-feature.md.ejs +1 -1
  35. package/templates/common/prompts/project-context.md.ejs +1 -1
  36. package/templates/common/scripts/run-e2e.js.ejs +63 -0
  37. package/templates/common/sonar-project.properties.ejs +27 -0
  38. package/templates/common/src/tests/e2e/e2e.users.test.js.ejs +49 -0
  39. package/templates/common/src/tests/e2e/e2e.users.test.ts.ejs +49 -0
  40. 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
- [![npm version](https://img.shields.io/npm/v/nodejs-quickstart-structure.svg?style=flat-square)](https://www.npmjs.com/package/nodejs-quickstart-structure)
4
- [![npm total downloads](https://img.shields.io/npm/dt/nodejs-quickstart-structure.svg?style=flat-square)](https://www.npmjs.com/package/nodejs-quickstart-structure)
5
- [![npm monthly downloads](https://img.shields.io/npm/dm/nodejs-quickstart-structure.svg?style=flat-square)](https://www.npmjs.com/package/nodejs-quickstart-structure)
6
- [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg?style=flat-square)](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
- ![Demo](docs/demo.gif)
11
-
12
- ## Features
13
-
14
- - **Interactive CLI**: Easy-to-use prompts to configure your project.
15
- - **Multiple Architectures**: Supports both **MVC** (Model-View-Controller) and **Clean Architecture**.
16
- - **Language Support**: Choose between **JavaScript** and **TypeScript**.
17
- - **Database Integration**: Pre-configured setup for **MySQL**, **PostgreSQL**, or **MongoDB**.
18
- - **Communication Flow**: Scaffold APIs using **REST**, **GraphQL** (with Apollo Server), or **Kafka** (event-driven).
19
- - **Caching Layer**: Choose between **Redis** or built-in **Memory Cache** for data caching.
20
- - **Centralized Error Handling**: Every project ships with a global error handler, custom error classes and structured JSON error responses — consistent across REST & GraphQL.
21
- - **Dockerized**: Automatically generates `docker-compose.yml` for DB, Kafka, Redis, and Zookeeper.
22
- - **Database Migrations/Schemas**: Integrated **Flyway** for SQL migrations or **Mongoose** schemas for MongoDB.
23
- - **Professional Standards**: Generated projects come with highly professional, industry-standard tooling.
24
-
25
- ## 🌟 Why developers love this?
26
-
27
- - **Community Trusted**: Over **3,000+** projects bootstrapped within the first month.
28
- - **Actively Maintained**: Constant updates and optimizations (30+ versions released) based on real-world developer feedback.
29
- - **Resilience First**: Unlike basic boilerplates, our generated code focuses on infrastructure stability (Retry logic, Health checks, and Graceful shutdowns).
30
-
31
- ## šŸ† Professional Standards (New)
32
-
33
- We don't just generate boilerplate; we generate **production-ready** foundations. Every project includes:
34
-
35
- - **šŸ” Code Quality**: Pre-configured `Eslint` and `Prettier` for consistent coding standards.
36
- - **šŸ›”ļø Security**: Built-in `Helmet`, `HPP`, `CORS`, and Rate-Limiting middleware.
37
- - **🚨 Error Handling**: Centralized global error middleware with custom error classes and structured JSON responses. GraphQL uses Apollo's `formatError` hook; REST uses Express error middleware.
38
- - **🧪 Testing Excellence**: Integrated `Jest` and `Supertest`. Every generated project maintains **>70% Unit Test coverage** for controllers, services, and resolvers out of the box.
39
- - **šŸ”„ CI/CD Integration**: Pre-configured workflows for **GitHub Actions**, **Jenkins**, and **GitLab CI**.
40
- - **āš“ Git Hooks**: `Husky` and `Lint-Staged` to ensure no bad code is ever committed.
41
- - **šŸ¤ Reliability**: Health Checks (`/health`) with deep database pings, Infrastructure Retry Logic (handling Docker startup delays), and Graceful Shutdown workflows.
42
- - **🐳 DevOps**: Highly optimized **Multi-Stage Dockerfile** for small, secure production images.
43
- - **šŸš€ Deployment**: Ship confidently with an integrated **PM2 Ecosystem Configuration** for zero-downtime reloads and robust process management.
44
-
45
- ## 🧩 480+ Project Combinations
46
-
47
- The CLI supports a massive number of configurations to fit your exact needs:
48
-
49
- - **240 Core Combinations**:
50
- - **MVC Architecture**: 180 variants (Languages Ɨ View Engines Ɨ Databases Ɨ Communication Patterns Ɨ Caching)
51
- - **Clean Architecture**: 60 variants (Languages Ɨ Databases Ɨ Communication Patterns Ɨ Caching)
52
- - **480 Total Scenarios**:
53
- - Every combination can be generated with or without (**GitHub Actions CI/CD** / **Jenkins** or **GitLab CI**), tripling the possibilities.
54
- - Every single one of these 480 scenarios is verified to be compatible with our 70% Coverage Threshold policy.
55
-
56
- For a detailed list of all supported cases, check out [docs/generateCase.md](docs/generateCase.md).
57
-
58
- ## Installation
59
-
60
- You can install the tool globally directly from npm:
61
-
62
- ```bash
63
- npm install -g nodejs-quickstart-structure
64
- ```
65
-
66
- ## Usage
67
-
68
- Once installed, simply run the following command in any directory where you want to create a new project:
69
-
70
- ```bash
71
- nodejs-quickstart init
72
- ```
73
-
74
- ## Quick Start (Recommended)
75
-
76
- You can run the generator directly without installing it globally:
77
-
78
- ```bash
79
- npx nodejs-quickstart-structure@latest init
80
- ```
81
-
82
- ### Configuration Options
83
-
84
- The CLI will guide you through the following steps:
85
-
86
- 1. **Project Name**: The name of the folder to create.
87
- 2. **Language**: `JavaScript` or `TypeScript`.
88
- 3. **Architecture**: `MVC` or `Clean Architecture`.
89
- 4. **Database**: `MySQL`, `PostgreSQL`, or `MongoDB`.
90
- 5. **Database Name**: The name of the initial database.
91
- 6. **Communication**: `REST APIs` (default), `GraphQL`, or `Kafka`.
92
- 7. **Caching**: `None`, `Redis`, or `Memory Cache`.
93
- 8. **CI/CD**: `GitHub Actions`, `Jenkins`, `GitLab CI` or `None`.
94
-
95
- ## Generated Project Structure
96
-
97
- The generated project will include:
98
-
99
- - `src/`: Source code (controllers, routes, services/use-cases).
100
- - `src/errors/`: Custom error classes — `ApiError`, `NotFoundError`, `BadRequestError`.
101
- - `flyway/sql/`: SQL migration scripts (if SQL database selected).
102
- - `docker-compose.yml`: Services configuration for DB, Flyway, and Kafka.
103
- - `package.json`: Dependencies and scripts (`start`, `dev`, `build`).
104
- - `tsconfig.json`: (If TypeScript is selected) Type checking configuration.
105
-
106
- ### Getting Started with the Generated App
107
-
108
- ```bash
109
- cd <your-project-name>
110
-
111
- # Start infrastructure (DB, etc.)
112
- npm install
113
-
114
- docker-compose up
115
- ```
116
-
117
- ## ā¤ļø Support the Project
118
-
119
- We just hit **3,000 downloads**! If this tool helped you save hours of setup time, please consider:
120
- - Giving us a ⭐ on [GitHub](https://github.com/paudang/nodejs-quickstart-structure) to help others find it.
121
- - Following the [Medium Article](https://medium.com/@paudang/nodejs-quickstart-generator-93c276d60e0b) for deep-dive tutorials.
122
-
123
- ## License
124
-
125
- ISC
126
-
127
- ## šŸš€ Roadmap & Upcoming Features
128
-
129
- We are constantly working to improve `nodejs-quickstart-structure` and make it the most robust boilerplate generator for Node.js.
130
-
131
- You can track our current progress, see what features are being worked on, and vote for your favorites on our public Trello board:
132
-
133
- šŸ‘‰ **[View our Public Roadmap on Trello](https://trello.com/b/TPTo8ylF/nodejs-quickstart-structure-product)**
134
-
135
- If you have a feature request or want to contribute, feel free to check the board and open an issue or pull request!
1
+ # Node.js Quickstart Generator
2
+
3
+ [![npm version](https://img.shields.io/npm/v/nodejs-quickstart-structure.svg?style=flat-square)](https://www.npmjs.com/package/nodejs-quickstart-structure)
4
+ [![npm total downloads](https://img.shields.io/npm/dt/nodejs-quickstart-structure?style=flat-square&color=emerald&label=Downloads)](https://www.npmjs.com/package/nodejs-quickstart-structure)
5
+ [![npm monthly downloads](https://img.shields.io/npm/dm/nodejs-quickstart-structure.svg?style=flat-square)](https://www.npmjs.com/package/nodejs-quickstart-structure)
6
+ [![License: ISC](https://img.shields.io/badge/License-ISC-blue.svg?style=flat-square)](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
+ ![Demo](docs/demo.gif)
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('--caching <type>', 'Caching Layer (None/Redis)')
34
- .action(async (options) => {
35
- // Fix for Commander camelCase conversion
36
- if (options.ciProvider) {
37
- options.ciProvider = options.ciProvider;
38
- }
39
-
40
- console.log(chalk.blue('Welcome to the Node.js Quickstart Generator!'));
41
-
42
- try {
43
- const answers = await getProjectDetails(options);
44
- console.log(chalk.green('\nConfiguration received:'));
45
- console.log(JSON.stringify(answers, null, 2));
46
-
47
- console.log(chalk.yellow('\nGenerating project...'));
48
- await generateProject(answers);
49
-
50
- console.log(chalk.green('\nāœ” Project generated successfully!'));
51
-
52
- console.log(chalk.magenta('\nšŸš€ Project is AI-Ready!'));
53
- console.log(chalk.magenta('-----------------------------------------'));
54
- console.log(chalk.magenta('šŸ¤– We detected you are using AI tools.'));
55
- console.log(chalk.magenta(`šŸ“ Use Cursor? We've configured '.cursorrules' for you.`));
56
- console.log(chalk.magenta(`šŸ“ Use ChatGPT/Gemini? Check the 'prompts/' folder for Agent Skills.`));
57
- console.log(chalk.magenta('-----------------------------------------'));
58
-
59
- let manualStartInstructions = `\n${chalk.yellow('Development:')}\n cd ${answers.projectName}\n npm install`;
60
-
61
- const needsInfrastructure = answers.database !== 'None' || answers.caching === 'Redis' || answers.communication === 'Kafka';
62
-
63
- if (needsInfrastructure) {
64
- let servicesToStart = '';
65
- if (answers.database !== 'None') servicesToStart += ' db';
66
- if (answers.caching === 'Redis') servicesToStart += ' redis';
67
- if (answers.communication === 'Kafka') servicesToStart += ' zookeeper kafka';
68
-
69
- manualStartInstructions += `\n docker-compose up -d${servicesToStart} # Start infrastructure first\n npm run dev`;
70
- } else {
71
- manualStartInstructions += `\n npm run dev`;
72
- }
73
-
74
- 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`));
75
-
76
- } catch (error) {
77
- if (error.name === 'ExitPromptError') {
78
- console.log(chalk.yellow('\n\nšŸ‘‹ Goodbye! Setup cancelled.'));
79
- process.exit(0);
80
- }
81
- console.error(chalk.red('Error generating project:'), error);
82
- process.exit(1);
83
- }
84
- });
85
- program.parse(process.argv);
86
-
87
- if (!process.argv.slice(2).length) {
88
- program.outputHelp();
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: 'None',
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)'}