create-backlist 6.0.6 → 6.0.8

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 (46) hide show
  1. package/bin/index.js +141 -0
  2. package/package.json +4 -10
  3. package/src/analyzer.js +105 -308
  4. package/src/generators/dotnet.js +94 -120
  5. package/src/generators/java.js +109 -157
  6. package/src/generators/node.js +85 -262
  7. package/src/generators/template.js +2 -38
  8. package/src/templates/dotnet/partials/Controller.cs.ejs +14 -7
  9. package/src/templates/java-spring/partials/ApplicationSeeder.java.ejs +2 -7
  10. package/src/templates/java-spring/partials/AuthController.java.ejs +10 -23
  11. package/src/templates/java-spring/partials/Controller.java.ejs +6 -17
  12. package/src/templates/java-spring/partials/Dockerfile.ejs +1 -6
  13. package/src/templates/java-spring/partials/Entity.java.ejs +5 -15
  14. package/src/templates/java-spring/partials/JwtAuthFilter.java.ejs +7 -30
  15. package/src/templates/java-spring/partials/JwtService.java.ejs +10 -38
  16. package/src/templates/java-spring/partials/Repository.java.ejs +1 -10
  17. package/src/templates/java-spring/partials/Service.java.ejs +7 -45
  18. package/src/templates/java-spring/partials/User.java.ejs +4 -17
  19. package/src/templates/java-spring/partials/UserDetailsServiceImpl.java.ejs +4 -10
  20. package/src/templates/java-spring/partials/UserRepository.java.ejs +0 -8
  21. package/src/templates/java-spring/partials/docker-compose.yml.ejs +8 -16
  22. package/src/templates/node-ts-express/base/server.ts +6 -13
  23. package/src/templates/node-ts-express/base/tsconfig.json +3 -13
  24. package/src/templates/node-ts-express/partials/ApiDocs.ts.ejs +7 -17
  25. package/src/templates/node-ts-express/partials/App.test.ts.ejs +26 -49
  26. package/src/templates/node-ts-express/partials/Auth.controller.ts.ejs +62 -56
  27. package/src/templates/node-ts-express/partials/Auth.middleware.ts.ejs +10 -21
  28. package/src/templates/node-ts-express/partials/Controller.ts.ejs +40 -40
  29. package/src/templates/node-ts-express/partials/DbContext.cs.ejs +3 -3
  30. package/src/templates/node-ts-express/partials/Dockerfile.ejs +11 -9
  31. package/src/templates/node-ts-express/partials/Model.cs.ejs +7 -25
  32. package/src/templates/node-ts-express/partials/Model.ts.ejs +12 -20
  33. package/src/templates/node-ts-express/partials/PrismaController.ts.ejs +55 -72
  34. package/src/templates/node-ts-express/partials/PrismaSchema.prisma.ejs +12 -27
  35. package/src/templates/node-ts-express/partials/README.md.ejs +12 -9
  36. package/src/templates/node-ts-express/partials/Seeder.ts.ejs +64 -44
  37. package/src/templates/node-ts-express/partials/docker-compose.yml.ejs +16 -31
  38. package/src/templates/node-ts-express/partials/package.json.ejs +1 -3
  39. package/src/templates/node-ts-express/partials/routes.ts.ejs +24 -35
  40. package/src/utils.js +4 -19
  41. package/bin/backlist.js +0 -227
  42. package/src/db/prisma.ts +0 -4
  43. package/src/scanner/analyzeFrontend.js +0 -146
  44. package/src/scanner/index.js +0 -99
  45. package/src/templates/dotnet/partials/Dto.cs.ejs +0 -8
  46. package/src/templates/node-ts-express/partials/prismaClient.ts.ejs +0 -4
@@ -1,63 +1,83 @@
1
- // Auto-generated by create-backlist v5.1 on <%= new Date().toISOString() %>
1
+ // Auto-generated by create-backlist v4.0 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'; // For colorful console logs
6
6
 
7
+ // Load env vars
7
8
  dotenv.config();
8
9
 
10
+ // We assume a User model exists for seeding.
11
+ // The path is relative to the generated 'backend' project root.
9
12
  import User from '../src/models/User.model';
10
13
 
11
- function getErrorMessage(err: unknown) {
12
- if (err instanceof Error) return err.message;
13
- return String(err);
14
- }
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
+ };
15
28
 
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');
29
+ // --- Import Data ---
30
+ const importData = async () => {
31
+ try {
32
+ // Clear existing data
33
+ await User.deleteMany();
19
34
 
20
- await mongoose.connect(MONGO_URI);
21
- console.log(chalk.green('MongoDB Connected for Seeder...'));
22
- }
35
+ const sampleUsers = [];
36
+ const userCount = 10; // Number of sample users to create
23
37
 
24
- async function importData() {
25
- // Clear existing data
26
- await User.deleteMany({});
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
+ }
27
45
 
28
- const sampleUsers = Array.from({ length: 10 }).map(() => ({
29
- name: faker.person.fullName(),
30
- email: faker.internet.email().toLowerCase(),
31
- password: 'password123',
32
- }));
46
+ await User.insertMany(sampleUsers);
33
47
 
34
- await User.insertMany(sampleUsers);
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
+ };
35
55
 
36
- console.log(chalk.green.bold('Data Imported Successfully!'));
37
- }
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();
38
62
 
39
- async function destroyData() {
40
- await User.deleteMany({});
41
- console.log(chalk.red.bold('Data Destroyed Successfully!'));
42
- }
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
+ };
43
70
 
44
- async function run() {
45
- try {
46
- await connectDB();
71
+ // --- CLI Logic to run the seeder ---
72
+ const runSeeder = async () => {
73
+ await connectDB();
47
74
 
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 {}
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();
60
80
  }
61
- }
81
+ };
62
82
 
63
- run();
83
+ runSeeder();
@@ -1,4 +1,4 @@
1
- # Auto-generated by create-backlist v5.1
1
+ # Auto-generated by create-backlist v5.0
2
2
  version: '3.8'
3
3
 
4
4
  services:
@@ -8,55 +8,40 @@ services:
8
8
  ports:
9
9
  - '<%= port %>:<%= port %>'
10
10
  environment:
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
- <% } -%>
11
+ - PORT=<%= port %>
12
+ - DATABASE_URL=${DATABASE_URL}
13
+ - JWT_SECRET=${JWT_SECRET}
18
14
  depends_on:
19
- db:
20
- condition: service_healthy
15
+ - db
21
16
  volumes:
22
17
  - .:/usr/src/app
23
18
  - /usr/src/app/node_modules
24
19
  command: npm run dev
25
20
 
26
21
  db:
27
- <% if (dbType === 'mongoose') { -%>
28
- image: mongo:7
22
+ <% if (dbType === 'mongoose') { %>
23
+ image: mongo:latest
29
24
  container_name: <%= projectName %>-mongo-db
30
25
  ports:
31
26
  - '27017:27017'
32
27
  volumes:
33
28
  - mongo-data:/data/db
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
29
+ <% } else if (dbType === 'prisma') { %>
30
+ image: postgres:14-alpine
41
31
  container_name: <%= projectName %>-postgres-db
42
32
  ports:
43
33
  - '5432:5432'
44
34
  environment:
45
- POSTGRES_USER: ${DB_USER:-postgres}
46
- POSTGRES_PASSWORD: ${DB_PASSWORD:-password}
47
- POSTGRES_DB: ${DB_NAME:-<%= projectName %>}
35
+ - POSTGRES_USER=${DB_USER}
36
+ - POSTGRES_PASSWORD=${DB_PASSWORD}
37
+ - POSTGRES_DB=${DB_NAME}
48
38
  volumes:
49
39
  - postgres-data:/var/lib/postgresql/data
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
- <% } -%>
40
+ <% } %>
56
41
 
57
42
  volumes:
58
- <% if (dbType === 'mongoose') { -%>
43
+ <% if (dbType === 'mongoose') { %>
59
44
  mongo-data:
60
- <% } else if (dbType === 'prisma') { -%>
45
+ <% } else if (dbType === 'prisma') { %>
61
46
  postgres-data:
62
- <% } -%>
47
+ <% } %>
@@ -4,11 +4,9 @@
4
4
  "private": true,
5
5
  "main": "dist/server.js",
6
6
  "scripts": {
7
- "dev": "ts-node-dev --respawn --transpile-only src/server.ts",
8
7
  "build": "tsc",
9
8
  "start": "node dist/server.js",
10
- "typecheck": "tsc --noEmit",
11
- "clean": "rimraf dist"
9
+ "dev": "ts-node-dev --respawn --transpile-only src/server.ts"
12
10
  },
13
11
  "dependencies": {
14
12
  "cors": "^2.8.5",
@@ -1,67 +1,56 @@
1
1
  // Auto-generated by create-backlist on <%= new Date().toISOString() %>
2
2
  import { Router, Request, Response } from 'express';
3
-
4
- <%
5
- /**
6
- * Collect controllers safely
7
- */
3
+ <%
4
+ // Build unique controller list safely
8
5
  const controllers = [];
9
6
  if (Array.isArray(endpoints)) {
10
- endpoints.forEach(ep => {
7
+ endpoints.forEach((ep) => {
11
8
  if (ep && ep.controllerName && ep.controllerName !== 'Default' && !controllers.includes(ep.controllerName)) {
12
9
  controllers.push(ep.controllerName);
13
10
  }
14
11
  });
15
12
  }
16
13
  %>
17
-
18
14
  <% controllers.forEach((ctrl) => { %>
19
15
  import * as <%= ctrl %>Controller from './controllers/<%= ctrl %>.controller';
20
16
  <% }) %>
21
17
 
22
- <% if (addAuth) { -%>
18
+ <% if (addAuth) { %>
23
19
  import { protect } from './middleware/Auth.middleware';
24
- <% } -%>
20
+ <% } %>
25
21
 
26
22
  const router = Router();
27
23
 
24
+ // If no endpoints detected, emit a basic route so file is valid
28
25
  <% if (!Array.isArray(endpoints) || endpoints.length === 0) { %>
29
26
  router.get('/health', (_req: Request, res: Response) => {
30
27
  res.status(200).json({ ok: true, message: 'Auto-generated routes alive' });
31
28
  });
32
29
  <% } %>
33
30
 
34
- <%
35
- /**
36
- * Render endpoints
37
- * Prefer ep.route (normalized) and fallback to ep.path
38
- */
31
+ <%
39
32
  if (Array.isArray(endpoints)) {
40
- endpoints.forEach((ep) => {
41
- if (!ep) return;
42
-
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}
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 = '';
47
40
 
48
- const method = String(ep.method || 'GET').toLowerCase();
49
- const ctrl = ep.controllerName || 'Default';
50
- const action = ep.actionName || null;
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
+ }
51
48
 
52
- const needsProtect = !!addAuth && method !== 'get'; // default: protect non-GET
49
+ const needsProtect = !!addAuth && (method === 'post' || method === 'put' || method === 'delete');
53
50
  const middleware = needsProtect ? 'protect, ' : '';
54
-
55
- let handler = '';
56
- if (ctrl !== 'Default' && action) {
57
- handler = `${ctrl}Controller.${action}`;
58
- }
59
51
  %>
60
- router.<%= method %>(
61
- '<%- expressPath %>',
62
- <%- middleware %><%- handler || '(req: Request, res: Response) => res.status(501).json({ message: "Not Implemented" })' %>
63
- );
64
- <%
52
+ router.<%= method %>('<%- expressPath || "/" %>', <%- middleware %><%- handler || '(req: Request, res: Response) => res.status(501).json({ message: "Not Implemented" })' %>);
53
+ <%
65
54
  });
66
55
  }
67
56
  %>
package/src/utils.js CHANGED
@@ -1,27 +1,12 @@
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
-
14
3
  async function isCommandAvailable(command) {
15
- const args = VERSION_ARGS[command] || ['--version'];
16
-
17
4
  try {
18
- // Reject false only if spawn fails (ENOENT). Non-zero exit still counts as "available".
19
- await execa(command, args, { reject: false });
5
+ // Using a harmless version command to check for presence
6
+ const checkCommand = command === 'java' ? '-version' : '--version';
7
+ await execa(command, [checkCommand]);
20
8
  return true;
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
9
+ } catch {
25
10
  return false;
26
11
  }
27
12
  }
package/bin/backlist.js DELETED
@@ -1,227 +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');
7
- const { Command } = require('commander');
8
- const chokidar = require('chokidar');
9
-
10
- const { isCommandAvailable } = require('../src/utils');
11
-
12
- const { generateNodeProject } = require('../src/generators/node');
13
- const { generateDotnetProject } = require('../src/generators/dotnet');
14
- const { generateJavaProject } = require('../src/generators/java');
15
- const { generatePythonProject } = require('../src/generators/python');
16
-
17
- const { scanFrontend, writeContracts } = require('../src/scanner');
18
-
19
- function resolveOptionsFromFlags(flags) {
20
- return {
21
- projectName: flags.projectName || 'backend',
22
- srcPath: flags.srcPath || 'src',
23
- stack: flags.stack || 'node-ts-express',
24
- dbType: flags.dbType,
25
- addAuth: flags.addAuth,
26
- addSeeder: flags.addSeeder,
27
- extraFeatures: flags.extraFeatures || [],
28
- projectDir: path.resolve(process.cwd(), flags.projectName || 'backend'),
29
- frontendSrcDir: path.resolve(process.cwd(), flags.srcPath || 'src'),
30
- };
31
- }
32
-
33
- async function runGeneration(options, contracts) {
34
- switch (options.stack) {
35
- case 'node-ts-express':
36
- await generateNodeProject({ ...options, contracts });
37
- break;
38
-
39
- case 'dotnet-webapi':
40
- if (!await isCommandAvailable('dotnet')) {
41
- throw new Error('.NET SDK is not installed. Please install it from https://dotnet.microsoft.com/download');
42
- }
43
- await generateDotnetProject({ ...options, contracts });
44
- break;
45
-
46
- case 'java-spring':
47
- if (!await isCommandAvailable('java')) {
48
- throw new Error('Java (JDK 17 or newer) is not installed. Please install a JDK to continue.');
49
- }
50
- await generateJavaProject({ ...options, contracts });
51
- break;
52
-
53
- case 'python-fastapi':
54
- if (!await isCommandAvailable('python')) {
55
- throw new Error('Python is not installed. Please install Python (3.8+) and pip to continue.');
56
- }
57
- await generatePythonProject({ ...options, contracts });
58
- break;
59
-
60
- default:
61
- throw new Error(`The selected stack '${options.stack}' is not supported yet.`);
62
- }
63
- }
64
-
65
- async function interactiveMain() {
66
- console.log(chalk.cyan.bold('Welcome to Backlist! The Polyglot Backend Generator.'));
67
-
68
- const answers = await inquirer.prompt([
69
- {
70
- type: 'input',
71
- name: 'projectName',
72
- message: 'Enter a name for your backend directory:',
73
- default: 'backend',
74
- validate: input => input ? true : 'Project name cannot be empty.'
75
- },
76
- {
77
- type: 'list',
78
- name: 'stack',
79
- message: 'Select the backend stack:',
80
- choices: [
81
- { name: 'Node.js (TypeScript, Express)', value: 'node-ts-express' },
82
- { name: 'C# (ASP.NET Core Web API)', value: 'dotnet-webapi' },
83
- { name: 'Java (Spring Boot)', value: 'java-spring' },
84
- { name: 'Python (FastAPI)', value: 'python-fastapi' },
85
- ],
86
- },
87
- {
88
- type: 'input',
89
- name: 'srcPath',
90
- message: 'Enter the path to your frontend `src` directory:',
91
- default: 'src',
92
- },
93
- {
94
- type: 'list',
95
- name: 'dbType',
96
- message: 'Select your database type for Node.js:',
97
- choices: [
98
- { name: 'NoSQL (MongoDB with Mongoose)', value: 'mongoose' },
99
- { name: 'SQL (PostgreSQL/MySQL with Prisma)', value: 'prisma' },
100
- ],
101
- when: (answers) => answers.stack === 'node-ts-express'
102
- },
103
- {
104
- type: 'confirm',
105
- name: 'addAuth',
106
- message: 'Add JWT authentication boilerplate?',
107
- default: true,
108
- when: (answers) => answers.stack === 'node-ts-express'
109
- },
110
- {
111
- type: 'confirm',
112
- name: 'addSeeder',
113
- message: 'Add a database seeder with sample data?',
114
- default: true,
115
- when: (answers) => answers.stack === 'node-ts-express' && answers.addAuth
116
- },
117
- {
118
- type: 'checkbox',
119
- name: 'extraFeatures',
120
- message: 'Select additional features for Node.js:',
121
- choices: [
122
- { name: 'Docker Support (Dockerfile & docker-compose.yml)', value: 'docker', checked: true },
123
- { name: 'API Testing Boilerplate (Jest & Supertest)', value: 'testing', checked: true },
124
- { name: 'API Documentation (Swagger UI)', value: 'swagger', checked: true },
125
- ],
126
- when: (answers) => answers.stack === 'node-ts-express'
127
- }
128
- ]);
129
-
130
- const options = {
131
- ...answers,
132
- projectDir: path.resolve(process.cwd(), answers.projectName),
133
- frontendSrcDir: path.resolve(process.cwd(), answers.srcPath),
134
- };
135
-
136
- const contracts = await scanFrontend({ frontendSrcDir: options.frontendSrcDir });
137
-
138
- try {
139
- console.log(chalk.blue(`\nStarting backend generation for: ${chalk.bold(options.stack)}`));
140
- await runGeneration(options, contracts);
141
-
142
- console.log(chalk.green.bold('\nBackend generation complete!'));
143
- console.log('\nNext Steps:');
144
- console.log(chalk.cyan(` cd ${options.projectName}`));
145
- console.log(chalk.cyan(' (Check the generated README.md for instructions)'));
146
- } catch (error) {
147
- console.error(chalk.red.bold('\nAn error occurred during generation:'));
148
- console.error(error);
149
-
150
- if (fs.existsSync(options.projectDir)) {
151
- console.log(chalk.yellow(' -> Cleaning up failed installation...'));
152
- fs.removeSync(options.projectDir);
153
- }
154
- process.exit(1);
155
- }
156
- }
157
-
158
- async function main() {
159
- const program = new Command();
160
-
161
- program
162
- .name('backlist')
163
- .description('Backlist CLI - generate backend from frontend via AST scan')
164
- .version('1.0.0');
165
-
166
- program.command('scan')
167
- .description('Scan frontend and write contracts JSON')
168
- .option('-s, --srcPath <path>', 'frontend src path', 'src')
169
- .option('-o, --out <file>', 'output contracts file', '.backlist/contracts.json')
170
- .action(async (flags) => {
171
- const frontendSrcDir = path.resolve(process.cwd(), flags.srcPath);
172
- const outFile = path.resolve(process.cwd(), flags.out);
173
- const contracts = await scanFrontend({ frontendSrcDir });
174
- await writeContracts(outFile, contracts);
175
- console.log(chalk.green(`Wrote contracts to ${outFile}`));
176
- });
177
-
178
- program.command('generate')
179
- .description('Generate backend using contracts')
180
- .requiredOption('-k, --stack <stack>', 'stack: node-ts-express | dotnet-webapi | java-spring | python-fastapi')
181
- .option('-p, --projectName <name>', 'backend directory', 'backend')
182
- .option('-s, --srcPath <path>', 'frontend src path', 'src')
183
- .option('-c, --contracts <file>', 'contracts file', '.backlist/contracts.json')
184
- .action(async (flags) => {
185
- const options = resolveOptionsFromFlags(flags);
186
- const contractsPath = path.resolve(process.cwd(), flags.contracts);
187
- const contracts = fs.existsSync(contractsPath)
188
- ? await fs.readJson(contractsPath)
189
- : await scanFrontend({ frontendSrcDir: options.frontendSrcDir });
190
-
191
- await runGeneration(options, contracts);
192
- console.log(chalk.green('Generation complete.'));
193
- });
194
-
195
- program.command('watch')
196
- .description('Watch frontend and regenerate backend on changes')
197
- .requiredOption('-k, --stack <stack>', 'stack')
198
- .option('-p, --projectName <name>', 'backend directory', 'backend')
199
- .option('-s, --srcPath <path>', 'frontend src path', 'src')
200
- .action(async (flags) => {
201
- const options = resolveOptionsFromFlags(flags);
202
- const watcher = chokidar.watch(options.frontendSrcDir, { ignoreInitial: true });
203
-
204
- const run = async () => {
205
- const contracts = await scanFrontend({ frontendSrcDir: options.frontendSrcDir });
206
- await runGeneration(options, contracts);
207
- console.log(chalk.green(`[watch] regenerated at ${new Date().toLocaleTimeString()}`));
208
- };
209
-
210
- await run();
211
- watcher.on('add', run).on('change', run).on('unlink', run);
212
- console.log(chalk.cyan(`[watch] watching ${options.frontendSrcDir}`));
213
- });
214
-
215
- // If no args => old interactive mode
216
- if (process.argv.length <= 2) {
217
- await interactiveMain();
218
- return;
219
- }
220
-
221
- await program.parseAsync(process.argv);
222
- }
223
-
224
- main().catch((e) => {
225
- console.error(e);
226
- process.exit(1);
227
- });
package/src/db/prisma.ts DELETED
@@ -1,4 +0,0 @@
1
- // Auto-generated by create-backlist
2
- import { PrismaClient } from '@prisma/client';
3
-
4
- export const prisma = new PrismaClient();