7
7
8
8
const { execSync } = require ( "child_process" ) ;
9
9
const { createHash } = require ( "crypto" ) ;
10
- const { readFileSync, mkdirSync, rmSync, renameSync } = require ( "fs" ) ;
10
+ const { readFileSync, mkdirSync, rmSync, renameSync, existsSync } = require ( "fs" ) ;
11
11
const { resolve } = require ( "path" ) ;
12
12
13
13
function run ( command ) {
@@ -24,48 +24,52 @@ for (const asset in config.assets) {
24
24
for ( const platform of platforms ) {
25
25
const directory = resolve ( __dirname , ".." , "assets" , "platform" , platform ) ;
26
26
const destination = resolve ( directory , asset ) ;
27
+ const extractDirectory = resolve ( directory , "arduino-cli" ) ;
28
+ // Check if the asset has already been downloaded
29
+ if ( ! existsSync ( extractDirectory ) ) {
27
30
28
- // Download the asset.
29
- run ( [
30
- "curl" ,
31
- `https://github.com/arduino/arduino-cli/releases/download/${ config . version } /${ asset } ` ,
32
- "--location" ,
33
- `--output-dir ${ directory } ` ,
34
- `--remote-name` ,
35
- "--silent" ,
36
- "--show-error" ,
37
- ] . join ( " " ) ) ;
31
+ // Download the asset.
32
+ run ( [
33
+ "curl" ,
34
+ `https://github.com/arduino/arduino-cli/releases/download/${ config . version } /${ asset } ` ,
35
+ "--location" ,
36
+ `--output-dir ${ directory } ` ,
37
+ `--remote-name` ,
38
+ "--silent" ,
39
+ "--show-error" ,
40
+ ] . join ( " " ) ) ;
38
41
39
- // Verify the hash.
40
- const actualHash = createHash ( "sha256" )
41
- . update ( readFileSync ( destination ) )
42
- . digest ( "hex" ) ;
43
- if ( actualHash !== hash ) {
44
- throw new Error (
45
- `Hash mismatch for ${ asset } on ${ platform } . Expected ${ hash } but got ${ actualHash } .`
46
- ) ;
47
- }
42
+ // Verify the hash.
43
+ const actualHash = createHash ( "sha256" )
44
+ . update ( readFileSync ( destination ) )
45
+ . digest ( "hex" ) ;
46
+ if ( actualHash !== hash ) {
47
+ throw new Error (
48
+ `Hash mismatch for ${ asset } on ${ platform } . Expected ${ hash } but got ${ actualHash } .`
49
+ ) ;
50
+ }
51
+
48
52
49
- // Extract to an "arduino-cli" directory.
50
- const extractDirectory = resolve ( directory , "arduino-cli" ) ;
51
- mkdirSync ( extractDirectory , { recursive : true } ) ;
52
- // tar on Linux doesn't understand zip files.
53
- if ( asset . endsWith ( ".zip" ) && process . platform === 'linux' ) {
54
- run ( `unzip ${ destination } -d ${ extractDirectory } ` ) ;
55
- } else {
56
- run ( `tar -xf ${ destination } -C ${ extractDirectory } ` ) ;
57
- }
53
+ // Extract to an "arduino-cli" directory.
54
+ mkdirSync ( extractDirectory , { recursive : true } ) ;
55
+ // tar on Linux doesn't understand zip files.
56
+ if ( asset . endsWith ( ".zip" ) && process . platform === 'linux' ) {
57
+ run ( `unzip ${ destination } -d ${ extractDirectory } ` ) ;
58
+ } else {
59
+ run ( `tar -xf ${ destination } -C ${ extractDirectory } ` ) ;
60
+ }
58
61
59
- // Remove the downloaded archive. We don't need to ship it.
60
- rmSync ( destination ) ;
62
+ // Remove the downloaded archive. We don't need to ship it.
63
+ rmSync ( destination ) ;
61
64
62
- // VSIX signing will silently strip any extensionless files. Artificially
63
- // add a ".app" extension to extensionless executables.
64
- const executable = resolve ( extractDirectory , "arduino-cli" ) ;
65
- try {
66
- renameSync ( executable , `${ executable } .app` ) ;
67
- } catch {
68
- // The file might not exist. This is expected for Windows.
65
+ // VSIX signing will silently strip any extensionless files. Artificially
66
+ // add a ".app" extension to extensionless executables.
67
+ const executable = resolve ( extractDirectory , "arduino-cli" ) ;
68
+ try {
69
+ renameSync ( executable , `${ executable } .app` ) ;
70
+ } catch {
71
+ // The file might not exist. This is expected for Windows.
72
+ }
69
73
}
70
74
}
71
75
}
0 commit comments