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.
- package/bin/backlist.js +227 -0
- package/package.json +10 -4
- package/src/analyzer.js +210 -89
- package/src/db/prisma.ts +4 -0
- package/src/generators/dotnet.js +120 -94
- package/src/generators/java.js +157 -109
- package/src/generators/node.js +262 -85
- package/src/generators/template.js +38 -2
- package/src/scanner/index.js +99 -0
- package/src/templates/dotnet/partials/Controller.cs.ejs +7 -14
- package/src/templates/dotnet/partials/Dto.cs.ejs +8 -0
- package/src/templates/java-spring/partials/ApplicationSeeder.java.ejs +7 -2
- package/src/templates/java-spring/partials/AuthController.java.ejs +23 -10
- package/src/templates/java-spring/partials/Controller.java.ejs +17 -6
- package/src/templates/java-spring/partials/Dockerfile.ejs +6 -1
- package/src/templates/java-spring/partials/Entity.java.ejs +15 -5
- package/src/templates/java-spring/partials/JwtAuthFilter.java.ejs +30 -7
- package/src/templates/java-spring/partials/JwtService.java.ejs +38 -10
- package/src/templates/java-spring/partials/Repository.java.ejs +10 -1
- package/src/templates/java-spring/partials/Service.java.ejs +45 -7
- package/src/templates/java-spring/partials/User.java.ejs +17 -4
- package/src/templates/java-spring/partials/UserDetailsServiceImpl.java.ejs +10 -4
- package/src/templates/java-spring/partials/UserRepository.java.ejs +8 -0
- package/src/templates/java-spring/partials/docker-compose.yml.ejs +16 -8
- package/src/templates/node-ts-express/base/server.ts +12 -5
- package/src/templates/node-ts-express/base/tsconfig.json +13 -3
- package/src/templates/node-ts-express/partials/ApiDocs.ts.ejs +17 -7
- package/src/templates/node-ts-express/partials/App.test.ts.ejs +27 -27
- package/src/templates/node-ts-express/partials/Auth.controller.ts.ejs +56 -62
- package/src/templates/node-ts-express/partials/Auth.middleware.ts.ejs +21 -10
- package/src/templates/node-ts-express/partials/Controller.ts.ejs +40 -40
- package/src/templates/node-ts-express/partials/DbContext.cs.ejs +3 -3
- package/src/templates/node-ts-express/partials/Dockerfile.ejs +9 -11
- package/src/templates/node-ts-express/partials/Model.cs.ejs +25 -7
- package/src/templates/node-ts-express/partials/Model.ts.ejs +20 -12
- package/src/templates/node-ts-express/partials/PrismaController.ts.ejs +72 -55
- package/src/templates/node-ts-express/partials/PrismaSchema.prisma.ejs +27 -12
- package/src/templates/node-ts-express/partials/README.md.ejs +9 -12
- package/src/templates/node-ts-express/partials/Seeder.ts.ejs +44 -64
- package/src/templates/node-ts-express/partials/docker-compose.yml.ejs +31 -16
- package/src/templates/node-ts-express/partials/package.json.ejs +3 -1
- package/src/templates/node-ts-express/partials/prismaClient.ts.ejs +4 -0
- package/src/templates/node-ts-express/partials/routes.ts.ejs +35 -24
- package/src/utils.js +19 -4
- package/bin/index.js +0 -141
|
@@ -1,26 +1,41 @@
|
|
|
1
|
-
// Auto-generated by create-backlist v5.
|
|
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"
|
|
8
|
+
provider = "postgresql"
|
|
9
9
|
url = env("DATABASE_URL")
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
|
|
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
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
##
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
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';
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
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
|
-
|
|
30
|
-
const
|
|
31
|
-
|
|
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
|
-
|
|
36
|
-
|
|
20
|
+
await mongoose.connect(MONGO_URI);
|
|
21
|
+
console.log(chalk.green('MongoDB Connected for Seeder...'));
|
|
22
|
+
}
|
|
37
23
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
57
|
-
|
|
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
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
72
|
-
|
|
73
|
-
|
|
44
|
+
async function run() {
|
|
45
|
+
try {
|
|
46
|
+
await connectDB();
|
|
74
47
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
|
|
63
|
+
run();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# Auto-generated by create-backlist v5.
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
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
|
-
|
|
23
|
-
image: mongo:
|
|
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
|
-
|
|
30
|
-
|
|
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
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
58
|
+
<% if (dbType === 'mongoose') { -%>
|
|
44
59
|
mongo-data:
|
|
45
|
-
|
|
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
|
-
"
|
|
10
|
+
"typecheck": "tsc --noEmit",
|
|
11
|
+
"clean": "rimraf dist"
|
|
10
12
|
},
|
|
11
13
|
"dependencies": {
|
|
12
14
|
"cors": "^2.8.5",
|
|
@@ -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
|
-
|
|
3
|
+
|
|
4
|
+
<%
|
|
5
|
+
/**
|
|
6
|
+
* Collect controllers safely
|
|
7
|
+
*/
|
|
5
8
|
const controllers = [];
|
|
6
9
|
if (Array.isArray(endpoints)) {
|
|
7
|
-
endpoints.forEach(
|
|
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
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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 &&
|
|
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 %>(
|
|
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
|
-
//
|
|
6
|
-
|
|
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();
|