@doquflow/cli 1.2.0 → 1.2.1
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/dist/commands/ui.js +41 -4
- package/package.json +2 -2
package/dist/commands/ui.js
CHANGED
|
@@ -16,6 +16,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
exports.run = run;
|
|
18
18
|
const node_child_process_1 = require("node:child_process");
|
|
19
|
+
const node_http_1 = __importDefault(require("node:http"));
|
|
19
20
|
const node_path_1 = __importDefault(require("node:path"));
|
|
20
21
|
const node_os_1 = __importDefault(require("node:os"));
|
|
21
22
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
@@ -152,6 +153,27 @@ function openBrowser(url) {
|
|
|
152
153
|
console.log(` (Could not auto-open browser — visit ${url} manually)`);
|
|
153
154
|
});
|
|
154
155
|
}
|
|
156
|
+
// ── Public API ────────────────────────────────────────────────────────────────
|
|
157
|
+
// ── Port conflict helper ──────────────────────────────────────────────────────
|
|
158
|
+
// Returns true if a DocuFlow server is already answering on this port.
|
|
159
|
+
function pingDocuflow(port) {
|
|
160
|
+
return new Promise(resolve => {
|
|
161
|
+
const req = node_http_1.default.get({ hostname: 'localhost', port, path: '/api/ping', timeout: 1500 }, (res) => {
|
|
162
|
+
let body = '';
|
|
163
|
+
res.on('data', (chunk) => { body += chunk; });
|
|
164
|
+
res.on('end', () => {
|
|
165
|
+
try {
|
|
166
|
+
resolve(JSON.parse(body).ok === true);
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
resolve(false);
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
req.on('error', () => resolve(false));
|
|
174
|
+
req.on('timeout', () => { req.destroy(); resolve(false); });
|
|
175
|
+
});
|
|
176
|
+
}
|
|
155
177
|
async function run(opts = {}) {
|
|
156
178
|
const port = opts.port ?? (process.env.DOCUFLOW_PORT ? parseInt(process.env.DOCUFLOW_PORT, 10) : 48821);
|
|
157
179
|
// ── 1. Locate bundled UI ────────────────────────────────────────────────
|
|
@@ -349,14 +371,29 @@ async function run(opts = {}) {
|
|
|
349
371
|
});
|
|
350
372
|
server.on('error', (err) => {
|
|
351
373
|
if (err.code === 'EADDRINUSE') {
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
374
|
+
// Check if it's already our own server before erroring
|
|
375
|
+
pingDocuflow(port).then(isDocuflow => {
|
|
376
|
+
if (isDocuflow) {
|
|
377
|
+
const url = `http://localhost:${port}`;
|
|
378
|
+
console.log('');
|
|
379
|
+
console.log(' ✅ DocuFlow is already running — reusing existing server.');
|
|
380
|
+
console.log(` 🌐 ${url}`);
|
|
381
|
+
console.log('');
|
|
382
|
+
if (!opts.noOpen)
|
|
383
|
+
openBrowser(url);
|
|
384
|
+
process.exit(0);
|
|
385
|
+
}
|
|
386
|
+
// Different process owns the port
|
|
387
|
+
console.error(`\n ❌ Port ${port} is already in use by another process.`);
|
|
388
|
+
console.error(` Find and stop it: lsof -ti:${port} | xargs kill`);
|
|
389
|
+
console.error(` Or try: DOCUFLOW_PORT=48822 docuflow ui\n`);
|
|
390
|
+
process.exit(1);
|
|
391
|
+
});
|
|
355
392
|
}
|
|
356
393
|
else {
|
|
357
394
|
console.error(`\n ❌ Server error: ${err.message}\n`);
|
|
395
|
+
process.exit(1);
|
|
358
396
|
}
|
|
359
|
-
process.exit(1);
|
|
360
397
|
});
|
|
361
398
|
// Graceful shutdown
|
|
362
399
|
const shutdown = (signal) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@doquflow/cli",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "CLI for setting up Docuflow in your project",
|
|
5
5
|
"author": "Docuflow <hello@doquflows.dev>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
"build": "tsc && node -e \"const fs=require('fs'),p=require('path'),src=p.join(process.cwd(),'../ui/dist'),dst=p.join(process.cwd(),'ui-dist');if(!fs.existsSync(src)){console.log('Warning: packages/ui/dist not found — run npm run build:ui first');process.exit(0)}fs.mkdirSync(dst,{recursive:true});fs.cpSync(src,dst,{recursive:true,force:true});console.log(' ✓ ui-dist synced from packages/ui/dist ('+(fs.readdirSync(dst).length)+' files at root)')\""
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@doquflow/server": "1.2.
|
|
34
|
+
"@doquflow/server": "1.2.1",
|
|
35
35
|
"cors": "^2.8.5",
|
|
36
36
|
"express": "^4.19.2"
|
|
37
37
|
},
|