@sachin-thakur/create-nodejs-app 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/DEVELOPMENT.md +183 -0
- package/README.md +238 -0
- package/bin/cli.js +177 -0
- package/package.json +36 -0
- package/src/generator.js +121 -0
- package/src/templates/clean.js +11 -0
- package/src/templates/featureBased.js +11 -0
- package/src/templates/index.js +76 -0
- package/src/templates/mvc.js +890 -0
- package/src/utils/cicd.js +99 -0
- package/src/utils/docker.js +157 -0
- package/src/utils/envFile.js +102 -0
- package/src/utils/packageJson.js +142 -0
- package/src/utils/readme.js +277 -0
- package/test.sh +40 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
function generateReadme(projectName, config) {
|
|
2
|
+
const isTypeScript = config.language === "typescript";
|
|
3
|
+
|
|
4
|
+
return `# ${projectName}
|
|
5
|
+
|
|
6
|
+
A production-ready ${config.projectType.toUpperCase()} application built with Node.js and ${
|
|
7
|
+
isTypeScript ? "TypeScript" : "JavaScript"
|
|
8
|
+
}.
|
|
9
|
+
|
|
10
|
+
## ๐ Features
|
|
11
|
+
|
|
12
|
+
- โก **${
|
|
13
|
+
config.language === "typescript" ? "TypeScript" : "JavaScript"
|
|
14
|
+
}** - Type safety and modern syntax
|
|
15
|
+
- ๐๏ธ **${config.architecture.toUpperCase()} Architecture** - Clean and maintainable code structure
|
|
16
|
+
${
|
|
17
|
+
config.database !== "none"
|
|
18
|
+
? `- ๐๏ธ **${
|
|
19
|
+
config.database.charAt(0).toUpperCase() + config.database.slice(1)
|
|
20
|
+
}** - Database integration`
|
|
21
|
+
: ""
|
|
22
|
+
}
|
|
23
|
+
${
|
|
24
|
+
config.features.includes("auth")
|
|
25
|
+
? "- ๐ **JWT Authentication** - Secure user authentication"
|
|
26
|
+
: ""
|
|
27
|
+
}
|
|
28
|
+
${
|
|
29
|
+
config.features.includes("validation")
|
|
30
|
+
? "- โ
**Request Validation** - Input validation with Zod"
|
|
31
|
+
: ""
|
|
32
|
+
}
|
|
33
|
+
${
|
|
34
|
+
config.features.includes("logging")
|
|
35
|
+
? "- ๐ **Logging** - Structured logging with Winston"
|
|
36
|
+
: ""
|
|
37
|
+
}
|
|
38
|
+
${
|
|
39
|
+
config.features.includes("swagger")
|
|
40
|
+
? "- ๐ **API Documentation** - Auto-generated Swagger docs"
|
|
41
|
+
: ""
|
|
42
|
+
}
|
|
43
|
+
${
|
|
44
|
+
config.features.includes("rate-limit")
|
|
45
|
+
? "- ๐ก๏ธ **Rate Limiting** - API rate limiting protection"
|
|
46
|
+
: ""
|
|
47
|
+
}
|
|
48
|
+
${
|
|
49
|
+
config.features.includes("cors")
|
|
50
|
+
? "- ๐ **CORS** - Cross-origin resource sharing configuration"
|
|
51
|
+
: ""
|
|
52
|
+
}
|
|
53
|
+
${
|
|
54
|
+
config.features.includes("cache")
|
|
55
|
+
? "- โก **Redis Caching** - Fast data caching"
|
|
56
|
+
: ""
|
|
57
|
+
}
|
|
58
|
+
${
|
|
59
|
+
config.features.includes("jobs")
|
|
60
|
+
? "- ๐ **Background Jobs** - Task queue with Bull"
|
|
61
|
+
: ""
|
|
62
|
+
}
|
|
63
|
+
${
|
|
64
|
+
config.features.includes("email")
|
|
65
|
+
? "- ๐ง **Email Service** - Email sending with Nodemailer"
|
|
66
|
+
: ""
|
|
67
|
+
}
|
|
68
|
+
${
|
|
69
|
+
config.features.includes("file-upload")
|
|
70
|
+
? "- ๐ **File Upload** - File upload handling"
|
|
71
|
+
: ""
|
|
72
|
+
}
|
|
73
|
+
${
|
|
74
|
+
config.testing !== "none"
|
|
75
|
+
? `- ๐งช **Testing** - Unit and integration tests with ${
|
|
76
|
+
config.testing.charAt(0).toUpperCase() + config.testing.slice(1)
|
|
77
|
+
}`
|
|
78
|
+
: ""
|
|
79
|
+
}
|
|
80
|
+
${config.docker ? "- ๐ณ **Docker** - Containerization ready" : ""}
|
|
81
|
+
${config.cicd ? "- ๐ **CI/CD** - GitHub Actions workflow" : ""}
|
|
82
|
+
|
|
83
|
+
## ๐ Prerequisites
|
|
84
|
+
|
|
85
|
+
- Node.js >= 16.x
|
|
86
|
+
- npm or yarn
|
|
87
|
+
${config.database === "postgresql" ? "- PostgreSQL >= 13.x" : ""}
|
|
88
|
+
${config.database === "mongodb" ? "- MongoDB >= 5.x" : ""}
|
|
89
|
+
${config.database === "mysql" ? "- MySQL >= 8.x" : ""}
|
|
90
|
+
${
|
|
91
|
+
config.features.includes("cache") || config.features.includes("jobs")
|
|
92
|
+
? "- Redis >= 6.x"
|
|
93
|
+
: ""
|
|
94
|
+
}
|
|
95
|
+
${config.docker ? "- Docker and Docker Compose (optional)" : ""}
|
|
96
|
+
|
|
97
|
+
## ๐ ๏ธ Installation
|
|
98
|
+
|
|
99
|
+
1. Clone the repository:
|
|
100
|
+
\`\`\`bash
|
|
101
|
+
git clone <repository-url>
|
|
102
|
+
cd ${projectName}
|
|
103
|
+
\`\`\`
|
|
104
|
+
|
|
105
|
+
2. Install dependencies:
|
|
106
|
+
\`\`\`bash
|
|
107
|
+
npm install
|
|
108
|
+
\`\`\`
|
|
109
|
+
|
|
110
|
+
3. Set up environment variables:
|
|
111
|
+
\`\`\`bash
|
|
112
|
+
cp .env.example .env
|
|
113
|
+
\`\`\`
|
|
114
|
+
Edit the \`.env\` file with your configuration.
|
|
115
|
+
|
|
116
|
+
${
|
|
117
|
+
config.database !== "none"
|
|
118
|
+
? `4. Set up the database:
|
|
119
|
+
\`\`\`bash
|
|
120
|
+
# Create database
|
|
121
|
+
${
|
|
122
|
+
config.database === "postgresql"
|
|
123
|
+
? "createdb myapp_db"
|
|
124
|
+
: config.database === "mongodb"
|
|
125
|
+
? "# MongoDB will create the database automatically"
|
|
126
|
+
: "# Create MySQL database"
|
|
127
|
+
}
|
|
128
|
+
\`\`\`
|
|
129
|
+
`
|
|
130
|
+
: ""
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
## ๐ Running the Application
|
|
134
|
+
|
|
135
|
+
### Development mode:
|
|
136
|
+
\`\`\`bash
|
|
137
|
+
npm run dev
|
|
138
|
+
\`\`\`
|
|
139
|
+
|
|
140
|
+
### Production mode:
|
|
141
|
+
\`\`\`bash
|
|
142
|
+
${isTypeScript ? "npm run build\n" : ""}npm start
|
|
143
|
+
\`\`\`
|
|
144
|
+
|
|
145
|
+
${
|
|
146
|
+
config.docker
|
|
147
|
+
? `### Using Docker:
|
|
148
|
+
\`\`\`bash
|
|
149
|
+
docker-compose up
|
|
150
|
+
\`\`\`
|
|
151
|
+
`
|
|
152
|
+
: ""
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
The application will be running at \`http://localhost:3000\`
|
|
156
|
+
|
|
157
|
+
${
|
|
158
|
+
config.features.includes("swagger")
|
|
159
|
+
? `## ๐ API Documentation
|
|
160
|
+
|
|
161
|
+
Once the server is running, visit:
|
|
162
|
+
- Swagger UI: \`http://localhost:3000/api-docs\`
|
|
163
|
+
`
|
|
164
|
+
: ""
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
## ๐งช Testing
|
|
168
|
+
|
|
169
|
+
${
|
|
170
|
+
config.testing !== "none"
|
|
171
|
+
? `Run tests:
|
|
172
|
+
\`\`\`bash
|
|
173
|
+
npm test
|
|
174
|
+
\`\`\`
|
|
175
|
+
|
|
176
|
+
Run tests in watch mode:
|
|
177
|
+
\`\`\`bash
|
|
178
|
+
npm run test:watch
|
|
179
|
+
\`\`\`
|
|
180
|
+
|
|
181
|
+
Generate coverage report:
|
|
182
|
+
\`\`\`bash
|
|
183
|
+
npm run test:coverage
|
|
184
|
+
\`\`\`
|
|
185
|
+
`
|
|
186
|
+
: "Testing framework not included. Add your preferred testing framework."
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
## ๐ Project Structure
|
|
190
|
+
|
|
191
|
+
\`\`\`
|
|
192
|
+
${projectName}/
|
|
193
|
+
โโโ src/
|
|
194
|
+
${
|
|
195
|
+
config.architecture === "mvc"
|
|
196
|
+
? `โ โโโ config/ # Configuration files
|
|
197
|
+
โ โโโ controllers/ # Request handlers
|
|
198
|
+
โ โโโ models/ # Data models
|
|
199
|
+
โ โโโ routes/ # API routes
|
|
200
|
+
โ โโโ middlewares/ # Custom middlewares
|
|
201
|
+
โ โโโ services/ # Business logic
|
|
202
|
+
โ โโโ utils/ # Utility functions
|
|
203
|
+
โ โโโ index.${isTypeScript ? "ts" : "js"} # Application entry point`
|
|
204
|
+
: ""
|
|
205
|
+
}
|
|
206
|
+
${
|
|
207
|
+
config.architecture === "clean"
|
|
208
|
+
? `โ โโโ domain/ # Business entities
|
|
209
|
+
โ โโโ application/ # Use cases
|
|
210
|
+
โ โโโ infrastructure/ # External services
|
|
211
|
+
โ โโโ presentation/ # Controllers & routes
|
|
212
|
+
โ โโโ index.${isTypeScript ? "ts" : "js"} # Application entry point`
|
|
213
|
+
: ""
|
|
214
|
+
}
|
|
215
|
+
${
|
|
216
|
+
config.architecture === "feature-based"
|
|
217
|
+
? `โ โโโ features/ # Feature modules
|
|
218
|
+
โ โโโ shared/ # Shared utilities
|
|
219
|
+
โ โโโ config/ # Configuration
|
|
220
|
+
โ โโโ index.${isTypeScript ? "ts" : "js"} # Application entry point`
|
|
221
|
+
: ""
|
|
222
|
+
}
|
|
223
|
+
โโโ tests/ # Test files
|
|
224
|
+
${
|
|
225
|
+
isTypeScript
|
|
226
|
+
? "โโโ dist/ # Compiled JavaScript (generated)\n"
|
|
227
|
+
: ""
|
|
228
|
+
}โโโ .env.example # Environment variables template
|
|
229
|
+
โโโ .gitignore
|
|
230
|
+
โโโ package.json
|
|
231
|
+
${isTypeScript ? "โโโ tsconfig.json # TypeScript configuration\n" : ""}${
|
|
232
|
+
config.docker ? "โโโ Dockerfile\nโโโ docker-compose.yml\n" : ""
|
|
233
|
+
}โโโ README.md
|
|
234
|
+
\`\`\`
|
|
235
|
+
|
|
236
|
+
## ๐ง Available Scripts
|
|
237
|
+
|
|
238
|
+
- \`npm start\` - Start production server
|
|
239
|
+
- \`npm run dev\` - Start development server with hot reload
|
|
240
|
+
${
|
|
241
|
+
isTypeScript ? "- `npm run build` - Build for production\n" : ""
|
|
242
|
+
}- \`npm run lint\` - Run ESLint
|
|
243
|
+
- \`npm run lint:fix\` - Fix ESLint errors
|
|
244
|
+
- \`npm run format\` - Format code with Prettier
|
|
245
|
+
${
|
|
246
|
+
config.testing !== "none"
|
|
247
|
+
? "- `npm test` - Run tests\n- `npm run test:watch` - Run tests in watch mode\n- `npm run test:coverage` - Generate coverage report"
|
|
248
|
+
: ""
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
## ๐ Environment Variables
|
|
252
|
+
|
|
253
|
+
See \`.env.example\` for all available environment variables.
|
|
254
|
+
|
|
255
|
+
## ๐ค Contributing
|
|
256
|
+
|
|
257
|
+
1. Fork the repository
|
|
258
|
+
2. Create your feature branch (\`git checkout -b feature/amazing-feature\`)
|
|
259
|
+
3. Commit your changes (\`git commit -m 'Add some amazing feature'\`)
|
|
260
|
+
4. Push to the branch (\`git push origin feature/amazing-feature\`)
|
|
261
|
+
5. Open a Pull Request
|
|
262
|
+
|
|
263
|
+
## ๐ License
|
|
264
|
+
|
|
265
|
+
This project is licensed under the MIT License.
|
|
266
|
+
|
|
267
|
+
## ๐จโ๐ป Author
|
|
268
|
+
|
|
269
|
+
Your Name
|
|
270
|
+
|
|
271
|
+
## ๐ Acknowledgments
|
|
272
|
+
|
|
273
|
+
- Generated with [create-nodejs-app](https://github.com/yourusername/create-nodejs-app)
|
|
274
|
+
`;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
module.exports = { generateReadme };
|
package/test.sh
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/bin/bash
|
|
2
|
+
|
|
3
|
+
# Quick test script for create-nodejs-app
|
|
4
|
+
# This script tests the CLI by creating a sample project
|
|
5
|
+
|
|
6
|
+
echo "๐งช Testing create-nodejs-app CLI..."
|
|
7
|
+
echo ""
|
|
8
|
+
|
|
9
|
+
# Create a temporary directory
|
|
10
|
+
TEST_DIR="/tmp/test-create-nodejs-app-$(date +%s)"
|
|
11
|
+
mkdir -p "$TEST_DIR"
|
|
12
|
+
cd "$TEST_DIR"
|
|
13
|
+
|
|
14
|
+
echo "๐ Test directory: $TEST_DIR"
|
|
15
|
+
echo ""
|
|
16
|
+
|
|
17
|
+
# Run the CLI (you'll need to answer the prompts)
|
|
18
|
+
echo "๐ Running CLI..."
|
|
19
|
+
echo "Please answer the prompts to create a test project"
|
|
20
|
+
echo ""
|
|
21
|
+
|
|
22
|
+
node /home/claude/create-nodejs-app/bin/cli.js test-project
|
|
23
|
+
|
|
24
|
+
# Check if project was created
|
|
25
|
+
if [ -d "test-project" ]; then
|
|
26
|
+
echo ""
|
|
27
|
+
echo "โ
Project created successfully!"
|
|
28
|
+
echo ""
|
|
29
|
+
echo "๐ฆ Project structure:"
|
|
30
|
+
tree -L 2 test-project/ || ls -la test-project/
|
|
31
|
+
echo ""
|
|
32
|
+
echo "๐ Files created:"
|
|
33
|
+
find test-project -type f | head -20
|
|
34
|
+
echo ""
|
|
35
|
+
echo "๐ Test completed! Check the project at: $TEST_DIR/test-project"
|
|
36
|
+
else
|
|
37
|
+
echo ""
|
|
38
|
+
echo "โ Project creation failed!"
|
|
39
|
+
exit 1
|
|
40
|
+
fi
|