@triophore/falcon-cli 1.0.3 ā 1.0.6
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/lib/ProjectGenerator.js +2 -2
- package/lib/RouteGenerator.js +66 -31
- package/package.json +1 -1
package/lib/ProjectGenerator.js
CHANGED
|
@@ -193,7 +193,7 @@ class ProjectGenerator {
|
|
|
193
193
|
license: "ISC",
|
|
194
194
|
type: "commonjs",
|
|
195
195
|
dependencies: {
|
|
196
|
-
"falconjs": "
|
|
196
|
+
"@triophore/falconjs": "^1.0.1",
|
|
197
197
|
"@hapi/boom": "^10.0.1",
|
|
198
198
|
"@hapi/inert": "^7.1.0",
|
|
199
199
|
"@hapi/vision": "^7.0.3",
|
|
@@ -261,7 +261,7 @@ class ProjectGenerator {
|
|
|
261
261
|
},
|
|
262
262
|
auth: {
|
|
263
263
|
jwt: {
|
|
264
|
-
|
|
264
|
+
secret: process.env.JWT_SECRET || "your-secret-key-here",
|
|
265
265
|
validate: async (decoded, request) => {
|
|
266
266
|
// Your JWT validation logic
|
|
267
267
|
return { id: decoded.id, roles: decoded.roles };
|
package/lib/RouteGenerator.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const path = require('path');
|
|
2
2
|
const fs = require('fs').promises;
|
|
3
|
-
const { input } = require('@inquirer/prompts');
|
|
3
|
+
const { input, select } = require('@inquirer/prompts');
|
|
4
4
|
|
|
5
5
|
class RouteGenerator {
|
|
6
6
|
constructor(options = {}) {
|
|
@@ -25,43 +25,78 @@ class RouteGenerator {
|
|
|
25
25
|
});
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
const method = await select({
|
|
29
|
+
message: 'HTTP Method:',
|
|
30
|
+
choices: [
|
|
31
|
+
{ name: 'GET', value: 'GET' },
|
|
32
|
+
{ name: 'POST', value: 'POST' },
|
|
33
|
+
{ name: 'PUT', value: 'PUT' },
|
|
34
|
+
{ name: 'DELETE', value: 'DELETE' },
|
|
35
|
+
{ name: 'PATCH', value: 'PATCH' },
|
|
36
|
+
{ name: 'ANY', value: '*' },
|
|
37
|
+
]
|
|
38
|
+
});
|
|
29
39
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
console.log(`\nš§ Generating route: ${name} [${method}]\n`);
|
|
41
|
+
|
|
42
|
+
// Construct filename: [METHOD]#name.js
|
|
43
|
+
const filename = `[${method.toUpperCase()}]#${name.toLowerCase()}.js`;
|
|
44
|
+
|
|
45
|
+
// Handle nested paths
|
|
46
|
+
// If name contains slashes, we need to handle directory creation
|
|
47
|
+
// But wait, if name is "auth/login", filename becomes "[GET]#auth/login.js" which is wrong.
|
|
48
|
+
// We want "auth/[GET]#login.js".
|
|
49
|
+
|
|
50
|
+
let finalPath;
|
|
51
|
+
if (name.includes('/') || name.includes('\\')) {
|
|
52
|
+
const parts = name.split(/[/\\]/);
|
|
53
|
+
const baseName = parts.pop();
|
|
54
|
+
const dirPath = parts.join('/');
|
|
55
|
+
|
|
56
|
+
finalPath = path.join(routesDir, dirPath, `[${method.toUpperCase()}]#${baseName.toLowerCase()}.js`);
|
|
57
|
+
|
|
58
|
+
// Create subdirectories
|
|
59
|
+
try {
|
|
60
|
+
await fs.mkdir(path.dirname(finalPath), { recursive: true });
|
|
61
|
+
} catch (error) {
|
|
62
|
+
// Ignore
|
|
63
|
+
}
|
|
64
|
+
} else {
|
|
65
|
+
finalPath = path.join(routesDir, filename);
|
|
66
|
+
// Ensure routes dir exists
|
|
67
|
+
try {
|
|
68
|
+
await fs.mkdir(routesDir, { recursive: true });
|
|
69
|
+
} catch (err) { }
|
|
35
70
|
}
|
|
36
71
|
|
|
37
|
-
const routeContent = this.getRouteTemplate(name);
|
|
38
|
-
const routePath = path.join(routesDir, `${name.toLowerCase()}.js`);
|
|
39
72
|
|
|
40
|
-
|
|
73
|
+
const routeContent = this.getRouteTemplate(name, method);
|
|
74
|
+
await fs.writeFile(finalPath, routeContent);
|
|
41
75
|
|
|
42
|
-
console.log(`ā
Route created: ${
|
|
76
|
+
console.log(`ā
Route created: ${finalPath}`);
|
|
43
77
|
}
|
|
44
78
|
|
|
45
|
-
getRouteTemplate(name) {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
79
|
+
getRouteTemplate(name, method) {
|
|
80
|
+
method = method === '*' ? 'ANY' : method;
|
|
81
|
+
return `/**
|
|
82
|
+
* ${method} Route for ${name}
|
|
83
|
+
*/
|
|
84
|
+
module.exports = {
|
|
85
|
+
options: {
|
|
86
|
+
tags: ['api'],
|
|
87
|
+
description: 'Auto-generated ${method} route',
|
|
88
|
+
notes: 'Returns example data',
|
|
89
|
+
validate: {} // Add payload/query/params validation here
|
|
90
|
+
},
|
|
91
|
+
handler: async (request, h) => {
|
|
92
|
+
return {
|
|
93
|
+
success: true,
|
|
94
|
+
message: 'Hello from Falcon.js!',
|
|
95
|
+
timestamp: new Date().toISOString(),
|
|
96
|
+
// data: request.payload // for POST/PUT
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
};`;
|
|
65
100
|
}
|
|
66
101
|
}
|
|
67
102
|
|