coconuts 1.0.9 → 1.0.11

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.
Files changed (2) hide show
  1. package/bin.js +83 -2
  2. package/package.json +7 -3
package/bin.js CHANGED
@@ -1,4 +1,85 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- // Forward execution to @lovelybunch/cli
4
- import '@lovelybunch/cli/dist/cli.js';
3
+ import { spawn } from 'child_process';
4
+ import { fileURLToPath } from 'url';
5
+ import { dirname, join } from 'path';
6
+ import fs from 'fs';
7
+
8
+ const __filename = fileURLToPath(import.meta.url);
9
+ const __dirname = dirname(__filename);
10
+
11
+ // Get the command and arguments
12
+ const [,, command, ...args] = process.argv;
13
+
14
+ if (command === 'serve') {
15
+ console.log('šŸš€ Starting GAIT web interface...');
16
+
17
+ // Set environment variables
18
+ const currentDir = process.cwd();
19
+ console.log(`šŸ—‚ļø Serving data from: ${currentDir}/.gait`);
20
+ process.env.GAIT_DATA_PATH = currentDir;
21
+
22
+ // Check if .gait directory exists
23
+ if (!fs.existsSync(join(currentDir, '.gait'))) {
24
+ console.error('āŒ Error: GAIT is not initialized in this directory.');
25
+ console.error(' Run "nut init" to initialize GAIT.');
26
+ process.exit(1);
27
+ }
28
+
29
+ // Find available port
30
+ const port = args.find(arg => arg.startsWith('--port='))?.split('=')[1] || '3000';
31
+ const host = args.find(arg => arg.startsWith('--host='))?.split('=')[1] || 'localhost';
32
+
33
+ // Start the API server directly
34
+ try {
35
+ // Dynamic import to avoid issues with ES modules
36
+ const { startServer } = await import('@lovelybunch/api');
37
+
38
+ console.log(`šŸ” Starting server on port ${port}...`);
39
+
40
+ // Start the Hono API server with static frontend
41
+ const server = await startServer({
42
+ port: parseInt(port),
43
+ host: host
44
+ });
45
+
46
+ const url = `http://${host}:${port}`;
47
+ console.log(`šŸ“± Web interface running at ${url}`);
48
+
49
+ // Open browser automatically
50
+ setTimeout(() => {
51
+ const openCommand = process.platform === 'darwin' ? 'open' :
52
+ process.platform === 'win32' ? 'start' : 'xdg-open';
53
+ spawn(openCommand, [url], { detached: true, stdio: 'ignore' });
54
+ console.log(`🌐 Opening browser at ${url}`);
55
+ }, 1000);
56
+
57
+ // Handle graceful shutdown
58
+ process.on('SIGINT', () => {
59
+ console.log('\nšŸ›‘ Shutting down GAIT web interface...');
60
+ server.close(() => {
61
+ process.exit(0);
62
+ });
63
+ });
64
+
65
+ process.on('SIGTERM', () => {
66
+ server.close(() => {
67
+ process.exit(0);
68
+ });
69
+ });
70
+
71
+ } catch (error) {
72
+ console.error('āŒ Failed to start GAIT web interface:', error);
73
+ process.exit(1);
74
+ }
75
+
76
+ } else {
77
+ // Forward other commands to the CLI
78
+ try {
79
+ await import('@lovelybunch/cli/dist/cli.js');
80
+ } catch (error) {
81
+ console.error('āŒ Failed to load CLI:', error);
82
+ console.error(' Make sure @lovelybunch/cli is built and available.');
83
+ process.exit(1);
84
+ }
85
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "coconuts",
3
- "version": "1.0.9",
3
+ "version": "1.0.11",
4
4
  "description": "Command-line interface wrapper for GAIT",
5
5
  "type": "module",
6
6
  "bin": {
@@ -18,9 +18,13 @@
18
18
  "access": "public"
19
19
  },
20
20
  "dependencies": {
21
- "@lovelybunch/cli": "^1.0.9"
21
+ "@lovelybunch/api": "file:../api",
22
+ "@lovelybunch/cli": "file:../cli"
22
23
  },
23
24
  "engines": {
24
25
  "node": ">=18.0.0"
25
- }
26
+ },
27
+ "keywords": ["cli", "gait", "coconut", "command-line"],
28
+ "author": "",
29
+ "license": "ISC"
26
30
  }