create-backlist 1.3.0 → 1.3.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/index.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  const inquirer = require('inquirer');
4
4
  const chalk = require('chalk');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-backlist",
3
- "version": "1.3.0",
3
+ "version": "1.3.2",
4
4
  "description": "An advanced, multi-language backend generator based on frontend analysis.",
5
5
  "type": "commonjs",
6
6
  "bin": {
@@ -9,7 +9,7 @@
9
9
  "scripts": {
10
10
  "start": "node bin/index.js"
11
11
  },
12
- "author": "Your Name",
12
+ "author": "W.A.H.ISHAN",
13
13
  "license": "MIT",
14
14
  "dependencies": {
15
15
  "@babel/parser": "^7.22.7",
@@ -8,6 +8,7 @@ const { renderAndWrite, getTemplatePath } = require('./template');
8
8
  async function generateNodeProject(options) {
9
9
  const { projectDir, projectName, frontendSrcDir } = options;
10
10
 
11
+ // --- Step 1: Analyze Frontend ---
11
12
  console.log(chalk.blue(' -> Analyzing frontend for API endpoints...'));
12
13
  const endpoints = await analyzeFrontend(frontendSrcDir);
13
14
  if (endpoints.length > 0) {
@@ -16,31 +17,41 @@ async function generateNodeProject(options) {
16
17
  console.log(chalk.yellow(' -> No API endpoints found. A basic project will be created.'));
17
18
  }
18
19
 
20
+ // --- Step 2: Scaffold Base Project ---
19
21
  console.log(chalk.blue(' -> Scaffolding Node.js (Express + TS) project...'));
20
22
 
23
+ // Copy the base template directory which includes `src/server.ts`
21
24
  const baseDir = getTemplatePath('node-ts-express/base');
22
25
  await fs.copy(baseDir, projectDir);
23
26
 
27
+ // --- Step 3: Generate Dynamic Files from Templates ---
28
+
29
+ // Generate package.json
24
30
  await renderAndWrite(
25
31
  getTemplatePath('node-ts-express/partials/package.json.ejs'),
26
32
  path.join(projectDir, 'package.json'),
27
33
  { projectName }
28
34
  );
29
35
 
36
+ // Generate routes.ts based on analyzed endpoints
30
37
  await renderAndWrite(
31
38
  getTemplatePath('node-ts-express/partials/routes.ts.ejs'),
32
39
  path.join(projectDir, 'src', 'routes.ts'),
33
40
  { endpoints }
34
41
  );
35
42
 
43
+ // --- Step 4: Modify the copied server.ts to inject routes ---
44
+ // THIS IS THE FIX: We do this AFTER the base files are copied.
36
45
  const serverFilePath = path.join(projectDir, 'src', 'server.ts');
37
- let serverFile = await fs.readFile(serverFilePath, 'utf-8');
38
- serverFile = serverFile.replace('// INJECT:ROUTES', `import apiRoutes from './routes';\napp.use(apiRoutes);`);
39
- await fs.writeFile(serverFilePath, serverFile);
40
-
46
+ let serverFileContent = await fs.readFile(serverFilePath, 'utf-8');
47
+ serverFileContent = serverFileContent.replace('// INJECT:ROUTES', `import apiRoutes from './routes';\napp.use(apiRoutes);`);
48
+ await fs.writeFile(serverFilePath, serverFileContent);
49
+
50
+ // --- Step 5: Install Dependencies ---
41
51
  console.log(chalk.magenta(' -> Installing dependencies (npm install)...'));
42
52
  await execa('npm', ['install'], { cwd: projectDir });
43
53
 
54
+ // --- Step 6: Generate README ---
44
55
  await renderAndWrite(
45
56
  getTemplatePath('node-ts-express/partials/README.md.ejs'),
46
57
  path.join(projectDir, 'README.md'),
@@ -1,15 +1,22 @@
1
- import express from 'express';
1
+ import express, { Express, Request, Response } from 'express';
2
2
  import cors from 'cors';
3
3
  import dotenv from 'dotenv';
4
4
 
5
5
  dotenv.config();
6
- const app = express();
6
+
7
+ const app: Express = express(); // Added :Express type
8
+
7
9
  app.use(cors());
8
10
  app.use(express.json());
9
11
 
10
- app.get('/', (req, res) => res.send('Node.js Backend says Hello! Generated by Backlist.'));
12
+ app.get('/', (req: Request, res: Response) => { // Added :Request and :Response types
13
+ res.send('Node.js Backend says Hello! Generated by Backlist.');
14
+ });
11
15
 
12
16
  // INJECT:ROUTES
13
17
 
14
- const PORT = process.env.PORT || 8000;
15
- app.listen(PORT, () => console.log(`⚡️ Server running on http://localhost:${PORT}`));
18
+ const PORT: number | string = process.env.PORT || 8000; // Added type for PORT
19
+
20
+ app.listen(PORT, () => {
21
+ console.log(`⚡️ Server running on http://localhost:${PORT}`);
22
+ });