Skip to content

Commit ad0c516

Browse files
committed
feat: add --port argument for configurable port (default 9080)
1 parent 203a6eb commit ad0c516

File tree

1 file changed

+27
-5
lines changed

1 file changed

+27
-5
lines changed

scripts/serve.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88
* brew install code-server
99
*
1010
* Usage:
11-
* pnpm serve # Build, install, and start code-server
12-
* pnpm serve:rebuild # Only rebuild and reinstall the extension
11+
* pnpm serve # Build, install, and start code-server on port 9080
12+
* pnpm serve -- --port 8080 # Use a custom port
13+
* pnpm serve:rebuild # Only rebuild and reinstall the extension
1314
*
1415
* The script will:
1516
* 1. Check if code-server is installed
1617
* 2. Build the vsix (pnpm vsix)
1718
* 3. Install the vsix into code-server
1819
* 4. Configure user settings (disable welcome tab)
19-
* 5. Start code-server on http://127.0.0.1:8080 (unless --rebuild-only)
20+
* 5. Start code-server on http://127.0.0.1:9080 (unless --rebuild-only)
2021
*
2122
* Your password is stored in ~/.config/code-server/config.yaml
2223
*/
@@ -39,6 +40,20 @@ const VSIX_PATH = path.join(os.tmpdir(), "roo-code-serve.vsix")
3940
// Parse command line flags
4041
const rebuildOnly = process.argv.includes("--rebuild-only")
4142

43+
// Parse --port argument (default: 9080)
44+
const DEFAULT_PORT = 9080
45+
function getPort() {
46+
const portIndex = process.argv.indexOf("--port")
47+
if (portIndex !== -1 && process.argv[portIndex + 1]) {
48+
const port = parseInt(process.argv[portIndex + 1], 10)
49+
if (!isNaN(port) && port > 0 && port < 65536) {
50+
return port
51+
}
52+
}
53+
return DEFAULT_PORT
54+
}
55+
const port = getPort()
56+
4257
function log(message) {
4358
console.log(`${CYAN}[serve]${RESET} ${message}`)
4459
}
@@ -147,7 +162,7 @@ async function main() {
147162
const cwd = process.cwd()
148163
console.log(`\n${BOLD}Starting code-server...${RESET}`)
149164
console.log(` Working directory: ${cwd}`)
150-
console.log(` URL: ${CYAN}http://127.0.0.1:8080${RESET}`)
165+
console.log(` URL: ${CYAN}http://127.0.0.1:${port}${RESET}`)
151166
console.log(` Password: ${YELLOW}~/.config/code-server/config.yaml${RESET}`)
152167
console.log(`\n Press ${BOLD}Ctrl+C${RESET} to stop\n`)
153168

@@ -157,7 +172,14 @@ async function main() {
157172
// -e: Ignore last opened directory (start fresh)
158173
const codeServer = spawn(
159174
"code-server",
160-
["--disable-workspace-trust", "--disable-getting-started-override", "-e", cwd],
175+
[
176+
"--bind-addr",
177+
`127.0.0.1:${port}`,
178+
"--disable-workspace-trust",
179+
"--disable-getting-started-override",
180+
"-e",
181+
cwd,
182+
],
161183
{
162184
stdio: "inherit",
163185
cwd: cwd,

0 commit comments

Comments
 (0)