@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.
@@ -193,7 +193,7 @@ class ProjectGenerator {
193
193
  license: "ISC",
194
194
  type: "commonjs",
195
195
  dependencies: {
196
- "falconjs": "file:../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
- key: process.env.JWT_SECRET || "your-secret-key-here",
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 };
@@ -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
- console.log(`\nšŸ”§ Generating route: ${name}\n`);
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
- // Create routes directory if it doesn't exist
31
- try {
32
- await fs.mkdir(routesDir, { recursive: true });
33
- } catch (error) {
34
- // Directory already exists
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
- await fs.writeFile(routePath, routeContent);
73
+ const routeContent = this.getRouteTemplate(name, method);
74
+ await fs.writeFile(finalPath, routeContent);
41
75
 
42
- console.log(`āœ… Route created: ${routePath}`);
76
+ console.log(`āœ… Route created: ${finalPath}`);
43
77
  }
44
78
 
45
- getRouteTemplate(name) {
46
- return `module.exports.route = async function (context) {
47
- context.server.route({
48
- method: 'GET',
49
- path: '/${name.toLowerCase()}',
50
- options: {
51
- tags: ['api', 'example'],
52
- description: 'Example GET endpoint',
53
- notes: 'Returns example data'
54
- },
55
- handler: async (request, h) => {
56
- return {
57
- success: true,
58
- message: 'Hello from Falcon.js!',
59
- timestamp: new Date().toISOString()
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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triophore/falcon-cli",
3
- "version": "1.0.3",
3
+ "version": "1.0.6",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {