@@ -71,14 +71,15 @@ async function main() {
7171
7272 // Create output directories if they don't exist
7373 await fs . mkdir ( TS_OUT_DIR , { recursive : true } )
74+
7475 await cleanup ( )
7576
7677 // Check for missing proto files for services in serviceNameMap
7778 await ensureProtoFilesExist ( )
7879
7980 // Process all proto files
80- console . log ( chalk . cyan ( "Processing proto files from" ) , SCRIPT_DIR )
8181 const protoFiles = await globby ( "**/*.proto" , { cwd : SCRIPT_DIR , realpath : true } )
82+ console . log ( chalk . cyan ( `Processing ${ protoFiles . length } proto files from` ) , SCRIPT_DIR )
8283
8384 // Build the protoc command with proper path handling for cross-platform
8485 const tsProtocCommand = [
@@ -90,7 +91,7 @@ async function main() {
9091 ...protoFiles ,
9192 ] . join ( " " )
9293 try {
93- console . log ( chalk . cyan ( `Generating TypeScript code for:\n${ protoFiles . join ( "\n" ) } ...` ) )
94+ log_verbose ( chalk . cyan ( `Generating TypeScript code for:\n${ protoFiles . join ( "\n" ) } ...` ) )
9495 execSync ( tsProtocCommand , { stdio : "inherit" } )
9596 } catch ( error ) {
9697 console . error ( chalk . red ( "Error generating TypeScript for proto files:" ) , error )
@@ -108,30 +109,32 @@ async function main() {
108109 ...protoFiles ,
109110 ] . join ( " " )
110111 try {
111- console . log ( chalk . cyan ( "Generating descriptor set..." ) )
112+ log_verbose ( chalk . cyan ( "Generating descriptor set..." ) )
112113 execSync ( descriptorProtocCommand , { stdio : "inherit" } )
113114 } catch ( error ) {
114115 console . error ( chalk . red ( "Error generating descriptor set for proto file:" ) , error )
115116 process . exit ( 1 )
116117 }
117118
118- console . log ( chalk . green ( "Protocol Buffer code generation completed successfully." ) )
119- console . log ( chalk . green ( `TypeScript files generated in: ${ TS_OUT_DIR } ` ) )
119+ log_verbose ( chalk . green ( "Protocol Buffer code generation completed successfully." ) )
120+ log_verbose ( chalk . green ( `TypeScript files generated in: ${ TS_OUT_DIR } ` ) )
120121
121122 await generateMethodRegistrations ( )
122123 await generateHostMethodRegistrations ( )
123124 await generateServiceConfig ( )
124125 await generateHostServiceConfig ( )
125126 await generateGrpcClientConfig ( )
126127 await generateHostGrpcClientConfig ( )
128+
129+ console . log ( chalk . bold . blue ( "Finished Protocol Buffer code generation." ) )
127130}
128131
129132/**
130133 * Generate a gRPC client configuration file for the webview
131134 * This eliminates the need for manual imports and client creation in grpc-client.ts
132135 */
133136async function generateGrpcClientConfig ( ) {
134- console . log ( chalk . cyan ( "Generating gRPC client configuration..." ) )
137+ log_verbose ( chalk . cyan ( "Generating gRPC client configuration..." ) )
135138
136139 const serviceImports = [ ]
137140 const serviceClientCreations = [ ]
@@ -168,7 +171,7 @@ export {
168171
169172 const configPath = path . join ( ROOT_DIR , "webview-ui" , "src" , "services" , "grpc-client.ts" )
170173 await fs . writeFile ( configPath , content )
171- console . log ( chalk . green ( `Generated gRPC client at ${ configPath } ` ) )
174+ log_verbose ( chalk . green ( `Generated gRPC client at ${ configPath } ` ) )
172175}
173176
174177/**
@@ -178,7 +181,7 @@ export {
178181 * @returns Map of service names to their streaming methods
179182 */
180183async function parseProtoForStreamingMethods ( protoFiles , scriptDir ) {
181- console . log ( chalk . cyan ( "Parsing proto files for streaming methods..." ) )
184+ log_verbose ( chalk . cyan ( "Parsing proto files for streaming methods..." ) )
182185
183186 // Map of service name to array of streaming method names
184187 const streamingMethodsMap = new Map ( )
@@ -230,7 +233,7 @@ async function parseProtoForStreamingMethods(protoFiles, scriptDir) {
230233}
231234
232235async function generateMethodRegistrations ( ) {
233- console . log ( chalk . cyan ( "Generating method registration files..." ) )
236+ log_verbose ( chalk . cyan ( "Generating method registration files..." ) )
234237
235238 // Parse proto files for streaming methods
236239 const protoFiles = await globby ( "*.proto" , { cwd : SCRIPT_DIR } )
@@ -240,7 +243,7 @@ async function generateMethodRegistrations() {
240243 try {
241244 await fs . access ( serviceDir )
242245 } catch ( error ) {
243- console . log ( chalk . cyan ( `Creating directory ${ serviceDir } for new service` ) )
246+ log_verbose ( chalk . cyan ( `Creating directory ${ serviceDir } for new service` ) )
244247 await fs . mkdir ( serviceDir , { recursive : true } )
245248 }
246249
@@ -251,7 +254,7 @@ async function generateMethodRegistrations() {
251254 const fullServiceName = serviceNameMap [ serviceName ]
252255 const streamingMethods = streamingMethodsMap . get ( fullServiceName ) || [ ]
253256
254- console . log ( chalk . cyan ( `Generating method registrations for ${ serviceName } ...` ) )
257+ log_verbose ( chalk . cyan ( `Generating method registrations for ${ serviceName } ...` ) )
255258
256259 // Get all TypeScript files in the service directory
257260 const files = await globby ( "*.ts" , { cwd : serviceDir } )
@@ -304,7 +307,7 @@ export function registerAllMethods(): void {
304307
305308 // Write the methods.ts file
306309 await fs . writeFile ( registryFile , methodsContent )
307- console . log ( chalk . green ( `Generated ${ registryFile } ` ) )
310+ log_verbose ( chalk . green ( `Generated ${ registryFile } ` ) )
308311
309312 // Generate index.ts file
310313 const capitalizedServiceName = serviceName . charAt ( 0 ) . toUpperCase ( ) + serviceName . slice ( 1 )
@@ -333,18 +336,18 @@ registerAllMethods()`
333336
334337 // Write the index.ts file
335338 await fs . writeFile ( indexFile , indexContent )
336- console . log ( chalk . green ( `Generated ${ indexFile } ` ) )
339+ log_verbose ( chalk . green ( `Generated ${ indexFile } ` ) )
337340 }
338341
339- console . log ( chalk . green ( "Method registration files generated successfully." ) )
342+ log_verbose ( chalk . green ( "Method registration files generated successfully." ) )
340343}
341344
342345/**
343346 * Generate a service configuration file that maps service names to their handlers
344347 * This eliminates the need for manual switch/case statements in grpc-handler.ts
345348 */
346349async function generateServiceConfig ( ) {
347- console . log ( chalk . cyan ( "Generating service configuration file..." ) )
350+ log_verbose ( chalk . cyan ( "Generating service configuration file..." ) )
348351
349352 const serviceImports = [ ]
350353 const serviceConfigs = [ ]
@@ -385,15 +388,15 @@ export const serviceHandlers: Record<string, ServiceHandlerConfig> = {${serviceC
385388
386389 const configPath = path . join ( ROOT_DIR , "src" , "core" , "controller" , "grpc-service-config.ts" )
387390 await fs . writeFile ( configPath , content )
388- console . log ( chalk . green ( `Generated service configuration at ${ configPath } ` ) )
391+ log_verbose ( chalk . green ( `Generated service configuration at ${ configPath } ` ) )
389392}
390393
391394/**
392395 * Ensure that a .proto file exists for each service in the serviceNameMap
393396 * If a .proto file doesn't exist, create a template file
394397 */
395398async function ensureProtoFilesExist ( ) {
396- console . log ( chalk . cyan ( "Checking for missing proto files..." ) )
399+ log_verbose ( chalk . cyan ( "Checking for missing proto files..." ) )
397400
398401 // Get existing proto files
399402 const existingProtoFiles = await globby ( "*.proto" , { cwd : SCRIPT_DIR } )
@@ -402,7 +405,7 @@ async function ensureProtoFilesExist() {
402405 // Check each service in serviceNameMap
403406 for ( const [ serviceName , fullServiceName ] of Object . entries ( serviceNameMap ) ) {
404407 if ( ! existingProtoServices . includes ( serviceName ) ) {
405- console . log ( chalk . yellow ( `Creating template proto file for ${ serviceName } ...` ) )
408+ log_verbose ( chalk . yellow ( `Creating template proto file for ${ serviceName } ...` ) )
406409
407410 // Extract service class name from full name (e.g., "cline.ModelsService" -> "ModelsService")
408411 const serviceClassName = fullServiceName . split ( "." ) . pop ( )
@@ -435,7 +438,7 @@ service ${serviceClassName} {
435438 // Write the template proto file
436439 const protoFilePath = path . join ( SCRIPT_DIR , `${ serviceName } .proto` )
437440 await fs . writeFile ( protoFilePath , protoContent )
438- console . log ( chalk . green ( `Created template proto file at ${ protoFilePath } ` ) )
441+ log_verbose ( chalk . green ( `Created template proto file at ${ protoFilePath } ` ) )
439442 }
440443 }
441444}
@@ -444,7 +447,7 @@ service ${serviceClassName} {
444447 * Generate method registration files for host services
445448 */
446449async function generateHostMethodRegistrations ( ) {
447- console . log ( chalk . cyan ( "Generating host method registration files..." ) )
450+ log_verbose ( chalk . cyan ( "Generating host method registration files..." ) )
448451
449452 // Parse proto files for streaming methods
450453 const hostProtoFiles = await globby ( "*.proto" , { cwd : path . join ( SCRIPT_DIR , "host" ) } )
@@ -454,7 +457,7 @@ async function generateHostMethodRegistrations() {
454457 try {
455458 await fs . access ( serviceDir )
456459 } catch ( error ) {
457- console . log ( chalk . cyan ( `Creating directory ${ serviceDir } for new host service` ) )
460+ log_verbose ( chalk . cyan ( `Creating directory ${ serviceDir } for new host service` ) )
458461 await fs . mkdir ( serviceDir , { recursive : true } )
459462 }
460463
@@ -465,7 +468,7 @@ async function generateHostMethodRegistrations() {
465468 const fullServiceName = hostServiceNameMap [ serviceName ]
466469 const streamingMethods = streamingMethodsMap . get ( fullServiceName ) || [ ]
467470
468- console . log ( chalk . cyan ( `Generating method registrations for host ${ serviceName } ...` ) )
471+ log_verbose ( chalk . cyan ( `Generating method registrations for host ${ serviceName } ...` ) )
469472
470473 // Get all TypeScript files in the service directory
471474 const files = await globby ( "*.ts" , { cwd : serviceDir } )
@@ -518,7 +521,7 @@ export function registerAllMethods(): void {
518521
519522 // Write the methods.ts file
520523 await fs . writeFile ( registryFile , methodsContent )
521- console . log ( chalk . green ( `Generated ${ registryFile } ` ) )
524+ log_verbose ( chalk . green ( `Generated ${ registryFile } ` ) )
522525
523526 // Generate index.ts file
524527 const capitalizedServiceName = serviceName . charAt ( 0 ) . toUpperCase ( ) + serviceName . slice ( 1 )
@@ -547,17 +550,17 @@ registerAllMethods()`
547550
548551 // Write the index.ts file
549552 await fs . writeFile ( indexFile , indexContent )
550- console . log ( chalk . green ( `Generated ${ indexFile } ` ) )
553+ log_verbose ( chalk . green ( `Generated ${ indexFile } ` ) )
551554 }
552555
553- console . log ( chalk . green ( "Host method registration files generated successfully." ) )
556+ log_verbose ( chalk . green ( "Host method registration files generated successfully." ) )
554557}
555558
556559/**
557560 * Generate a service configuration file for host services
558561 */
559562async function generateHostServiceConfig ( ) {
560- console . log ( chalk . cyan ( "Generating host service configuration file..." ) )
563+ log_verbose ( chalk . cyan ( "Generating host service configuration file..." ) )
561564
562565 const serviceImports = [ ]
563566 const serviceConfigs = [ ]
@@ -598,21 +601,21 @@ export const hostServiceHandlers: Record<string, HostServiceHandlerConfig> = {${
598601 const configPath = path . join ( ROOT_DIR , "src" , "hosts" , "vscode" , "host-grpc-service-config.ts" )
599602 await fs . mkdir ( path . dirname ( configPath ) , { recursive : true } )
600603 await fs . writeFile ( configPath , content )
601- console . log ( chalk . green ( `Generated host service configuration at ${ configPath } ` ) )
604+ log_verbose ( chalk . green ( `Generated host service configuration at ${ configPath } ` ) )
602605}
603606
604607/**
605608 * Generate a gRPC client configuration file for host services
606609 */
607610async function generateHostGrpcClientConfig ( ) {
608- console . log ( chalk . cyan ( "Generating host gRPC client configuration..." ) )
611+ log_verbose ( chalk . cyan ( "Generating host gRPC client configuration..." ) )
609612
610613 const serviceImports = [ ]
611614 const serviceClientCreations = [ ]
612615 const serviceExports = [ ]
613616
614617 // Process each service in the hostServiceNameMap
615- for ( const [ dirName , fullServiceName ] of Object . entries ( hostServiceNameMap ) ) {
618+ for ( const [ dirName , _fullServiceName ] of Object . entries ( hostServiceNameMap ) ) {
616619 const capitalizedName = dirName . charAt ( 0 ) . toUpperCase ( ) + dirName . slice ( 1 )
617620
618621 // Add import statement
@@ -643,12 +646,12 @@ export {
643646 const configPath = path . join ( ROOT_DIR , "src" , "hosts" , "vscode" , "client" , "host-grpc-client.ts" )
644647 await fs . mkdir ( path . dirname ( configPath ) , { recursive : true } )
645648 await fs . writeFile ( configPath , content )
646- console . log ( chalk . green ( `Generated host gRPC client at ${ configPath } ` ) )
649+ log_verbose ( chalk . green ( `Generated host gRPC client at ${ configPath } ` ) )
647650}
648651
649652async function cleanup ( ) {
650653 // Clean up existing generated files
651- console . log ( chalk . cyan ( "Cleaning up existing generated TypeScript files..." ) )
654+ log_verbose ( chalk . cyan ( "Cleaning up existing generated TypeScript files..." ) )
652655 const existingFiles = await globby ( "**/*.ts" , { cwd : TS_OUT_DIR } )
653656 for ( const file of existingFiles ) {
654657 await fs . unlink ( path . join ( TS_OUT_DIR , file ) )
@@ -705,6 +708,12 @@ function checkAppleSiliconCompatibility() {
705708 }
706709}
707710
711+ function log_verbose ( s ) {
712+ if ( process . argv . includes ( "-v" ) || process . argv . includes ( "--verbose" ) ) {
713+ console . log ( s )
714+ }
715+ }
716+
708717// Run the main function
709718main ( ) . catch ( ( error ) => {
710719 console . error ( chalk . red ( "Error:" ) , error )
0 commit comments