@triophore/falcon-cli 1.0.1 → 1.0.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.
@@ -6,122 +6,120 @@ const { spawn } = require('child_process');
6
6
  const { showSuccess, runNpmInstall, createDirectory } = require('./utils');
7
7
 
8
8
  class ProjectGenerator {
9
- constructor(options = {}) {
10
- this.verbose = options.verbose || false;
11
- this.skipInstall = options.skipInstall || false;
12
- this.useDefaults = options.useDefaults || false;
9
+ constructor(options = {}) {
10
+ this.verbose = options.verbose || false;
11
+ this.skipInstall = options.skipInstall || false;
12
+ this.useDefaults = options.useDefaults || false;
13
+ }
14
+
15
+ async create(projectName, template = 'basic') {
16
+ const currentDir = process.cwd();
17
+
18
+ // Get project name if not provided
19
+ if (!projectName) {
20
+ projectName = await input({
21
+ message: 'Project name:',
22
+ validate: v => v.trim() ? true : 'Project name is required',
23
+ });
13
24
  }
14
25
 
15
- async create(projectName, template = 'basic') {
16
- const currentDir = process.cwd();
17
-
18
- // Get project name if not provided
19
- if (!projectName) {
20
- projectName = await input({
21
- message: 'Project name:',
22
- validate: v => v.trim() ? true : 'Project name is required',
23
- });
24
- }
25
-
26
- const projectPath = path.join(currentDir, projectName);
27
-
28
- // Check if directory exists
29
- try {
30
- await fs.access(projectPath);
31
- const overwrite = await confirm({
32
- message: `Directory "${projectName}" already exists. Overwrite?`,
33
- default: false
34
- });
35
- if (!overwrite) {
36
- console.log('āŒ Project creation cancelled');
37
- return;
38
- }
39
- } catch (error) {
40
- // Directory doesn't exist, which is good
41
- }
42
-
43
- console.log(`\nšŸš€ Creating Falcon.js project: ${projectName}\n`);
44
-
45
- // Create project structure
46
- await this.createProjectStructure(projectPath, projectName, template);
47
-
48
- // Install dependencies
49
- if (!this.skipInstall) {
50
- console.log('šŸ“¦ Installing dependencies...');
51
- await runNpmInstall(projectPath);
52
- }
53
-
54
- showSuccess(projectName, this.skipInstall);
26
+ const projectPath = path.join(currentDir, projectName);
27
+
28
+ // Check if directory exists
29
+ try {
30
+ await fs.access(projectPath);
31
+ const overwrite = await confirm({
32
+ message: `Directory "${projectName}" already exists. Overwrite?`,
33
+ default: false
34
+ });
35
+ if (!overwrite) {
36
+ console.log('āŒ Project creation cancelled');
37
+ return;
38
+ }
39
+ } catch (error) {
40
+ // Directory doesn't exist, which is good
55
41
  }
56
42
 
57
- async createProjectStructure(projectPath, projectName, template) {
58
- // Create directories
59
- const directories = [
60
- 'models/mongo',
61
- 'routes',
62
- 'services',
63
- 'workers',
64
- 'validators',
65
- 'init',
66
- 'logs',
67
- 'public'
68
- ];
69
-
70
- for (const dir of directories) {
71
- await createDirectory(path.join(projectPath, dir));
72
- }
73
-
74
- // Create files
75
- await this.createPackageJson(projectPath, projectName);
76
- await this.createSettings(projectPath, projectName);
77
- await this.createIndexJs(projectPath);
78
- await this.createEnvFile(projectPath, projectName);
79
- await this.createExampleFiles(projectPath);
43
+ console.log(`\nšŸš€ Creating Falcon.js project: ${projectName}\n`);
44
+
45
+ // Create project structure
46
+ await this.createProjectStructure(projectPath, projectName, template);
47
+
48
+ // Install dependencies
49
+ if (!this.skipInstall) {
50
+ console.log('šŸ“¦ Installing dependencies...');
51
+ await runNpmInstall(projectPath);
80
52
  }
81
53
 
82
- async createPackageJson(projectPath, projectName) {
83
- const packageJson = {
84
- name: projectName,
85
- version: "1.0.0",
86
- description: "Falcon.js application",
87
- main: "index.js",
88
- scripts: {
89
- start: "node index.js",
90
- dev: "nodemon index.js",
91
- test: "echo \"Error: no test specified\" && exit 1"
92
- },
93
- keywords: ["falcon", "nodejs", "api"],
94
- author: "",
95
- license: "ISC",
96
- type: "commonjs",
97
- dependencies: {
98
- "falconjs": "file:../falconjs",
99
- "@hapi/boom": "^10.0.1",
100
- "@hapi/inert": "^7.1.0",
101
- "@hapi/vision": "^7.0.3",
102
- "joi": "^17.13.3",
103
- "mongoose": "^8.3.1",
104
- "redis": "^4.7.0",
105
- "mqtt": "^5.13.3",
106
- "log4js": "^6.9.1",
107
- "rate-limiter-flexible": "^2.4.2",
108
- "hapi-alive": "^2.0.4",
109
- "hapi-swagger": "^17.2.1",
110
- "dotenv": "^16.0.0"
111
- },
112
- devDependencies: {
113
- "nodemon": "^3.1.10"
114
- }
115
- };
116
-
117
- await fs.writeFile(
118
- path.join(projectPath, 'package.json'),
119
- JSON.stringify(packageJson, null, 2)
120
- );
54
+ showSuccess(projectName, this.skipInstall);
55
+ }
56
+
57
+ async createProjectStructure(projectPath, projectName, template) {
58
+ // Create directories
59
+ const directories = [
60
+ 'models/mongo',
61
+ 'routes',
62
+ 'services',
63
+ 'workers',
64
+ 'validators',
65
+ 'init',
66
+ 'logs',
67
+ 'public'
68
+ ];
69
+
70
+ for (const dir of directories) {
71
+ await createDirectory(path.join(projectPath, dir));
121
72
  }
122
73
 
123
- async createSettings(projectPath, projectName) {
124
- const settings = `module.exports.settings = {
74
+ // Create files
75
+ await this.createPackageJson(projectPath, projectName);
76
+ await this.createSettings(projectPath, projectName);
77
+ await this.createIndexJs(projectPath);
78
+ await this.createEnvFile(projectPath, projectName);
79
+ await this.createExampleFiles(projectPath);
80
+ }
81
+
82
+ async createPackageJson(projectPath, projectName) {
83
+ const packageJson = {
84
+ name: projectName,
85
+ version: "1.0.0",
86
+ description: "Falcon.js application",
87
+ main: "index.js",
88
+ scripts: {
89
+ start: "node index.js",
90
+ dev: "nodemon index.js",
91
+ test: "echo \"Error: no test specified\" && exit 1"
92
+ },
93
+ keywords: ["falcon", "nodejs", "api"],
94
+ author: "",
95
+ license: "ISC",
96
+ type: "commonjs",
97
+ dependencies: {
98
+ "@triophore/falconjs": "^1.0.0",
99
+ "@hapi/boom": "^10.0.1",
100
+ "@hapi/inert": "^7.1.0",
101
+ "@hapi/vision": "^7.0.3",
102
+ "joi": "^17.13.3",
103
+ "mongoose": "^8.3.1",
104
+ "redis": "^4.7.0",
105
+ "rate-limiter-flexible": "^2.4.2",
106
+ "hapi-alive": "^2.0.4",
107
+ "hapi-swagger": "^17.2.1",
108
+ "dotenv": "^16.0.0"
109
+ },
110
+ devDependencies: {
111
+ "nodemon": "^3.1.10"
112
+ }
113
+ };
114
+
115
+ await fs.writeFile(
116
+ path.join(projectPath, 'package.json'),
117
+ JSON.stringify(packageJson, null, 2)
118
+ );
119
+ }
120
+
121
+ async createSettings(projectPath, projectName) {
122
+ const settings = `module.exports.settings = {
125
123
  name: "${projectName}",
126
124
  http: {
127
125
  host: process.env.HTTP_HOST || "localhost",
@@ -179,19 +177,19 @@ class ProjectGenerator {
179
177
  postInit: "post"
180
178
  };`;
181
179
 
182
- await fs.writeFile(path.join(projectPath, 'settings.js'), settings);
183
- }
180
+ await fs.writeFile(path.join(projectPath, 'settings.js'), settings);
181
+ }
184
182
 
185
- async createIndexJs(projectPath) {
186
- const indexContent = await fs.readFile(
187
- path.join(__dirname, '../templates/index.txt'),
188
- 'utf8'
189
- );
190
- await fs.writeFile(path.join(projectPath, 'index.js'), indexContent);
191
- }
183
+ async createIndexJs(projectPath) {
184
+ const indexContent = await fs.readFile(
185
+ path.join(__dirname, '../templates/index.txt'),
186
+ 'utf8'
187
+ );
188
+ await fs.writeFile(path.join(projectPath, 'index.js'), indexContent);
189
+ }
192
190
 
193
- async createEnvFile(projectPath, projectName) {
194
- const envContent = `# Falcon.js Environment Configuration
191
+ async createEnvFile(projectPath, projectName) {
192
+ const envContent = `# Falcon.js Environment Configuration
195
193
  # Generated by falcon-cli
196
194
 
197
195
  # Server Configuration
@@ -221,26 +219,26 @@ LOG_MAX_SIZE=10M
221
219
  MODE=DEV
222
220
  `;
223
221
 
224
- await fs.writeFile(path.join(projectPath, '.env'), envContent);
225
- }
226
-
227
- async createExampleFiles(projectPath) {
228
- const templates = [
229
- { src: 'example-route.js', dest: 'routes/example.js' },
230
- { src: 'example-validator.js', dest: 'validators/ExamplePayload.js' },
231
- { src: 'example-service.js', dest: 'services/example.js' },
232
- { src: 'example-worker.js', dest: 'workers/example.js' },
233
- { src: 'post-init.js', dest: 'init/post.js' }
234
- ];
235
-
236
- for (const template of templates) {
237
- const content = await fs.readFile(
238
- path.join(__dirname, '../templates', template.src),
239
- 'utf8'
240
- );
241
- await fs.writeFile(path.join(projectPath, template.dest), content);
242
- }
222
+ await fs.writeFile(path.join(projectPath, '.env'), envContent);
223
+ }
224
+
225
+ async createExampleFiles(projectPath) {
226
+ const templates = [
227
+ { src: 'example-route.js', dest: 'routes/example.js' },
228
+ { src: 'example-validator.js', dest: 'validators/ExamplePayload.js' },
229
+ { src: 'example-service.js', dest: 'services/example.js' },
230
+ { src: 'example-worker.js', dest: 'workers/example.js' },
231
+ { src: 'post-init.js', dest: 'init/post.js' }
232
+ ];
233
+
234
+ for (const template of templates) {
235
+ const content = await fs.readFile(
236
+ path.join(__dirname, '../templates', template.src),
237
+ 'utf8'
238
+ );
239
+ await fs.writeFile(path.join(projectPath, template.dest), content);
243
240
  }
241
+ }
244
242
  }
245
243
 
246
244
  module.exports = ProjectGenerator;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@triophore/falcon-cli",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -1,10 +1,10 @@
1
- const { FalconBaseService } = require('falconjs');
1
+ const { FalconBaseService } = require('@triophore/falconjs');
2
2
 
3
3
  /**
4
4
  * Example service - rename and customize as needed
5
5
  */
6
6
  class ExampleService extends FalconBaseService {
7
-
7
+
8
8
  constructor() {
9
9
  super('example'); // Service ID for MQTT topics
10
10
  }
@@ -15,7 +15,7 @@ class ExampleService extends FalconBaseService {
15
15
  async onMessage(topic, msg) {
16
16
  try {
17
17
  const message = JSON.parse(msg.toString());
18
-
18
+
19
19
  switch (topic) {
20
20
  case 'service_example':
21
21
  await this.handleRequest(message);
@@ -33,9 +33,9 @@ class ExampleService extends FalconBaseService {
33
33
  */
34
34
  async handleRequest(request) {
35
35
  console.log('Processing request:', request);
36
-
36
+
37
37
  // Your service logic here
38
-
38
+
39
39
  // Send response back via MQTT
40
40
  this.publish({
41
41
  status: 'completed',
@@ -49,7 +49,7 @@ class ExampleService extends FalconBaseService {
49
49
  */
50
50
  async run() {
51
51
  console.log('Example service is running...');
52
-
52
+
53
53
  // Your initialization logic here
54
54
  }
55
55
  }
@@ -1,10 +1,10 @@
1
- const { FalconBaseWorker } = require('falconjs');
1
+ const { FalconBaseWorker } = require('@triophore/falconjs');
2
2
 
3
3
  /**
4
4
  * Example worker - rename and customize as needed
5
5
  */
6
6
  class ExampleWorker extends FalconBaseWorker {
7
-
7
+
8
8
  constructor() {
9
9
  super('example'); // Worker ID for MQTT topics
10
10
  }
@@ -15,7 +15,7 @@ class ExampleWorker extends FalconBaseWorker {
15
15
  async onMessage(topic, msg) {
16
16
  try {
17
17
  const message = JSON.parse(msg.toString());
18
-
18
+
19
19
  switch (topic) {
20
20
  case 'worker_example_job':
21
21
  await this.processJob(message);
@@ -33,12 +33,12 @@ class ExampleWorker extends FalconBaseWorker {
33
33
  */
34
34
  async processJob(job) {
35
35
  const { jobId, data } = job;
36
-
36
+
37
37
  console.log(`Processing job ${jobId}:`, data);
38
-
38
+
39
39
  // Simulate work
40
40
  await new Promise(resolve => setTimeout(resolve, 2000));
41
-
41
+
42
42
  // Update job status in database if available
43
43
  if (this.models.job) {
44
44
  await this.models.job.findByIdAndUpdate(jobId, {
@@ -47,7 +47,7 @@ class ExampleWorker extends FalconBaseWorker {
47
47
  result: { processed: true }
48
48
  });
49
49
  }
50
-
50
+
51
51
  // Send completion notification
52
52
  await this.publish('worker_example_complete', {
53
53
  jobId: jobId,
@@ -62,13 +62,13 @@ class ExampleWorker extends FalconBaseWorker {
62
62
  async run() {
63
63
  const args = this.parseArgs();
64
64
  console.log('Example worker started with args:', args);
65
-
65
+
66
66
  // If specific job passed as argument, process it immediately
67
67
  if (args.jobId) {
68
68
  await this.processJob(args);
69
69
  process.exit(0); // Exit after processing single job
70
70
  }
71
-
71
+
72
72
  // Otherwise, keep running and wait for MQTT jobs
73
73
  console.log('Waiting for jobs...');
74
74
  }
@@ -2,7 +2,7 @@
2
2
  * Falcon.js Application Entry Point
3
3
  */
4
4
  require('dotenv').config();
5
- const { FalconServer } = require("falconjs");
5
+ const { FalconServer } = require("@triophore/falconjs");
6
6
 
7
7
  async function main() {
8
8
  try {