@@ -75,25 +75,46 @@ async function updateCppPropertiesFile(
7575
7676async function updateTasksFile (
7777 tasksFile : string ,
78- newNinjaVersion : string
78+ newPicotoolVersion : string ,
79+ newNinjaVersion ?: string
7980) : Promise < void > {
80- // read tasksFile (it contains the path)
81- let content = await readFile ( tasksFile , "utf8" ) ;
82-
83- // if a string with following format .pico-sdk/ninja/<version>/ exists
84- // then replace <version> with the new version
85- if ( content . includes ( ".pico-sdk/ninja/" ) ) {
86- const oldNinjaVersion = content . match ( / (?< = \. p i c o - s d k \/ n i n j a \/ ) ( .* ) (? = \/ ) / ) ;
87- if ( oldNinjaVersion !== null ) {
88- content = content . replaceAll (
89- `.pico-sdk/ninja/${ oldNinjaVersion [ 0 ] } ` ,
90- `.pico-sdk/ninja/${ newNinjaVersion } `
91- ) ;
81+ try {
82+ // read tasksFile (it contains the path)
83+ let content = await readFile ( tasksFile , "utf8" ) ;
84+
85+ // if a string with following format .pico-sdk/<thing>/<version>/ exists
86+ // then replace <version> with the new version
87+
88+ if ( content . includes ( ".pico-sdk/picotool/" ) ) {
89+ const oldPicotoolVersion =
90+ content . match ( / (?< = \. p i c o - s d k \/ p i c o t o o l \/ ) ( .* ) (? = \/ ) / ) ;
91+ if ( oldPicotoolVersion !== null ) {
92+ content = content . replaceAll (
93+ `.pico-sdk/picotool/${ oldPicotoolVersion [ 0 ] } ` ,
94+ `.pico-sdk/picotool/${ newPicotoolVersion } `
95+ ) ;
96+ }
9297 }
93- }
9498
95- // save tasksFile
96- await writeFile ( tasksFile , content , "utf8" ) ;
99+ if ( newNinjaVersion ) {
100+ if ( content . includes ( ".pico-sdk/ninja/" ) ) {
101+ const oldNinjaVersion =
102+ content . match ( / (?< = \. p i c o - s d k \/ n i n j a \/ ) ( .* ) (? = \/ ) / ) ;
103+ if ( oldNinjaVersion !== null ) {
104+ content = content . replaceAll (
105+ `.pico-sdk/ninja/${ oldNinjaVersion [ 0 ] } ` ,
106+ `.pico-sdk/ninja/${ newNinjaVersion } `
107+ ) ;
108+ }
109+ }
110+ }
111+
112+ // save tasksFile
113+ await writeFile ( tasksFile , content , "utf8" ) ;
114+ console . log ( "tasks.json file updated successfully." ) ;
115+ } catch {
116+ Logger . log ( "Error updating tasks.json file." ) ;
117+ }
97118}
98119
99120function buildCMakePath ( cmakeVersion : string ) : string {
@@ -305,8 +326,6 @@ export async function updateVSCodeStaticConfigs(
305326 const launchFile = join ( folder , ".vscode" , "launch.json" ) ;
306327 await updateLaunchFile ( launchFile , newSDKVersion ) ;
307328
308- if ( newNinjaVersion ) {
309- const tasksFile = join ( folder , ".vscode" , "tasks.json" ) ;
310- await updateTasksFile ( tasksFile , newNinjaVersion ) ;
311- }
329+ const tasksFile = join ( folder , ".vscode" , "tasks.json" ) ;
330+ await updateTasksFile ( tasksFile , newPicotoolVersion , newNinjaVersion ) ;
312331}
0 commit comments