gh-here 1.0.4 → 1.0.5
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/.claude/settings.local.json +2 -1
- package/bin/gh-here.js +41 -3
- package/package.json +1 -1
package/bin/gh-here.js
CHANGED
|
@@ -12,6 +12,17 @@ const args = process.argv.slice(2);
|
|
|
12
12
|
const openBrowser = args.includes('--open') || args.includes('-o');
|
|
13
13
|
const helpRequested = args.includes('--help') || args.includes('-h');
|
|
14
14
|
|
|
15
|
+
// Check for port specification
|
|
16
|
+
let specifiedPort = null;
|
|
17
|
+
const portArg = args.find(arg => arg.startsWith('--port='));
|
|
18
|
+
if (portArg) {
|
|
19
|
+
specifiedPort = parseInt(portArg.split('=')[1]);
|
|
20
|
+
if (isNaN(specifiedPort) || specifiedPort < 1 || specifiedPort > 65535) {
|
|
21
|
+
console.error('❌ Invalid port number. Port must be between 1 and 65535.');
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
15
26
|
// Check for browser specification
|
|
16
27
|
let specificBrowser = null;
|
|
17
28
|
const browserArg = args.find(arg => arg.startsWith('--browser='));
|
|
@@ -28,11 +39,13 @@ Usage: npx gh-here [options]
|
|
|
28
39
|
Options:
|
|
29
40
|
--open, -o Open browser automatically
|
|
30
41
|
--browser=<name> Specify browser (safari, chrome, firefox, arc)
|
|
42
|
+
--port=<number> Specify port number (default: 5555)
|
|
31
43
|
--help, -h Show this help message
|
|
32
44
|
|
|
33
45
|
Examples:
|
|
34
|
-
npx gh-here Start server on available
|
|
46
|
+
npx gh-here Start server on port 5555 (or next available)
|
|
35
47
|
npx gh-here --open Start server and open browser
|
|
48
|
+
npx gh-here --port=8080 Start server on port 8080
|
|
36
49
|
npx gh-here --open --browser=safari Start server and open in Safari
|
|
37
50
|
npx gh-here --open --browser=arc Start server and open in Arc
|
|
38
51
|
`);
|
|
@@ -50,7 +63,7 @@ const isGitRepo = !!gitRepoRoot;
|
|
|
50
63
|
setupRoutes(app, workingDir, isGitRepo, gitRepoRoot);
|
|
51
64
|
|
|
52
65
|
// Function to find an available port
|
|
53
|
-
async function findAvailablePort(startPort =
|
|
66
|
+
async function findAvailablePort(startPort = 5555) {
|
|
54
67
|
const net = require('net');
|
|
55
68
|
|
|
56
69
|
return new Promise((resolve, reject) => {
|
|
@@ -133,7 +146,32 @@ function openBrowserToUrl(url) {
|
|
|
133
146
|
// Start server with automatic port selection
|
|
134
147
|
async function startServer() {
|
|
135
148
|
try {
|
|
136
|
-
|
|
149
|
+
let port;
|
|
150
|
+
if (specifiedPort) {
|
|
151
|
+
// If user specified a port, try only that port
|
|
152
|
+
const net = require('net');
|
|
153
|
+
const server = net.createServer();
|
|
154
|
+
|
|
155
|
+
try {
|
|
156
|
+
await new Promise((resolve, reject) => {
|
|
157
|
+
server.listen(specifiedPort, () => {
|
|
158
|
+
server.close(() => resolve());
|
|
159
|
+
});
|
|
160
|
+
server.on('error', reject);
|
|
161
|
+
});
|
|
162
|
+
port = specifiedPort;
|
|
163
|
+
} catch (error) {
|
|
164
|
+
if (error.code === 'EADDRINUSE') {
|
|
165
|
+
console.error(`❌ Port ${specifiedPort} is already in use. Please choose a different port.`);
|
|
166
|
+
process.exit(1);
|
|
167
|
+
} else {
|
|
168
|
+
throw error;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
} else {
|
|
172
|
+
// Find available port starting from 5555
|
|
173
|
+
port = await findAvailablePort(5555);
|
|
174
|
+
}
|
|
137
175
|
const url = `http://localhost:${port}`;
|
|
138
176
|
|
|
139
177
|
app.listen(port, () => {
|