22 * Serve script for Roo Code extension development
33 *
44 * Usage:
5- * pnpm serve:install # Build and install the extension into code-server
6- * pnpm serve # Start code-server on port 9080
7- * pnpm serve -- --port 8080 # Use a custom port
8- * pnpm serve -- --host 0.0.0.0 # Bind to all interfaces (for Docker/remote access)
9- * pnpm serve -- --auth none # Disable authentication (password|none)
5+ * pnpm serve:install # Build and install the extension into code-server
106 *
117 * After making code changes, run `pnpm serve:install` again and reload the window
128 * (Cmd+Shift+P → "Developer: Reload Window")
139 */
1410
15- const { execSync, spawn } = require ( "child_process" )
11+ const { execSync } = require ( "child_process" )
1612const path = require ( "path" )
1713const os = require ( "os" )
1814
@@ -26,44 +22,6 @@ const RED = "\x1b[31m"
2622// Build vsix to a fixed path in temp directory
2723const VSIX_PATH = path . join ( os . tmpdir ( ) , "roo-code-serve.vsix" )
2824
29- // Parse command line flags
30- const installOnly = process . argv . includes ( "--install-only" )
31-
32- // Parse --port argument (default: 9080)
33- const DEFAULT_PORT = 9080
34- function getPort ( ) {
35- const portIndex = process . argv . indexOf ( "--port" )
36- if ( portIndex !== - 1 && process . argv [ portIndex + 1 ] ) {
37- const port = parseInt ( process . argv [ portIndex + 1 ] , 10 )
38- if ( ! isNaN ( port ) && port > 0 && port < 65536 ) {
39- return port
40- }
41- }
42- return DEFAULT_PORT
43- }
44- const port = getPort ( )
45-
46- // Parse --host argument (default: 127.0.0.1, use 0.0.0.0 for Docker/remote access)
47- const DEFAULT_HOST = "127.0.0.1"
48- function getHost ( ) {
49- const hostIndex = process . argv . indexOf ( "--host" )
50- if ( hostIndex !== - 1 && process . argv [ hostIndex + 1 ] ) {
51- return process . argv [ hostIndex + 1 ]
52- }
53- return DEFAULT_HOST
54- }
55- const host = getHost ( )
56-
57- // Parse --auth argument (optional, passed to code-server: "password" or "none")
58- function getAuth ( ) {
59- const authIndex = process . argv . indexOf ( "--auth" )
60- if ( authIndex !== - 1 && process . argv [ authIndex + 1 ] ) {
61- return process . argv [ authIndex + 1 ]
62- }
63- return null
64- }
65- const auth = getAuth ( )
66-
6725function log ( message ) {
6826 console . log ( `${ CYAN } [serve]${ RESET } ${ message } ` )
6927}
@@ -80,102 +38,31 @@ function logError(message) {
8038 console . error ( `${ RED } ✗${ RESET } ${ message } ` )
8139}
8240
83- function isCodeServerInstalled ( ) {
84- try {
85- execSync ( "which code-server" , { stdio : "pipe" } )
86- return true
87- } catch {
88- return false
89- }
90- }
91-
9241async function main ( ) {
93- // If install-only mode, just build and install the extension
94- if ( installOnly ) {
95- console . log ( `\n${ BOLD } 🔧 Roo Code - Install Extension${ RESET } \n` )
96-
97- // Build vsix to temp directory
98- log ( `Building vsix to ${ VSIX_PATH } ...` )
99- try {
100- execSync ( `pnpm vsix -- --out "${ VSIX_PATH } "` , { stdio : "inherit" } )
101- logSuccess ( "Build complete" )
102- } catch ( error ) {
103- logError ( "Build failed" )
104- process . exit ( 1 )
105- }
42+ console . log ( `\n${ BOLD } 🔧 Roo Code - Install Extension${ RESET } \n` )
10643
107- // Install extension into code-server
108- log ( "Installing extension into code-server..." )
109- try {
110- execSync ( `code-server --install-extension "${ VSIX_PATH } "` , { stdio : "inherit" } )
111- logSuccess ( "Extension installed" )
112- } catch ( error ) {
113- logWarning ( "Extension installation had warnings (this is usually fine)" )
114- }
115-
116- console . log ( `\n${ GREEN } ✓ Extension built and installed.${ RESET } ` )
117- console . log ( ` If code-server is running, reload the window to pick up changes.` )
118- console . log ( ` (Cmd+Shift+P → "Developer: Reload Window")\n` )
119- return
120- }
121-
122- // Default: Start code-server
123- log ( "Checking for code-server..." )
124- if ( ! isCodeServerInstalled ( ) ) {
125- logError ( "code-server is not installed" )
126- console . log ( "\nTo install code-server on macOS:" )
127- console . log ( ` ${ CYAN } brew install code-server${ RESET } ` )
128- console . log ( "\nFor other platforms, see: https://coder.com/docs/code-server/install" )
44+ // Build vsix to temp directory
45+ log ( `Building vsix to ${ VSIX_PATH } ...` )
46+ try {
47+ execSync ( `pnpm vsix -- --out "${ VSIX_PATH } "` , { stdio : "inherit" } )
48+ logSuccess ( "Build complete" )
49+ } catch ( error ) {
50+ logError ( "Build failed" )
12951 process . exit ( 1 )
13052 }
131- logSuccess ( "code-server found" )
13253
133- console . log ( `\n${ BOLD } 🚀 Roo Code - code-server Development Server${ RESET } \n` )
134- const cwd = process . cwd ( )
135- console . log ( `\n${ BOLD } Starting code-server...${ RESET } ` )
136- console . log ( ` Working directory: ${ cwd } ` )
137- console . log ( ` URL: ${ CYAN } http://${ host } :${ port } ${ RESET } ` )
138- if ( auth === "none" ) {
139- console . log ( ` Auth: ${ YELLOW } disabled${ RESET } ` )
140- } else {
141- console . log ( ` Password: ${ YELLOW } ~/.config/code-server/config.yaml${ RESET } ` )
142- }
143- console . log ( `\n Press ${ BOLD } Ctrl+C${ RESET } to stop\n` )
144-
145- // Spawn code-server with:
146- // --bind-addr: Address to bind to
147- // --auth: Authentication type (password or none)
148- // --disable-workspace-trust: Skip workspace trust prompts
149- // --disable-getting-started-override: Disable welcome/getting started page
150- // -e: Ignore last opened directory (start fresh)
151- const args = [ "--bind-addr" , `${ host } :${ port } ` ]
152- if ( auth ) {
153- args . push ( "--auth" , auth )
54+ // Install extension into code-server
55+ log ( "Installing extension into code-server..." )
56+ try {
57+ execSync ( `code-server --install-extension "${ VSIX_PATH } "` , { stdio : "inherit" } )
58+ logSuccess ( "Extension installed" )
59+ } catch ( error ) {
60+ logWarning ( "Extension installation had warnings (this is usually fine)" )
15461 }
155- args . push ( "--disable-workspace-trust" , "--disable-getting-started-override" , "-e" , cwd )
156-
157- const codeServer = spawn ( "code-server" , args , {
158- stdio : "inherit" ,
159- cwd : cwd ,
160- } )
161-
162- codeServer . on ( "error" , ( err ) => {
163- logError ( `Failed to start code-server: ${ err . message } ` )
164- process . exit ( 1 )
165- } )
166-
167- codeServer . on ( "close" , ( code ) => {
168- if ( code !== 0 && code !== null ) {
169- logError ( `code-server exited with code ${ code } ` )
170- }
171- } )
17262
173- // Handle Ctrl+C gracefully
174- process . on ( "SIGINT" , ( ) => {
175- console . log ( "\n" )
176- log ( "Shutting down code-server..." )
177- codeServer . kill ( "SIGTERM" )
178- } )
63+ console . log ( `\n${ GREEN } ✓ Extension built and installed.${ RESET } ` )
64+ console . log ( ` If code-server is running, reload the window to pick up changes.` )
65+ console . log ( ` (Cmd+Shift+P → "Developer: Reload Window")\n` )
17966}
18067
18168main ( ) . catch ( ( error ) => {
0 commit comments