@leanspec/ui 0.2.15 → 0.2.16

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/leanspec-ui.js +70 -5
  2. package/package.json +3 -2
@@ -2,20 +2,27 @@
2
2
  /**
3
3
  * LeanSpec UI Launcher
4
4
  *
5
- * This script serves the pre-built Vite UI using a simple HTTP server.
5
+ * This script:
6
+ * 1. Starts the Rust HTTP server (API backend on port 3333)
7
+ * 2. Serves the pre-built Vite UI on port 3000
8
+ *
6
9
  * For development, use `npm run dev` or `pnpm dev` instead.
7
10
  */
8
11
 
12
+ import { spawn } from 'child_process';
9
13
  import { createServer } from 'http';
10
14
  import { readFileSync, existsSync } from 'fs';
11
15
  import { join, dirname, extname } from 'path';
12
16
  import { fileURLToPath } from 'url';
17
+ import { createRequire } from 'module';
13
18
 
19
+ const require = createRequire(import.meta.url);
14
20
  const __filename = fileURLToPath(import.meta.url);
15
21
  const __dirname = dirname(__filename);
16
22
 
17
23
  // Configuration
18
- const PORT = process.env.PORT || 3000;
24
+ const UI_PORT = process.env.PORT || 3000;
25
+ const API_PORT = process.env.API_PORT || 3333;
19
26
  const DIST_DIR = join(__dirname, '..', 'dist');
20
27
 
21
28
  // MIME types
@@ -110,17 +117,75 @@ if (!existsSync(DIST_DIR)) {
110
117
  process.exit(1);
111
118
  }
112
119
 
113
- server.listen(PORT, () => {
114
- console.log(`🚀 LeanSpec UI running at http://localhost:${PORT}`);
120
+ // Start the Rust HTTP server (API backend)
121
+ let httpServerProcess;
122
+ try {
123
+ // Try to resolve @leanspec/http-server
124
+ const httpServerPath = require.resolve('@leanspec/http-server/bin/leanspec-http.js');
125
+
126
+ console.log('🚀 Starting LeanSpec HTTP server...');
127
+ httpServerProcess = spawn('node', [httpServerPath], {
128
+ stdio: 'inherit',
129
+ env: { ...process.env, PORT: API_PORT.toString() }
130
+ });
131
+
132
+ httpServerProcess.on('error', (err) => {
133
+ console.error('Failed to start HTTP server:', err.message);
134
+ console.error('\nThe UI requires @leanspec/http-server to function.');
135
+ console.error('Install it with: npm install @leanspec/http-server');
136
+ process.exit(1);
137
+ });
138
+
139
+ // Wait a moment for the HTTP server to start
140
+ await new Promise(resolve => setTimeout(resolve, 1000));
141
+
142
+ } catch (err) {
143
+ console.error('Error: @leanspec/http-server not found');
144
+ console.error('The UI requires the HTTP server to provide API functionality.');
145
+ console.error('');
146
+ console.error('Install it with:');
147
+ console.error(' npm install -g @leanspec/http-server');
148
+ console.error('');
149
+ console.error('Or install both together:');
150
+ console.error(' npm install -g lean-spec @leanspec/http-server @leanspec/ui');
151
+ process.exit(1);
152
+ }
153
+
154
+ // Start the UI server
155
+ server.listen(UI_PORT, () => {
156
+ console.log('');
157
+ console.log(`✅ LeanSpec is running!`);
158
+ console.log(` UI: http://localhost:${UI_PORT}`);
159
+ console.log(` API: http://localhost:${API_PORT}`);
160
+ console.log('');
115
161
  console.log(`Press Ctrl+C to stop`);
116
162
  });
117
163
 
118
164
  server.on('error', (err) => {
119
165
  if (err.code === 'EADDRINUSE') {
120
- console.error(`Error: Port ${PORT} is already in use`);
166
+ console.error(`Error: Port ${UI_PORT} is already in use`);
121
167
  console.error('Try setting a different port: PORT=3001 npx @leanspec/ui');
122
168
  } else {
123
169
  console.error('Server error:', err);
124
170
  }
171
+ if (httpServerProcess) {
172
+ httpServerProcess.kill();
173
+ }
125
174
  process.exit(1);
126
175
  });
176
+
177
+ // Cleanup on exit
178
+ process.on('SIGINT', () => {
179
+ console.log('\n\nShutting down...');
180
+ if (httpServerProcess) {
181
+ httpServerProcess.kill();
182
+ }
183
+ process.exit(0);
184
+ });
185
+
186
+ process.on('SIGTERM', () => {
187
+ if (httpServerProcess) {
188
+ httpServerProcess.kill();
189
+ }
190
+ process.exit(0);
191
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leanspec/ui",
3
- "version": "0.2.15",
3
+ "version": "0.2.16",
4
4
  "description": "LeanSpec web UI launcher for visual spec management (Vite SPA)",
5
5
  "type": "module",
6
6
  "bin": {
@@ -23,7 +23,8 @@
23
23
  },
24
24
  "dependencies": {
25
25
  "@dagrejs/dagre": "^1.1.8",
26
- "@leanspec/ui-components": "^0.2.11",
26
+ "@leanspec/http-server": "^0.2.15",
27
+ "@leanspec/ui-components": "^0.2.15",
27
28
  "@radix-ui/react-tooltip": "^1.2.8",
28
29
  "clsx": "^2.1.1",
29
30
  "cmdk": "^1.1.1",