seeclaudecode 1.0.0 → 1.0.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/bin/cli.js +36 -0
- package/package.json +1 -1
package/bin/cli.js
CHANGED
|
@@ -5,6 +5,7 @@ import { dirname, join, resolve } from 'path';
|
|
|
5
5
|
import { existsSync, statSync, readdirSync } from 'fs';
|
|
6
6
|
import { spawn } from 'child_process';
|
|
7
7
|
import { createInterface } from 'readline';
|
|
8
|
+
import { createServer } from 'net';
|
|
8
9
|
|
|
9
10
|
const __filename = fileURLToPath(import.meta.url);
|
|
10
11
|
const __dirname = dirname(__filename);
|
|
@@ -97,6 +98,34 @@ function question(prompt) {
|
|
|
97
98
|
});
|
|
98
99
|
}
|
|
99
100
|
|
|
101
|
+
// Check if port is available
|
|
102
|
+
function isPortAvailable(port) {
|
|
103
|
+
return new Promise((resolve) => {
|
|
104
|
+
const server = createServer();
|
|
105
|
+
server.once('error', () => resolve(false));
|
|
106
|
+
server.once('listening', () => {
|
|
107
|
+
server.close();
|
|
108
|
+
resolve(true);
|
|
109
|
+
});
|
|
110
|
+
server.listen(port);
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Find an available port starting from the given port
|
|
115
|
+
async function findAvailablePort(startPort) {
|
|
116
|
+
let currentPort = startPort;
|
|
117
|
+
const maxAttempts = 10;
|
|
118
|
+
|
|
119
|
+
for (let i = 0; i < maxAttempts; i++) {
|
|
120
|
+
if (await isPortAvailable(currentPort)) {
|
|
121
|
+
return currentPort;
|
|
122
|
+
}
|
|
123
|
+
currentPort++;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
throw new Error(`Could not find an available port after ${maxAttempts} attempts`);
|
|
127
|
+
}
|
|
128
|
+
|
|
100
129
|
// Validate directory
|
|
101
130
|
function validateDirectory(dir) {
|
|
102
131
|
const resolved = resolve(dir);
|
|
@@ -243,6 +272,13 @@ async function main() {
|
|
|
243
272
|
targetDir = result.path;
|
|
244
273
|
}
|
|
245
274
|
|
|
275
|
+
// Find available port
|
|
276
|
+
const requestedPort = port;
|
|
277
|
+
port = await findAvailablePort(port);
|
|
278
|
+
if (port !== requestedPort) {
|
|
279
|
+
console.log(`\x1b[33mPort ${requestedPort} is in use, using port ${port} instead\x1b[0m`);
|
|
280
|
+
}
|
|
281
|
+
|
|
246
282
|
// Start the server
|
|
247
283
|
startServer(targetDir);
|
|
248
284
|
|