projects-init-cli 2.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.
@@ -0,0 +1,337 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.generateFrontend = generateFrontend;
7
+ exports.generateBackend = generateBackend;
8
+ exports.generateMonorepoConfig = generateMonorepoConfig;
9
+ exports.generateRootFiles = generateRootFiles;
10
+ const frontend_1 = require("./frontend");
11
+ const express_1 = require("./backend/express");
12
+ const nestjs_1 = require("./backend/nestjs");
13
+ const fastapi_1 = require("./backend/fastapi");
14
+ const cdk_1 = require("./backend/cdk");
15
+ const sam_1 = require("./backend/sam");
16
+ const fs_extra_1 = __importDefault(require("fs-extra"));
17
+ const path_1 = __importDefault(require("path"));
18
+ async function generateFrontend(projectPath, config) {
19
+ const frontendPath = path_1.default.join(projectPath, 'frontend');
20
+ await fs_extra_1.default.ensureDir(frontendPath);
21
+ switch (config.frontend) {
22
+ case 'nextjs':
23
+ await (0, frontend_1.generateNextJS)(frontendPath, config);
24
+ break;
25
+ case 'react':
26
+ await (0, frontend_1.generateReact)(frontendPath, config);
27
+ break;
28
+ case 'html':
29
+ await (0, frontend_1.generateHTML)(frontendPath, config);
30
+ break;
31
+ }
32
+ }
33
+ async function generateBackend(projectPath, config) {
34
+ const backendPath = path_1.default.join(projectPath, 'backend');
35
+ await fs_extra_1.default.ensureDir(backendPath);
36
+ switch (config.backend) {
37
+ case 'express':
38
+ await (0, express_1.generateExpress)(backendPath, config);
39
+ break;
40
+ case 'nest':
41
+ await (0, nestjs_1.generateNestJS)(backendPath, config);
42
+ break;
43
+ case 'fastapi':
44
+ await (0, fastapi_1.generateFastAPI)(backendPath, config);
45
+ break;
46
+ case 'cdk':
47
+ await (0, cdk_1.generateCDK)(backendPath, config);
48
+ break;
49
+ case 'sam':
50
+ await (0, sam_1.generateSAM)(backendPath, config);
51
+ break;
52
+ }
53
+ }
54
+ async function generateMonorepoConfig(projectPath, config) {
55
+ const rootPackageJson = {
56
+ name: config.projectName,
57
+ version: '1.0.0',
58
+ private: true,
59
+ workspaces: ['frontend', 'backend'],
60
+ scripts: {
61
+ dev: 'concurrently "npm run dev --workspace=frontend" "npm run dev --workspace=backend"',
62
+ build: 'npm run build --workspaces',
63
+ install: 'npm install --workspaces'
64
+ },
65
+ devDependencies: {
66
+ concurrently: '^8.2.2'
67
+ }
68
+ };
69
+ await fs_extra_1.default.writeJSON(path_1.default.join(projectPath, 'package.json'), rootPackageJson, { spaces: 2 });
70
+ }
71
+ async function generateRootFiles(projectPath, config) {
72
+ // Generate README
73
+ const readme = `# ${config.projectName}
74
+
75
+ ## Project Structure
76
+
77
+ This is a monorepo project with the following structure:
78
+
79
+ - \`frontend/\` - ${config.frontend === 'nextjs' ? 'Next.js' : config.frontend === 'react' ? 'React' : 'HTML'} application with Tailwind CSS
80
+ - \`backend/\` - ${config.backend === 'express' ? 'Express.js' : config.backend === 'nest' ? 'NestJS' : config.backend === 'fastapi' ? 'FastAPI' : config.backend === 'cdk' ? 'AWS CDK' : 'AWS SAM'} backend
81
+
82
+ ## Getting Started
83
+
84
+ 1. Install dependencies:
85
+ \`\`\`bash
86
+ npm install
87
+ \`\`\`
88
+
89
+ 2. Start development servers:
90
+ \`\`\`bash
91
+ npm run dev
92
+ \`\`\`
93
+
94
+ ## Tech Stack
95
+
96
+ - Frontend: ${config.frontend === 'nextjs' ? 'Next.js' : config.frontend === 'react' ? 'React' : 'HTML'} + Tailwind CSS
97
+ - Backend: ${config.backend === 'express' ? 'Express.js' : config.backend === 'nest' ? 'NestJS' : config.backend === 'fastapi' ? 'FastAPI' : config.backend === 'cdk' ? 'AWS CDK' : 'AWS SAM'}
98
+ - Storage: ${config.storage === 'cdk' ? 'CDK Database' : config.storage === 'local-sqlite' ? 'Local SQLite' : 'External Database'}
99
+ ${config.databaseType ? `- Database: ${config.databaseType === 'sql' ? 'SQL' : 'NoSQL'}` : ''}
100
+ ${config.apiType ? `- API: ${config.apiType === 'rest' ? 'REST' : 'GraphQL'}` : ''}
101
+ `;
102
+ await fs_extra_1.default.writeFile(path_1.default.join(projectPath, 'README.md'), readme);
103
+ // Generate .gitignore
104
+ const gitignore = `node_modules/
105
+ dist/
106
+ build/
107
+ .env
108
+ .env.local
109
+ *.log
110
+ .DS_Store
111
+ .idea/
112
+ .vscode/
113
+ *.pyc
114
+ __pycache__/
115
+ .venv/
116
+ venv/
117
+ cdk.out/
118
+ .sam/
119
+ `;
120
+ await fs_extra_1.default.writeFile(path_1.default.join(projectPath, '.gitignore'), gitignore);
121
+ // Generate CI/CD workflows
122
+ await generateCICD(projectPath, config);
123
+ }
124
+ async function generateCICD(projectPath, config) {
125
+ const workflowsPath = path_1.default.join(projectPath, '.github', 'workflows');
126
+ await fs_extra_1.default.ensureDir(workflowsPath);
127
+ // Main CI workflow
128
+ const ciWorkflow = `name: CI
129
+
130
+ on:
131
+ push:
132
+ branches: [ main, develop ]
133
+ pull_request:
134
+ branches: [ main, develop ]
135
+
136
+ jobs:
137
+ test:
138
+ runs-on: ubuntu-latest
139
+
140
+ strategy:
141
+ matrix:
142
+ node-version: [20.x]
143
+
144
+ steps:
145
+ - uses: actions/checkout@v4
146
+
147
+ - name: Use Node.js \${{ matrix.node-version }}
148
+ uses: actions/setup-node@v4
149
+ with:
150
+ node-version: \${{ matrix.node-version }}
151
+ cache: 'npm'
152
+
153
+ - name: Install dependencies
154
+ run: npm ci
155
+
156
+ - name: Run frontend tests
157
+ run: npm run test --workspace=frontend
158
+ continue-on-error: ${config.frontend === 'html' ? 'true' : 'false'}
159
+
160
+ - name: Run backend tests
161
+ run: npm run test --workspace=backend
162
+ continue-on-error: ${config.backend === 'fastapi' || config.backend === 'cdk' || config.backend === 'sam' ? 'true' : 'false'}
163
+
164
+ - name: Build frontend
165
+ run: npm run build --workspace=frontend
166
+ continue-on-error: ${config.frontend === 'html' ? 'true' : 'false'}
167
+
168
+ - name: Build backend
169
+ run: npm run build --workspace=backend
170
+ continue-on-error: ${config.backend === 'fastapi' || config.backend === 'cdk' || config.backend === 'sam' ? 'true' : 'false'}
171
+
172
+ lint:
173
+ runs-on: ubuntu-latest
174
+
175
+ steps:
176
+ - uses: actions/checkout@v4
177
+
178
+ - name: Use Node.js
179
+ uses: actions/setup-node@v4
180
+ with:
181
+ node-version: '20.x'
182
+ cache: 'npm'
183
+
184
+ - name: Install dependencies
185
+ run: npm ci
186
+
187
+ - name: Run linter
188
+ run: npm run lint --workspaces --if-present
189
+ continue-on-error: true
190
+ `;
191
+ await fs_extra_1.default.writeFile(path_1.default.join(workflowsPath, 'ci.yml'), ciWorkflow);
192
+ // Deployment workflow
193
+ let deployWorkflow = `name: Deploy
194
+
195
+ on:
196
+ push:
197
+ branches: [ main ]
198
+ workflow_dispatch:
199
+
200
+ jobs:
201
+ deploy-frontend:
202
+ runs-on: ubuntu-latest
203
+ if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
204
+
205
+ steps:
206
+ - uses: actions/checkout@v4
207
+
208
+ - name: Use Node.js
209
+ uses: actions/setup-node@v4
210
+ with:
211
+ node-version: '20.x'
212
+ cache: 'npm'
213
+
214
+ - name: Install dependencies
215
+ run: npm ci --workspace=frontend
216
+
217
+ - name: Build frontend
218
+ run: npm run build --workspace=frontend
219
+
220
+ - name: Deploy to Netlify
221
+ uses: netlify/actions/cli@master
222
+ env:
223
+ NETLIFY_AUTH_TOKEN: \${{ secrets.NETLIFY_AUTH_TOKEN }}
224
+ NETLIFY_SITE_ID: \${{ secrets.NETLIFY_SITE_ID }}
225
+ with:
226
+ args: deploy --dir=frontend/.next --prod
227
+ continue-on-error: true
228
+
229
+ - name: Deploy to Render
230
+ run: |
231
+ echo "Deploy to Render by connecting your GitHub repository"
232
+ echo "Or use: render deploy --service=\${{ secrets.RENDER_SERVICE_ID }}"
233
+ continue-on-error: true
234
+
235
+ deploy-backend:
236
+ runs-on: ubuntu-latest
237
+ if: github.event_name == 'push' || github.event_name == 'workflow_dispatch'
238
+ `;
239
+ // Add backend deployment steps based on backend type
240
+ if (config.backend === 'cdk') {
241
+ deployWorkflow += `
242
+ steps:
243
+ - uses: actions/checkout@v4
244
+
245
+ - name: Use Node.js
246
+ uses: actions/setup-node@v4
247
+ with:
248
+ node-version: '20.x'
249
+ cache: 'npm'
250
+
251
+ - name: Install dependencies
252
+ run: npm ci --workspace=backend
253
+
254
+ - name: Configure AWS credentials
255
+ uses: aws-actions/configure-aws-credentials@v4
256
+ with:
257
+ aws-access-key-id: \${{ secrets.AWS_ACCESS_KEY_ID }}
258
+ aws-secret-access-key: \${{ secrets.AWS_SECRET_ACCESS_KEY }}
259
+ aws-region: \${{ secrets.AWS_REGION || 'us-east-1' }}
260
+
261
+ - name: Build CDK
262
+ run: npm run build --workspace=backend
263
+
264
+ - name: Deploy CDK Stack
265
+ run: |
266
+ cd backend
267
+ npm run cdk deploy -- --require-approval never --all
268
+ `;
269
+ }
270
+ else if (config.backend === 'sam') {
271
+ deployWorkflow += `
272
+ steps:
273
+ - uses: actions/checkout@v4
274
+
275
+ - name: Use Node.js
276
+ uses: actions/setup-node@v4
277
+ with:
278
+ node-version: '20.x'
279
+ cache: 'npm'
280
+
281
+ - name: Install dependencies
282
+ run: npm ci --workspace=backend
283
+
284
+ - name: Setup Python
285
+ uses: actions/setup-python@v5
286
+ with:
287
+ python-version: '3.11'
288
+
289
+ - name: Install SAM CLI
290
+ run: |
291
+ pip install aws-sam-cli
292
+
293
+ - name: Configure AWS credentials
294
+ uses: aws-actions/configure-aws-credentials@v4
295
+ with:
296
+ aws-access-key-id: \${{ secrets.AWS_ACCESS_KEY_ID }}
297
+ aws-secret-access-key: \${{ secrets.AWS_SECRET_ACCESS_KEY }}
298
+ aws-region: \${{ secrets.AWS_REGION || 'us-east-1' }}
299
+
300
+ - name: Build SAM application
301
+ run: |
302
+ cd backend
303
+ sam build
304
+
305
+ - name: Deploy SAM application
306
+ run: |
307
+ cd backend
308
+ sam deploy --no-confirm-changeset --no-fail-on-empty-changeset
309
+ `;
310
+ }
311
+ else {
312
+ deployWorkflow += `
313
+ steps:
314
+ - uses: actions/checkout@v4
315
+
316
+ - name: Use Node.js
317
+ uses: actions/setup-node@v4
318
+ with:
319
+ node-version: '20.x'
320
+ cache: 'npm'
321
+
322
+ - name: Install dependencies
323
+ run: npm ci --workspace=backend
324
+
325
+ - name: Build backend
326
+ run: npm run build --workspace=backend
327
+
328
+ - name: Deploy to Render
329
+ run: |
330
+ echo "Deploy to Render by connecting your GitHub repository"
331
+ echo "Or use: render deploy --service=\${{ secrets.RENDER_SERVICE_ID }}"
332
+ continue-on-error: true
333
+ `;
334
+ }
335
+ deployWorkflow += `\n`;
336
+ await fs_extra_1.default.writeFile(path_1.default.join(workflowsPath, 'deploy.yml'), deployWorkflow);
337
+ }
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "projects-init-cli",
3
+ "version": "2.0.0",
4
+ "description": "CLI tool to initialize projects with customizable frontend, backend, and storage options",
5
+ "main": "dist/index.js",
6
+ "bin": {
7
+ "projects-init": "./dist/index.js"
8
+ },
9
+ "scripts": {
10
+ "build": "tsc",
11
+ "start": "node dist/index.js",
12
+ "dev": "ts-node src/index.ts",
13
+ "prepublishOnly": "npm run build",
14
+ "prepack": "npm run build"
15
+ },
16
+ "keywords": [
17
+ "cli",
18
+ "scaffold",
19
+ "project-generator",
20
+ "nextjs",
21
+ "react",
22
+ "express",
23
+ "nestjs",
24
+ "fastapi"
25
+ ],
26
+ "author": "",
27
+ "license": "MIT",
28
+ "files": [
29
+ "dist",
30
+ "README.md"
31
+ ],
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/yourusername/projects-init-cli.git"
35
+ },
36
+ "engines": {
37
+ "node": ">=18.0.0"
38
+ },
39
+ "dependencies": {
40
+ "commander": "^11.1.0",
41
+ "inquirer": "^9.2.12",
42
+ "chalk": "^4.1.2",
43
+ "fs-extra": "^11.2.0"
44
+ },
45
+ "devDependencies": {
46
+ "@types/inquirer": "^9.0.7",
47
+ "@types/node": "^20.10.6",
48
+ "@types/fs-extra": "^11.0.4",
49
+ "typescript": "^5.3.3",
50
+ "ts-node": "^10.9.2"
51
+ }
52
+ }