create-backlist 6.0.8 → 6.1.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-backlist",
3
- "version": "6.0.8",
3
+ "version": "6.1.0",
4
4
  "description": "An advanced, multi-language backend generator based on frontend analysis.",
5
5
  "type": "commonjs",
6
6
  "bin": {
@@ -14,17 +14,90 @@ async function generateNodeProject(options) {
14
14
  try {
15
15
  // --- Step 1: Analyze Frontend ---
16
16
  console.log(chalk.blue(' -> Analyzing frontend for API endpoints...'));
17
- const endpoints = await analyzeFrontend(frontendSrcDir);
18
- if (endpoints.length > 0) console.log(chalk.green(` -> Found ${endpoints.length} endpoints.`));
19
- else console.log(chalk.yellow(' -> No API endpoints found. A basic project will be created.'));
17
+
18
+ // NOTE: 'let' use kala api endpoints wenas karana nisa
19
+ let endpoints = await analyzeFrontend(frontendSrcDir);
20
+
21
+ if (endpoints.length > 0) {
22
+ console.log(chalk.green(` -> Found ${endpoints.length} endpoints.`));
23
+
24
+ // ============================================================
25
+ // 🔥 FIX START: Sanitizing Endpoints Logic
26
+ // ============================================================
27
+ endpoints = endpoints.map(ep => {
28
+ // 1. Path eka sudda kirima (/api/v1/users -> ['users'])
29
+ // 'api', 'v1', histhan ain karanawa
30
+ const parts = ep.path.split('/').filter(part => part !== '' && part !== 'api' && part !== 'v1');
31
+
32
+ // Resource eka hoyaganeema (e.g., 'users')
33
+ let resource = parts[0] || 'Default';
34
+
35
+ // 2. Controller Name eka hadeema (CamelCase: 'users' -> 'Users')
36
+ // Special Case: resource eka 'auth' nam Controller eka 'Auth'
37
+ // 'V1' kiyana eka ain wenne methanin
38
+ let controllerName = resource.charAt(0).toUpperCase() + resource.slice(1);
39
+
40
+ // 3. Function Names hariyatama map kirima
41
+ let functionName = '';
42
+
43
+ // --- AUTH LOGIC ---
44
+ if (controllerName.toLowerCase() === 'auth') {
45
+ if (ep.path.includes('login')) functionName = 'loginUser';
46
+ else if (ep.path.includes('register')) functionName = 'registerUser';
47
+ else functionName = 'authAction'; // fallback
48
+ }
49
+ // --- GENERAL RESOURCES LOGIC ---
50
+ else {
51
+ // Singular/Plural logic to avoid 'Userss'
52
+ const singularName = resource.endsWith('s') ? resource.slice(0, -1) : resource;
53
+ const pluralName = resource.endsWith('s') ? resource : resource + 's';
54
+
55
+ const pascalSingular = singularName.charAt(0).toUpperCase() + singularName.slice(1);
56
+ const pascalPlural = pluralName.charAt(0).toUpperCase() + pluralName.slice(1);
57
+
58
+ if (ep.method === 'GET') {
59
+ if (ep.path.includes(':id')) functionName = `get${pascalSingular}ById`;
60
+ else functionName = `getAll${pascalPlural}`; // Fixes 'getAllUserss'
61
+ } else if (ep.method === 'POST') {
62
+ functionName = `create${pascalSingular}`;
63
+ } else if (ep.method === 'PUT') {
64
+ functionName = `update${pascalSingular}ById`;
65
+ } else if (ep.method === 'DELETE') {
66
+ functionName = `delete${pascalSingular}ById`;
67
+ } else {
68
+ functionName = `${ep.method.toLowerCase()}${pascalPlural}`;
69
+ }
70
+ }
71
+
72
+ // Update the endpoint object
73
+ // meka ejs file ekedi <%= ep.functionName %> kiyala use karanna puluwan
74
+ return {
75
+ ...ep,
76
+ controllerName,
77
+ functionName
78
+ };
79
+ });
80
+ // ============================================================
81
+ // 🔥 FIX END
82
+ // ============================================================
83
+
84
+ } else {
85
+ console.log(chalk.yellow(' -> No API endpoints found. A basic project will be created.'));
86
+ }
20
87
 
21
88
  // --- Step 2: Identify Models to Generate ---
22
89
  const modelsToGenerate = new Map();
23
90
  endpoints.forEach(ep => {
24
- if (ep.schemaFields && ep.controllerName !== 'Default' && !modelsToGenerate.has(ep.controllerName)) {
25
- modelsToGenerate.set(ep.controllerName, { name: ep.controllerName, fields: Object.entries(ep.schemaFields).map(([key, type]) => ({ name: key, type, isUnique: key === 'email' })) });
91
+ // Default saha Auth walata Model hadanna ona na (Auth ekata User Model eka yatin hadanawa)
92
+ // ep.controllerName dan hariyatama 'Users' kiyala enawa, 'V1' enne na.
93
+ if (ep.schemaFields && ep.controllerName !== 'Default' && ep.controllerName !== 'Auth' && !modelsToGenerate.has(ep.controllerName)) {
94
+ modelsToGenerate.set(ep.controllerName, {
95
+ name: ep.controllerName,
96
+ fields: Object.entries(ep.schemaFields).map(([key, type]) => ({ name: key, type, isUnique: key === 'email' }))
97
+ });
26
98
  }
27
99
  });
100
+
28
101
  if (addAuth && !modelsToGenerate.has('User')) {
29
102
  console.log(chalk.yellow(' -> Authentication requires a "User" model. Creating a default one.'));
30
103
  modelsToGenerate.set('User', { name: 'User', fields: [{ name: 'name', type: 'String' }, { name: 'email', type: 'String', isUnique: true }, { name: 'password', type: 'String' }] });
@@ -91,7 +164,10 @@ async function generateNodeProject(options) {
91
164
  console.log(chalk.blue(' -> Generating controllers...'));
92
165
  for (const [modelName] of modelsToGenerate.entries()) {
93
166
  const templateFile = dbType === 'mongoose' ? 'Controller.ts.ejs' : 'PrismaController.ts.ejs';
94
- await renderAndWrite(getTemplatePath(`node-ts-express/partials/${templateFile}`), path.join(destSrcDir, 'controllers', `${modelName}.controller.ts`), { modelName, projectName });
167
+ // Controller hadaddi Auth eka skip karanawa (mokada eka yatin wenama hadanawa)
168
+ if (modelName !== 'Auth') {
169
+ await renderAndWrite(getTemplatePath(`node-ts-express/partials/${templateFile}`), path.join(destSrcDir, 'controllers', `${modelName}.controller.ts`), { modelName, projectName });
170
+ }
95
171
  }
96
172
  }
97
173
 
@@ -145,6 +221,7 @@ async function generateNodeProject(options) {
145
221
  }
146
222
 
147
223
  // --- Step 9: Generate Main Route File & Inject Logic into Server ---
224
+ // IMPORTANT: 'endpoints' variable eka dan sanitized version eka.
148
225
  await renderAndWrite(getTemplatePath('node-ts-express/partials/routes.ts.ejs'), path.join(destSrcDir, 'routes.ts'), { endpoints, addAuth, dbType });
149
226
 
150
227
  let serverFileContent = await fs.readFile(path.join(destSrcDir, 'server.ts'), 'utf-8');