@@ -41,20 +41,21 @@ export class ArduinoApp {
41
41
if ( force || ! util . fileExistsSync ( path . join ( this . _settings . packagePath , "package_index.json" ) ) ) {
42
42
try {
43
43
// Use the dummy package to initialize the Arduino IDE
44
- await this . installBoard ( "dummy" , "dummy " , "" , false ) ;
44
+ await this . installBoard ( "dummy" , "" , "" , true ) ;
45
45
} catch ( ex ) {
46
46
}
47
47
}
48
48
}
49
49
50
50
/**
51
51
* Initialize the arduino library.
52
+ * @param {boolean } force - Whether force refresh library index file
52
53
*/
53
- public async initializeLibrary ( ) {
54
- if ( ! util . fileExistsSync ( path . join ( this . _settings . packagePath , "library_index.json" ) ) ) {
54
+ public async initializeLibrary ( force : boolean = false ) {
55
+ if ( force || ! util . fileExistsSync ( path . join ( this . _settings . packagePath , "library_index.json" ) ) ) {
55
56
try {
56
57
// Use the dummy library to initialize the Arduino IDE
57
- await this . installLibrary ( "dummy" , "" , false ) ;
58
+ await this . installLibrary ( "dummy" , "" , true ) ;
58
59
} catch ( ex ) {
59
60
}
60
61
}
@@ -177,17 +178,35 @@ export class ArduinoApp {
177
178
/**
178
179
* Install arduino board package based on package name and platform hardware architecture.
179
180
*/
180
- public async installBoard ( packageName : string , arch : string , version : string = "" , showOutput : boolean = true ) {
181
+ public async installBoard ( packageName : string , arch : string = "" , version : string = "" , showOutput : boolean = true ) {
181
182
arduinoChannel . show ( ) ;
182
- arduinoChannel . start ( `Install package - ${ packageName } ...` ) ;
183
+ const updatingIndex = packageName === "dummy" && ! arch && ! version ;
184
+ if ( updatingIndex ) {
185
+ arduinoChannel . start ( `Update package index files...` ) ;
186
+ } else {
187
+ arduinoChannel . start ( `Install package - ${ packageName } ...` ) ;
188
+ }
183
189
try {
184
190
await util . spawn ( this . _settings . commandPath ,
185
191
showOutput ? arduinoChannel . channel : null ,
186
- [ "--install-boards" , `${ packageName } : ${ arch } ${ version && ":" + version } ` ] ) ;
192
+ [ "--install-boards" , `${ packageName } ${ arch && ":" + arch } ${ version && ":" + version } ` ] ) ;
187
193
188
- arduinoChannel . end ( `Installed board package - ${ packageName } ${ os . EOL } ` ) ;
194
+ if ( updatingIndex ) {
195
+ arduinoChannel . end ( "Updated package index files." ) ;
196
+ } else {
197
+ arduinoChannel . end ( `Installed board package - ${ packageName } ${ os . EOL } ` ) ;
198
+ }
189
199
} catch ( error ) {
190
- arduinoChannel . error ( `Exit with code=${ error . code } ${ os . EOL } ` ) ;
200
+ // If a platform with the same version is already installed, nothing is installed and program exits with exit code 1
201
+ if ( error . code === 1 ) {
202
+ if ( updatingIndex ) {
203
+ arduinoChannel . end ( "Updated package index files." ) ;
204
+ } else {
205
+ arduinoChannel . end ( `Installed board package - ${ packageName } ${ os . EOL } ` ) ;
206
+ }
207
+ } else {
208
+ arduinoChannel . error ( `Exit with code=${ error . code } ${ os . EOL } ` ) ;
209
+ }
191
210
}
192
211
}
193
212
@@ -199,15 +218,33 @@ export class ArduinoApp {
199
218
200
219
public async installLibrary ( libName : string , version : string = "" , showOutput : boolean = true ) {
201
220
arduinoChannel . show ( ) ;
202
- arduinoChannel . start ( `Install library - ${ libName } ` ) ;
221
+ const updatingIndex = ( libName === "dummy" && ! version ) ;
222
+ if ( updatingIndex ) {
223
+ arduinoChannel . start ( "Update library index files..." ) ;
224
+ } else {
225
+ arduinoChannel . start ( `Install library - ${ libName } ` ) ;
226
+ }
203
227
try {
204
228
await util . spawn ( this . _settings . commandPath ,
205
229
showOutput ? arduinoChannel . channel : null ,
206
230
[ "--install-library" , `${ libName } ${ version && ":" + version } ` ] ) ;
207
231
208
- arduinoChannel . end ( `Installed library - ${ libName } ${ os . EOL } ` ) ;
232
+ if ( updatingIndex ) {
233
+ arduinoChannel . end ( "Updated library index files." ) ;
234
+ } else {
235
+ arduinoChannel . end ( `Installed library - ${ libName } ${ os . EOL } ` ) ;
236
+ }
209
237
} catch ( error ) {
210
- arduinoChannel . error ( `Exit with code=${ error . code } ${ os . EOL } ` ) ;
238
+ // If a library with the same version is already installed, nothing is installed and program exits with exit code 1
239
+ if ( error . code === 1 ) {
240
+ if ( updatingIndex ) {
241
+ arduinoChannel . end ( "Updated library index files." ) ;
242
+ } else {
243
+ arduinoChannel . end ( `Installed library - ${ libName } ${ os . EOL } ` ) ;
244
+ }
245
+ } else {
246
+ arduinoChannel . error ( `Exit with code=${ error . code } ${ os . EOL } ` ) ;
247
+ }
211
248
}
212
249
}
213
250
0 commit comments