nodejs-quickstart-structure 1.17.0 → 1.18.1
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 -4
- package/README.md +144 -135
- package/bin/index.js +93 -90
- package/lib/generator.js +4 -3
- package/lib/modules/config-files.js +31 -3
- package/lib/prompts.js +16 -1
- package/package.json +14 -2
- package/templates/clean-architecture/js/src/infrastructure/webserver/server.js.ejs +1 -1
- package/templates/clean-architecture/ts/src/index.ts.ejs +2 -3
- package/templates/common/.gitlab-ci.yml.ejs +44 -3
- package/templates/common/.snyk.ejs +45 -0
- package/templates/common/Dockerfile +19 -1
- package/templates/common/Jenkinsfile.ejs +26 -21
- package/templates/common/README.md.ejs +72 -54
- package/templates/common/SECURITY.md +20 -0
- package/templates/common/_github/workflows/{ci.yml → ci.yml.ejs} +9 -6
- package/templates/common/_github/workflows/security.yml.ejs +36 -0
- package/templates/common/_husky/pre-commit +4 -0
- package/templates/common/docker-compose.yml.ejs +1 -1
- 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 +16 -5
- package/templates/common/sonar-project.properties.ejs +27 -0
- package/templates/mvc/js/src/index.js.ejs +2 -2
- package/templates/mvc/ts/src/index.ts.ejs +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## [1.18.1] - 2026-03-27
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
### Fixed
|
|
6
|
+
- **Template Security Hardening**: Resolved 29 vulnerabilities in `package.json.ejs` by upgrading `Apollo Server`, `Jest`, and `ESLint`.
|
|
7
|
+
- **Apollo Server 5 Compatibility**: Migrated GraphQL integration to use `@as-integrations/express4`, resolving breaking changes in the latest Apollo release.
|
|
8
|
+
- **Surgical Security Overrides**: Implemented targeted `overrides` for `brace-expansion`, `jake`, and `micromatch`. Removed global `glob/minimatch` overrides to maintain compatibility with Jest's internal APIs while preserving a "Zero-Vulnerability" status.
|
|
9
|
+
- **E2E Validated**: Verified the entire "Secure-by-Default" ecosystem via Windows E2E tests, achieving 100% pass rate.
|
|
10
|
+
- **Enterprise Standards**: Synchronized all generator templates with the latest secure dependency standards across MVC and Clean Architecture.
|
|
11
|
+
### Changed
|
|
12
|
+
- **Readme**: Standardize Generated Project README.
|
|
13
|
+
|
|
14
|
+
## [1.18.0] - 2026-03-25
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
- **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.
|
|
18
|
+
- **Automated Security Workflows**: Pre-configured CI/CD stages for security scanning across GitHub Actions, GitLab CI, and Jenkins.
|
|
19
|
+
- **Pre-commit Security Gates**: Integrated **Husky** and **lint-staged** to automatically enforce code quality and security standards locally before every commit.
|
|
20
|
+
- **Security Standard Enforcement**: Added a standardized `SECURITY.md` policy and automated quality gates to ensure code resilience.
|
|
21
|
+
- **Comprehensive Security Guide**: Created a new documentation guide detailing the setup and operational workflows for the enterprise security features.
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
- **Matrix Expansion**: Updated the CLI to support over **1,680+ project combinations** by adding a conditional security hardening layer across all CI/CD providers.
|
|
25
|
+
|
|
26
|
+
### Fixed
|
|
27
|
+
- **Docker Node Version**: Updated Docker node version to 22.22.2-trixie-slim
|
|
7
28
|
|
|
8
29
|
## [1.17.0] - 2026-03-23
|
|
9
30
|
|
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,90 +1,93 @@
|
|
|
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
|
-
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 === 'MongoDB') servicesToStart += ' db';
|
|
66
|
-
else if (answers.database !== 'None') servicesToStart += ' db flyway';
|
|
67
|
-
if (answers.caching === 'Redis') servicesToStart += ' redis';
|
|
68
|
-
if (answers.communication === 'Kafka') servicesToStart += ' kafka';
|
|
69
|
-
|
|
70
|
-
manualStartInstructions += `\n docker-compose up -d${servicesToStart} # Start infrastructure first\n npm run dev`;
|
|
71
|
-
} else {
|
|
72
|
-
manualStartInstructions += `\n npm run dev`;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
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`));
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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.blue(`\n🚀 Preparing to generate ${chalk.bold(answers.projectName)} (${answers.architecture})...`));
|
|
46
|
+
|
|
47
|
+
console.log(chalk.yellow('\nGenerating project files...'));
|
|
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 === 'MongoDB') servicesToStart += ' db';
|
|
66
|
+
else if (answers.database !== 'None') servicesToStart += ' db flyway';
|
|
67
|
+
if (answers.caching === 'Redis') servicesToStart += ' redis';
|
|
68
|
+
if (answers.communication === 'Kafka') servicesToStart += ' kafka';
|
|
69
|
+
|
|
70
|
+
manualStartInstructions += `\n docker-compose up -d${servicesToStart} # Start infrastructure first\n npm run dev`;
|
|
71
|
+
} else {
|
|
72
|
+
manualStartInstructions += `\n npm run dev`;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
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`));
|
|
76
|
+
|
|
77
|
+
console.log(chalk.yellow(`\n⭐ If this tool saved you 5 minutes, please give us a star on GitHub: ${chalk.underline('https://github.com/paudang/nodejs-quickstart-structure')}`));
|
|
78
|
+
|
|
79
|
+
} catch (error) {
|
|
80
|
+
if (error.name === 'ExitPromptError') {
|
|
81
|
+
console.log(chalk.yellow('\n\n👋 Goodbye! Setup cancelled.'));
|
|
82
|
+
process.exit(0);
|
|
83
|
+
}
|
|
84
|
+
console.error(chalk.red('Error generating project:'), error);
|
|
85
|
+
process.exit(1);
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
program.parse(process.argv);
|
|
90
|
+
|
|
91
|
+
if (!process.argv.slice(2).length) {
|
|
92
|
+
program.outputHelp();
|
|
93
|
+
}
|
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)'}
|
|
@@ -131,7 +132,7 @@ export const generateProject = async (config) => {
|
|
|
131
132
|
2. git init
|
|
132
133
|
3. npm install
|
|
133
134
|
4. npm run prepare (To setup Husky hooks)
|
|
134
|
-
5. docker-compose up -d (To start DB/Infrastructure)
|
|
135
|
+
5. docker-compose up -d${config.database !== 'None' ? ' db' : ''}${config.caching === 'Redis' ? ' redis' : ''}${config.communication === 'Kafka' ? ' kafka' : ''} (To start DB/Infrastructure)
|
|
135
136
|
6. npm run dev (To start development server)
|
|
136
137
|
7. npm test (To run tests)
|
|
137
138
|
`);
|
|
@@ -52,6 +52,24 @@ export const renderProfessionalConfig = async (templatesDir, targetDir, config)
|
|
|
52
52
|
const jestE2eTemplate = await fs.readFile(path.join(templatesDir, 'common', 'jest.e2e.config.js.ejs'), 'utf-8');
|
|
53
53
|
const jestE2eContent = ejs.render(jestE2eTemplate, { ...config });
|
|
54
54
|
await fs.writeFile(path.join(targetDir, 'jest.e2e.config.js'), jestE2eContent);
|
|
55
|
+
|
|
56
|
+
// 1. Setup Husky pre-commit (Always for Professional Standard)
|
|
57
|
+
const huskyDir = path.join(targetDir, '.husky');
|
|
58
|
+
await fs.ensureDir(huskyDir);
|
|
59
|
+
await fs.copy(path.join(templatesDir, 'common', '_husky', 'pre-commit'), path.join(huskyDir, 'pre-commit'));
|
|
60
|
+
|
|
61
|
+
// 2. Enterprise Security Hardening (Optional)
|
|
62
|
+
if (config.includeSecurity) {
|
|
63
|
+
await fs.copy(path.join(templatesDir, 'common', 'SECURITY.md'), path.join(targetDir, 'SECURITY.md'));
|
|
64
|
+
|
|
65
|
+
const sonarTemplate = await fs.readFile(path.join(templatesDir, 'common', 'sonar-project.properties.ejs'), 'utf-8');
|
|
66
|
+
const sonarContent = ejs.render(sonarTemplate, { ...config });
|
|
67
|
+
await fs.writeFile(path.join(targetDir, 'sonar-project.properties'), sonarContent);
|
|
68
|
+
|
|
69
|
+
const snykTemplate = await fs.readFile(path.join(templatesDir, 'common', '.snyk.ejs'), 'utf-8');
|
|
70
|
+
const snykContent = ejs.render(snykTemplate, { ...config });
|
|
71
|
+
await fs.writeFile(path.join(targetDir, '.snyk'), snykContent);
|
|
72
|
+
}
|
|
55
73
|
};
|
|
56
74
|
|
|
57
75
|
export const renderAiNativeFiles = async (templatesDir, targetDir, config) => {
|
|
@@ -80,10 +98,20 @@ export const renderAiNativeFiles = async (templatesDir, targetDir, config) => {
|
|
|
80
98
|
};
|
|
81
99
|
|
|
82
100
|
export const setupCiCd = async (templatesDir, targetDir, config) => {
|
|
83
|
-
const { ciProvider } = config;
|
|
101
|
+
const { ciProvider, includeSecurity } = config;
|
|
84
102
|
if (ciProvider === 'GitHub Actions') {
|
|
85
|
-
|
|
86
|
-
await fs.
|
|
103
|
+
const workflowsDir = path.join(targetDir, '.github/workflows');
|
|
104
|
+
await fs.ensureDir(workflowsDir);
|
|
105
|
+
|
|
106
|
+
const ciTemplate = await fs.readFile(path.join(templatesDir, 'common', '_github/workflows/ci.yml.ejs'), 'utf-8');
|
|
107
|
+
const ciContent = ejs.render(ciTemplate, { ...config });
|
|
108
|
+
await fs.writeFile(path.join(workflowsDir, 'ci.yml'), ciContent);
|
|
109
|
+
|
|
110
|
+
if (includeSecurity) {
|
|
111
|
+
const securityTemplate = await fs.readFile(path.join(templatesDir, 'common', '_github/workflows/security.yml.ejs'), 'utf-8');
|
|
112
|
+
const securityContent = ejs.render(securityTemplate, { ...config });
|
|
113
|
+
await fs.writeFile(path.join(workflowsDir, 'security.yml'), securityContent);
|
|
114
|
+
}
|
|
87
115
|
} else if (ciProvider === 'Jenkins') {
|
|
88
116
|
const jenkinsTemplate = await fs.readFile(path.join(templatesDir, 'common', 'Jenkinsfile.ejs'), 'utf-8');
|
|
89
117
|
const jenkinsContent = ejs.render(jenkinsTemplate, { ...config });
|
package/lib/prompts.js
CHANGED
|
@@ -77,9 +77,24 @@ export const getProjectDetails = async (options = {}) => {
|
|
|
77
77
|
choices: ['None', 'GitHub Actions', 'Jenkins', 'GitLab CI'],
|
|
78
78
|
default: 'None',
|
|
79
79
|
when: !options.ciProvider
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
type: 'select',
|
|
83
|
+
name: 'includeSecurity',
|
|
84
|
+
message: 'Include Enterprise Security Hardening (Big Tech Standard: Snyk, SonarQube)?',
|
|
85
|
+
choices: ['No', 'Yes'],
|
|
86
|
+
default: "No",
|
|
87
|
+
when: (answers) => !options.includeSecurity && (options.ciProvider || answers.ciProvider) !== 'None'
|
|
80
88
|
}
|
|
81
89
|
];
|
|
82
90
|
|
|
83
91
|
const answers = await inquirer.prompt(questions);
|
|
84
|
-
|
|
92
|
+
const result = { ...options, ...answers };
|
|
93
|
+
|
|
94
|
+
// Normalize includeSecurity to boolean if it's a string from the select prompt
|
|
95
|
+
if (typeof result.includeSecurity === 'string') {
|
|
96
|
+
result.includeSecurity = result.includeSecurity === 'Yes';
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return result;
|
|
85
100
|
};
|