create-backlist 1.2.1 → 1.3.1
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 +1 -1
- package/package.json +1 -1
- package/src/generators/node.js +15 -4
package/bin/index.js
CHANGED
package/package.json
CHANGED
package/src/generators/node.js
CHANGED
|
@@ -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
|
|
38
|
-
|
|
39
|
-
await fs.writeFile(serverFilePath,
|
|
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'),
|