@@ -5,10 +5,14 @@ const version = '1.10.0';
5
5
6
6
( async ( ) => {
7
7
const os = require ( 'node:os' ) ;
8
- const { existsSync, promises : fs } = require ( 'node:fs' ) ;
8
+ const {
9
+ existsSync,
10
+ promises : fs ,
11
+ mkdirSync,
12
+ readdirSync,
13
+ cpSync,
14
+ } = require ( 'node:fs' ) ;
9
15
const path = require ( 'node:path' ) ;
10
- const shell = require ( 'shelljs' ) ;
11
- const { v4 } = require ( 'uuid' ) ;
12
16
const { exec } = require ( './utils' ) ;
13
17
14
18
const destination = path . join (
@@ -20,31 +24,38 @@ const version = '1.10.0';
20
24
'Examples'
21
25
) ;
22
26
if ( existsSync ( destination ) ) {
23
- shell . echo (
27
+ console . log (
24
28
`Skipping Git checkout of the examples because the repository already exists: ${ destination } `
25
29
) ;
26
30
return ;
27
31
}
28
32
29
- const repository = path . join ( os . tmpdir ( ) , `${ v4 ( ) } -arduino-examples` ) ;
30
- if ( shell . mkdir ( '-p' , repository ) . code !== 0 ) {
31
- shell . exit ( 1 ) ;
32
- }
33
+ const repository = await fs . mkdtemp (
34
+ path . join ( os . tmpdir ( ) , 'arduino-examples-' )
35
+ ) ;
33
36
34
37
exec (
35
38
'git' ,
36
39
[ 'clone' , 'https://github.com/arduino/arduino-examples.git' , repository ] ,
37
- shell
40
+ { logStdout : true }
38
41
) ;
39
42
40
43
exec (
41
44
'git' ,
42
45
[ '-C' , repository , 'checkout' , `tags/${ version } ` , '-b' , version ] ,
43
- shell
46
+ { logStdout : true }
44
47
) ;
45
48
46
- shell . mkdir ( '-p' , destination ) ;
47
- shell . cp ( '-fR' , path . join ( repository , 'examples' , '*' ) , destination ) ;
49
+ mkdirSync ( destination , { recursive : true } ) ;
50
+ const examplesPath = path . join ( repository , 'examples' ) ;
51
+ const exampleResources = readdirSync ( examplesPath ) ;
52
+ for ( const exampleResource of exampleResources ) {
53
+ cpSync (
54
+ path . join ( examplesPath , exampleResource ) ,
55
+ path . join ( destination , exampleResource ) ,
56
+ { recursive : true }
57
+ ) ;
58
+ }
48
59
49
60
const isSketch = async ( pathLike ) => {
50
61
try {
@@ -104,5 +115,5 @@ const version = '1.10.0';
104
115
JSON . stringify ( examples , null , 2 ) ,
105
116
{ encoding : 'utf8' }
106
117
) ;
107
- shell . echo ( `Generated output to ${ path . join ( destination , 'examples.json' ) } ` ) ;
118
+ console . log ( `Generated output to ${ path . join ( destination , 'examples.json' ) } ` ) ;
108
119
} ) ( ) ;
0 commit comments