create-backlist 6.0.0 → 6.0.2

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 (45) hide show
  1. package/bin/backlist.js +227 -0
  2. package/package.json +10 -4
  3. package/src/analyzer.js +210 -89
  4. package/src/db/prisma.ts +4 -0
  5. package/src/generators/dotnet.js +120 -94
  6. package/src/generators/java.js +157 -109
  7. package/src/generators/node.js +262 -85
  8. package/src/generators/template.js +38 -2
  9. package/src/scanner/index.js +99 -0
  10. package/src/templates/dotnet/partials/Controller.cs.ejs +7 -14
  11. package/src/templates/dotnet/partials/Dto.cs.ejs +8 -0
  12. package/src/templates/java-spring/partials/ApplicationSeeder.java.ejs +7 -2
  13. package/src/templates/java-spring/partials/AuthController.java.ejs +23 -10
  14. package/src/templates/java-spring/partials/Controller.java.ejs +17 -6
  15. package/src/templates/java-spring/partials/Dockerfile.ejs +6 -1
  16. package/src/templates/java-spring/partials/Entity.java.ejs +15 -5
  17. package/src/templates/java-spring/partials/JwtAuthFilter.java.ejs +30 -7
  18. package/src/templates/java-spring/partials/JwtService.java.ejs +38 -10
  19. package/src/templates/java-spring/partials/Repository.java.ejs +10 -1
  20. package/src/templates/java-spring/partials/Service.java.ejs +45 -7
  21. package/src/templates/java-spring/partials/User.java.ejs +17 -4
  22. package/src/templates/java-spring/partials/UserDetailsServiceImpl.java.ejs +10 -4
  23. package/src/templates/java-spring/partials/UserRepository.java.ejs +8 -0
  24. package/src/templates/java-spring/partials/docker-compose.yml.ejs +16 -8
  25. package/src/templates/node-ts-express/base/server.ts +12 -5
  26. package/src/templates/node-ts-express/base/tsconfig.json +13 -3
  27. package/src/templates/node-ts-express/partials/ApiDocs.ts.ejs +17 -7
  28. package/src/templates/node-ts-express/partials/App.test.ts.ejs +27 -27
  29. package/src/templates/node-ts-express/partials/Auth.controller.ts.ejs +56 -62
  30. package/src/templates/node-ts-express/partials/Auth.middleware.ts.ejs +21 -10
  31. package/src/templates/node-ts-express/partials/Controller.ts.ejs +40 -40
  32. package/src/templates/node-ts-express/partials/DbContext.cs.ejs +3 -3
  33. package/src/templates/node-ts-express/partials/Dockerfile.ejs +9 -11
  34. package/src/templates/node-ts-express/partials/Model.cs.ejs +25 -7
  35. package/src/templates/node-ts-express/partials/Model.ts.ejs +20 -12
  36. package/src/templates/node-ts-express/partials/PrismaController.ts.ejs +72 -55
  37. package/src/templates/node-ts-express/partials/PrismaSchema.prisma.ejs +27 -12
  38. package/src/templates/node-ts-express/partials/README.md.ejs +9 -12
  39. package/src/templates/node-ts-express/partials/Seeder.ts.ejs +44 -64
  40. package/src/templates/node-ts-express/partials/docker-compose.yml.ejs +31 -16
  41. package/src/templates/node-ts-express/partials/package.json.ejs +3 -1
  42. package/src/templates/node-ts-express/partials/prismaClient.ts.ejs +4 -0
  43. package/src/templates/node-ts-express/partials/routes.ts.ejs +35 -24
  44. package/src/utils.js +19 -4
  45. package/bin/index.js +0 -141
@@ -1,26 +1,41 @@
1
- // Auto-generated by create-backlist v5.0
1
+ // Auto-generated by create-backlist v5.1
2
2
 
3
3
  generator client {
4
4
  provider = "prisma-client-js"
5
5
  }
6
6
 
7
7
  datasource db {
8
- provider = "postgresql" // User can change to "mysql", "sqlite", "sqlserver", etc.
8
+ provider = "postgresql"
9
9
  url = env("DATABASE_URL")
10
10
  }
11
11
 
12
- <%# Loop through each model identified by the analyzer %>
12
+ <%
13
+ function mapPrismaType(t) {
14
+ const x = String(t || '').toLowerCase();
15
+ if (x === 'number' || x === 'int' || x === 'integer') return 'Int';
16
+ if (x === 'float' || x === 'double') return 'Float';
17
+ if (x === 'boolean' || x === 'bool') return 'Boolean';
18
+ if (x === 'date' || x === 'datetime') return 'DateTime';
19
+ return 'String';
20
+ }
21
+
22
+ function safeName(n) {
23
+ return String(n || '').replace(/[^a-zA-Z0-9_]/g, '');
24
+ }
25
+ %>
26
+
13
27
  <% modelsToGenerate.forEach(model => { %>
14
- model <%= model.name %> {
28
+ model <%= safeName(model.name) %> {
15
29
  id String @id @default(cuid())
16
- <%# Loop through each field in the model %>
17
- <% model.fields.forEach(field => { %>
18
- <%# Map JS types to Prisma types. This is a basic mapping. %>
19
- <% let prismaType = 'String'; %>
20
- <% if (field.type === 'Number') prismaType = 'Int'; %>
21
- <% if (field.type === 'Boolean') prismaType = 'Boolean'; %>
22
- <%= field.name.padEnd(10) %> <%= prismaType %><%- field.isOptional ? '?' : '' %><%- field.isUnique ? ' @unique' : '' %>
23
- <% }); %>
30
+
31
+ <% (model.fields || []).forEach(field => {
32
+ const fname = safeName(field.name);
33
+ const prismaType = mapPrismaType(field.type);
34
+ const optional = field.isOptional ? '?' : '';
35
+ const unique = field.isUnique ? ' @unique' : '';
36
+ -%>
37
+ <%= fname %> <%= prismaType %><%= optional %><%= unique %>
38
+ <% }); -%>
24
39
 
25
40
  createdAt DateTime @default(now())
26
41
  updatedAt DateTime @updatedAt
@@ -2,15 +2,12 @@
2
2
 
3
3
  This backend was auto-generated by **Backlist**.
4
4
 
5
- ## šŸš€ Getting Started
6
-
7
- 1. **Navigate to the directory:**
8
- ```bash
9
- cd <%= projectName %>
10
- ```
11
-
12
- 2. **Run the development server:**
13
- ```bash
14
- npm run dev
15
- ```
16
- The server will start on `http://localhost:8000`.
5
+ ## Requirements
6
+ - Node.js 18+
7
+ - npm 9+
8
+
9
+ <% if (dbType === 'prisma') { -%>
10
+ ## Database (Prisma + PostgreSQL)
11
+ 1. Copy env:
12
+ ```bash
13
+ cp .env.example .env
@@ -1,83 +1,63 @@
1
- // Auto-generated by create-backlist v4.0 on <%= new Date().toISOString() %>
1
+ // Auto-generated by create-backlist v5.1 on <%= new Date().toISOString() %>
2
2
  import mongoose from 'mongoose';
3
3
  import dotenv from 'dotenv';
4
4
  import { faker } from '@faker-js/faker';
5
- import chalk from 'chalk'; // For colorful console logs
5
+ import chalk from 'chalk';
6
6
 
7
- // Load env vars
8
7
  dotenv.config();
9
8
 
10
- // We assume a User model exists for seeding.
11
- // The path is relative to the generated 'backend' project root.
12
9
  import User from '../src/models/User.model';
13
10
 
14
- // --- Connect to DB ---
15
- const connectDB = async () => {
16
- try {
17
- const MONGO_URI = process.env.MONGO_URI || 'mongodb://127.0.0.1:27017/<%= projectName %>';
18
- if (!MONGO_URI) {
19
- throw new Error('MONGO_URI is not defined in your .env file');
20
- }
21
- await mongoose.connect(MONGO_URI);
22
- console.log(chalk.green('MongoDB Connected for Seeder...'));
23
- } catch (err) {
24
- console.error(chalk.red(`Seeder DB Connection Error: ${err.message}`));
25
- process.exit(1);
26
- }
27
- };
11
+ function getErrorMessage(err: unknown) {
12
+ if (err instanceof Error) return err.message;
13
+ return String(err);
14
+ }
28
15
 
29
- // --- Import Data ---
30
- const importData = async () => {
31
- try {
32
- // Clear existing data
33
- await User.deleteMany();
16
+ async function connectDB() {
17
+ const MONGO_URI = process.env.MONGO_URI || 'mongodb://127.0.0.1:27017/<%= projectName %>';
18
+ if (!MONGO_URI) throw new Error('MONGO_URI is not defined');
34
19
 
35
- const sampleUsers = [];
36
- const userCount = 10; // Number of sample users to create
20
+ await mongoose.connect(MONGO_URI);
21
+ console.log(chalk.green('MongoDB Connected for Seeder...'));
22
+ }
37
23
 
38
- for (let i = 0; i < userCount; i++) {
39
- sampleUsers.push({
40
- name: faker.person.fullName(),
41
- email: faker.internet.email().toLowerCase(),
42
- password: 'password123', // All sample users will have the same password for easy testing
43
- });
44
- }
24
+ async function importData() {
25
+ // Clear existing data
26
+ await User.deleteMany({});
45
27
 
46
- await User.insertMany(sampleUsers);
28
+ const sampleUsers = Array.from({ length: 10 }).map(() => ({
29
+ name: faker.person.fullName(),
30
+ email: faker.internet.email().toLowerCase(),
31
+ password: 'password123',
32
+ }));
47
33
 
48
- console.log(chalk.green.bold('āœ… Data Imported Successfully!'));
49
- process.exit();
50
- } catch (error) {
51
- console.error(chalk.red(`Error with data import: ${error.message}`));
52
- process.exit(1);
53
- }
54
- };
34
+ await User.insertMany(sampleUsers);
55
35
 
56
- // --- Destroy Data ---
57
- const destroyData = async () => {
58
- try {
59
- await User.deleteMany();
60
- // If you have other models, you can add them here for destruction
61
- // e.g., await Product.deleteMany();
36
+ console.log(chalk.green.bold('Data Imported Successfully!'));
37
+ }
62
38
 
63
- console.log(chalk.red.bold('šŸ”„ Data Destroyed Successfully!'));
64
- process.exit();
65
- } catch (error) {
66
- console.error(chalk.red(`Error with data destruction: ${error.message}`));
67
- process.exit(1);
68
- }
69
- };
39
+ async function destroyData() {
40
+ await User.deleteMany({});
41
+ console.log(chalk.red.bold('Data Destroyed Successfully!'));
42
+ }
70
43
 
71
- // --- CLI Logic to run the seeder ---
72
- const runSeeder = async () => {
73
- await connectDB();
44
+ async function run() {
45
+ try {
46
+ await connectDB();
74
47
 
75
- // process.argv[2] will be '-d' if the script is run with `npm run destroy`
76
- if (process.argv[2] === '-d') {
77
- await destroyData();
78
- } else {
79
- await importData();
48
+ if (process.argv.includes('-d')) {
49
+ await destroyData();
50
+ } else {
51
+ await importData();
52
+ }
53
+ } catch (err) {
54
+ console.error(chalk.red(`Seeder error: ${getErrorMessage(err)}`));
55
+ process.exitCode = 1;
56
+ } finally {
57
+ try {
58
+ await mongoose.disconnect();
59
+ } catch {}
80
60
  }
81
- };
61
+ }
82
62
 
83
- runSeeder();
63
+ run();
@@ -1,4 +1,4 @@
1
- # Auto-generated by create-backlist v5.0
1
+ # Auto-generated by create-backlist v5.1
2
2
  version: '3.8'
3
3
 
4
4
  services:
@@ -8,40 +8,55 @@ services:
8
8
  ports:
9
9
  - '<%= port %>:<%= port %>'
10
10
  environment:
11
- - PORT=<%= port %>
12
- - DATABASE_URL=${DATABASE_URL}
13
- - JWT_SECRET=${JWT_SECRET}
11
+ PORT: <%= port %>
12
+ JWT_SECRET: ${JWT_SECRET:-change_me_long_secret_change_me_long_secret}
13
+ <% if (dbType === 'mongoose') { -%>
14
+ MONGO_URI: ${MONGO_URI:-mongodb://db:27017/<%= projectName %>}
15
+ <% } else if (dbType === 'prisma') { -%>
16
+ DATABASE_URL: ${DATABASE_URL:-postgresql://${DB_USER:-postgres}:${DB_PASSWORD:-password}@db:5432/${DB_NAME:-<%= projectName %>}?schema=public}
17
+ <% } -%>
14
18
  depends_on:
15
- - db
19
+ db:
20
+ condition: service_healthy
16
21
  volumes:
17
22
  - .:/usr/src/app
18
23
  - /usr/src/app/node_modules
19
24
  command: npm run dev
20
25
 
21
26
  db:
22
- <% if (dbType === 'mongoose') { %>
23
- image: mongo:latest
27
+ <% if (dbType === 'mongoose') { -%>
28
+ image: mongo:7
24
29
  container_name: <%= projectName %>-mongo-db
25
30
  ports:
26
31
  - '27017:27017'
27
32
  volumes:
28
33
  - mongo-data:/data/db
29
- <% } else if (dbType === 'prisma') { %>
30
- image: postgres:14-alpine
34
+ healthcheck:
35
+ test: ["CMD", "mongosh", "--quiet", "mongodb://localhost:27017/admin", "--eval", "db.adminCommand('ping').ok"]
36
+ interval: 5s
37
+ timeout: 5s
38
+ retries: 20
39
+ <% } else if (dbType === 'prisma') { -%>
40
+ image: postgres:16-alpine
31
41
  container_name: <%= projectName %>-postgres-db
32
42
  ports:
33
43
  - '5432:5432'
34
44
  environment:
35
- - POSTGRES_USER=${DB_USER}
36
- - POSTGRES_PASSWORD=${DB_PASSWORD}
37
- - POSTGRES_DB=${DB_NAME}
45
+ POSTGRES_USER: ${DB_USER:-postgres}
46
+ POSTGRES_PASSWORD: ${DB_PASSWORD:-password}
47
+ POSTGRES_DB: ${DB_NAME:-<%= projectName %>}
38
48
  volumes:
39
49
  - postgres-data:/var/lib/postgresql/data
40
- <% } %>
50
+ healthcheck:
51
+ test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-postgres} -d ${DB_NAME:-<%= projectName %>}"]
52
+ interval: 5s
53
+ timeout: 5s
54
+ retries: 20
55
+ <% } -%>
41
56
 
42
57
  volumes:
43
- <% if (dbType === 'mongoose') { %>
58
+ <% if (dbType === 'mongoose') { -%>
44
59
  mongo-data:
45
- <% } else if (dbType === 'prisma') { %>
60
+ <% } else if (dbType === 'prisma') { -%>
46
61
  postgres-data:
47
- <% } %>
62
+ <% } -%>
@@ -4,9 +4,11 @@
4
4
  "private": true,
5
5
  "main": "dist/server.js",
6
6
  "scripts": {
7
+ "dev": "ts-node-dev --respawn --transpile-only src/server.ts",
7
8
  "build": "tsc",
8
9
  "start": "node dist/server.js",
9
- "dev": "ts-node-dev --respawn --transpile-only src/server.ts"
10
+ "typecheck": "tsc --noEmit",
11
+ "clean": "rimraf dist"
10
12
  },
11
13
  "dependencies": {
12
14
  "cors": "^2.8.5",
@@ -0,0 +1,4 @@
1
+ // Auto-generated by create-backlist
2
+ import { PrismaClient } from '@prisma/client';
3
+
4
+ export const prisma = new PrismaClient();
@@ -1,56 +1,67 @@
1
1
  // Auto-generated by create-backlist on <%= new Date().toISOString() %>
2
2
  import { Router, Request, Response } from 'express';
3
- <%
4
- // Build unique controller list safely
3
+
4
+ <%
5
+ /**
6
+ * Collect controllers safely
7
+ */
5
8
  const controllers = [];
6
9
  if (Array.isArray(endpoints)) {
7
- endpoints.forEach((ep) => {
10
+ endpoints.forEach(ep => {
8
11
  if (ep && ep.controllerName && ep.controllerName !== 'Default' && !controllers.includes(ep.controllerName)) {
9
12
  controllers.push(ep.controllerName);
10
13
  }
11
14
  });
12
15
  }
13
16
  %>
17
+
14
18
  <% controllers.forEach((ctrl) => { %>
15
19
  import * as <%= ctrl %>Controller from './controllers/<%= ctrl %>.controller';
16
20
  <% }) %>
17
21
 
18
- <% if (addAuth) { %>
22
+ <% if (addAuth) { -%>
19
23
  import { protect } from './middleware/Auth.middleware';
20
- <% } %>
24
+ <% } -%>
21
25
 
22
26
  const router = Router();
23
27
 
24
- // If no endpoints detected, emit a basic route so file is valid
25
28
  <% if (!Array.isArray(endpoints) || endpoints.length === 0) { %>
26
29
  router.get('/health', (_req: Request, res: Response) => {
27
30
  res.status(200).json({ ok: true, message: 'Auto-generated routes alive' });
28
31
  });
29
32
  <% } %>
30
33
 
31
- <%
34
+ <%
35
+ /**
36
+ * Render endpoints
37
+ * Prefer ep.route (normalized) and fallback to ep.path
38
+ */
32
39
  if (Array.isArray(endpoints)) {
33
- endpoints.forEach((ep) => {
34
- const rawPath = (ep && ep.path) ? ep.path : '/';
35
- const expressPath = (rawPath.replace(/^\/api/, '') || '/').replace(/{(\w+)}/g, ':$1');
36
- const method = ((ep && ep.method) ? ep.method : 'GET').toLowerCase();
37
- const ctrl = (ep && ep.controllerName) ? ep.controllerName : 'Default';
38
- const hasId = expressPath.includes(':');
39
- let handler = '';
40
+ endpoints.forEach((ep) => {
41
+ if (!ep) return;
40
42
 
41
- if (ctrl !== 'Default') {
42
- if (method === 'post' && !hasId) handler = `${ctrl}Controller.create${ctrl}`;
43
- else if (method === 'get' && !hasId) handler = `${ctrl}Controller.getAll${ctrl}s`;
44
- else if (method === 'get' && hasId) handler = `${ctrl}Controller.get${ctrl}ById`;
45
- else if (method === 'put' && hasId) handler = `${ctrl}Controller.update${ctrl}ById`;
46
- else if (method === 'delete' && hasId) handler = `${ctrl}Controller.delete${ctrl}ById`;
47
- }
43
+ const raw = (ep.route || ep.path || '/');
44
+ // mount router at /api in server.ts, so here we remove leading /api
45
+ const expressPath = (String(raw).replace(/^\/api/, '') || '/')
46
+ .replace(/{(\w+)}/g, ':$1'); // backward compat if analyzer still produces {id}
47
+
48
+ const method = String(ep.method || 'GET').toLowerCase();
49
+ const ctrl = ep.controllerName || 'Default';
50
+ const action = ep.actionName || null;
48
51
 
49
- const needsProtect = !!addAuth && (method === 'post' || method === 'put' || method === 'delete');
52
+ const needsProtect = !!addAuth && method !== 'get'; // default: protect non-GET
50
53
  const middleware = needsProtect ? 'protect, ' : '';
54
+
55
+ let handler = '';
56
+ if (ctrl !== 'Default' && action) {
57
+ handler = `${ctrl}Controller.${action}`;
58
+ }
51
59
  %>
52
- router.<%= method %>('<%- expressPath || "/" %>', <%- middleware %><%- handler || '(req: Request, res: Response) => res.status(501).json({ message: "Not Implemented" })' %>);
53
- <%
60
+ router.<%= method %>(
61
+ '<%- expressPath %>',
62
+ <%- middleware %><%- handler || '(req: Request, res: Response) => res.status(501).json({ message: "Not Implemented" })' %>
63
+ );
64
+ <%
54
65
  });
55
66
  }
56
67
  %>
package/src/utils.js CHANGED
@@ -1,12 +1,27 @@
1
1
  const { execa } = require('execa');
2
2
 
3
+ const VERSION_ARGS = {
4
+ java: ['-version'],
5
+ python: ['--version'],
6
+ python3: ['--version'],
7
+ node: ['--version'],
8
+ npm: ['--version'],
9
+ dotnet: ['--version'],
10
+ mvn: ['-v'],
11
+ git: ['--version'],
12
+ };
13
+
3
14
  async function isCommandAvailable(command) {
15
+ const args = VERSION_ARGS[command] || ['--version'];
16
+
4
17
  try {
5
- // Using a harmless version command to check for presence
6
- const checkCommand = command === 'java' ? '-version' : '--version';
7
- await execa(command, [checkCommand]);
18
+ // Reject false only if spawn fails (ENOENT). Non-zero exit still counts as "available".
19
+ await execa(command, args, { reject: false });
8
20
  return true;
9
- } catch {
21
+ } catch (err) {
22
+ // If command not found, execa throws with code 'ENOENT'
23
+ if (err && err.code === 'ENOENT') return false;
24
+ // Other unexpected errors: treat as not available
10
25
  return false;
11
26
  }
12
27
  }
package/bin/index.js DELETED
@@ -1,141 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- const inquirer = require('inquirer');
4
- const chalk = require('chalk');
5
- const fs = require('fs-extra');
6
- const path = require('path'); // FIX: Correctly require the 'path' module
7
- const { isCommandAvailable } = require('../src/utils');
8
-
9
- // Import ALL generators
10
- const { generateNodeProject } = require('../src/generators/node');
11
- const { generateDotnetProject } = require('../src/generators/dotnet');
12
- const { generateJavaProject } = require('../src/generators/java');
13
- const { generatePythonProject } = require('../src/generators/python');
14
-
15
- async function main() {
16
- console.log(chalk.cyan.bold('šŸš€ Welcome to Backlist! The Polyglot Backend Generator.'));
17
-
18
- const answers = await inquirer.prompt([
19
- // --- General Questions ---
20
- {
21
- type: 'input',
22
- name: 'projectName',
23
- message: 'Enter a name for your backend directory:',
24
- default: 'backend',
25
- validate: input => input ? true : 'Project name cannot be empty.'
26
- },
27
- {
28
- type: 'list',
29
- name: 'stack',
30
- message: 'Select the backend stack:',
31
- choices: [
32
- { name: 'Node.js (TypeScript, Express)', value: 'node-ts-express' },
33
- { name: 'C# (ASP.NET Core Web API)', value: 'dotnet-webapi' },
34
- { name: 'Java (Spring Boot)', value: 'java-spring' },
35
- { name: 'Python (FastAPI)', value: 'python-fastapi' },
36
- ],
37
- },
38
- {
39
- type: 'input',
40
- name: 'srcPath',
41
- message: 'Enter the path to your frontend `src` directory:',
42
- default: 'src',
43
- },
44
-
45
- // --- Node.js Specific Questions ---
46
- {
47
- type: 'list',
48
- name: 'dbType',
49
- message: 'Select your database type for Node.js:',
50
- choices: [
51
- { name: 'NoSQL (MongoDB with Mongoose)', value: 'mongoose' },
52
- { name: 'SQL (PostgreSQL/MySQL with Prisma)', value: 'prisma' },
53
- ],
54
- when: (answers) => answers.stack === 'node-ts-express'
55
- },
56
- {
57
- type: 'confirm',
58
- name: 'addAuth',
59
- message: 'Add JWT authentication boilerplate?',
60
- default: true,
61
- when: (answers) => answers.stack === 'node-ts-express'
62
- },
63
- {
64
- type: 'confirm',
65
- name: 'addSeeder',
66
- message: 'Add a database seeder with sample data?',
67
- default: true,
68
- // Seeder only makes sense if there's an auth/user model to seed
69
- when: (answers) => answers.stack === 'node-ts-express' && answers.addAuth
70
- },
71
- {
72
- type: 'checkbox',
73
- name: 'extraFeatures',
74
- message: 'Select additional features for Node.js:',
75
- choices: [
76
- { name: 'Docker Support (Dockerfile & docker-compose.yml)', value: 'docker', checked: true },
77
- { name: 'API Testing Boilerplate (Jest & Supertest)', value: 'testing', checked: true },
78
- { name: 'API Documentation (Swagger UI)', value: 'swagger', checked: true },
79
- ],
80
- when: (answers) => answers.stack === 'node-ts-express'
81
- }
82
- ]);
83
-
84
- const options = {
85
- ...answers,
86
- projectDir: path.resolve(process.cwd(), answers.projectName),
87
- frontendSrcDir: path.resolve(process.cwd(), answers.srcPath),
88
- };
89
-
90
- try {
91
- console.log(chalk.blue(`\n✨ Starting backend generation for: ${chalk.bold(options.stack)}`));
92
-
93
- // --- Dispatcher Logic for ALL Stacks ---
94
- switch (options.stack) {
95
- case 'node-ts-express':
96
- await generateNodeProject(options);
97
- break;
98
-
99
- case 'dotnet-webapi':
100
- if (!await isCommandAvailable('dotnet')) {
101
- throw new Error('.NET SDK is not installed. Please install it from https://dotnet.microsoft.com/download');
102
- }
103
- await generateDotnetProject(options);
104
- break;
105
-
106
- case 'java-spring':
107
- if (!await isCommandAvailable('java')) {
108
- throw new Error('Java (JDK 17 or newer) is not installed. Please install a JDK to continue.');
109
- }
110
- await generateJavaProject(options);
111
- break;
112
-
113
- case 'python-fastapi':
114
- if (!await isCommandAvailable('python')) {
115
- throw new Error('Python is not installed. Please install Python (3.8+) and pip to continue.');
116
- }
117
- await generatePythonProject(options);
118
- break;
119
-
120
- default:
121
- throw new Error(`The selected stack '${options.stack}' is not supported yet.`);
122
- }
123
-
124
- console.log(chalk.green.bold('\nāœ… Backend generation complete!'));
125
- console.log('\nNext Steps:');
126
- console.log(chalk.cyan(` cd ${options.projectName}`));
127
- console.log(chalk.cyan(' (Check the generated README.md for instructions)'));
128
-
129
- } catch (error) {
130
- console.error(chalk.red.bold('\nāŒ An error occurred during generation:'));
131
- console.error(error);
132
-
133
- if (fs.existsSync(options.projectDir)) {
134
- console.log(chalk.yellow(' -> Cleaning up failed installation...'));
135
- fs.removeSync(options.projectDir);
136
- }
137
- process.exit(1);
138
- }
139
- }
140
-
141
- main();