@@ -5,10 +5,14 @@ const version = '1.10.0';
55
66( async ( ) => {
77 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' ) ;
915 const path = require ( 'node:path' ) ;
10- const shell = require ( 'shelljs' ) ;
11- const { v4 } = require ( 'uuid' ) ;
1216 const { exec } = require ( './utils' ) ;
1317
1418 const destination = path . join (
@@ -20,31 +24,38 @@ const version = '1.10.0';
2024 'Examples'
2125 ) ;
2226 if ( existsSync ( destination ) ) {
23- shell . echo (
27+ console . log (
2428 `Skipping Git checkout of the examples because the repository already exists: ${ destination } `
2529 ) ;
2630 return ;
2731 }
2832
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+ ) ;
3336
3437 exec (
3538 'git' ,
3639 [ 'clone' , 'https://github.com/arduino/arduino-examples.git' , repository ] ,
37- shell
40+ { logStdout : true }
3841 ) ;
3942
4043 exec (
4144 'git' ,
4245 [ '-C' , repository , 'checkout' , `tags/${ version } ` , '-b' , version ] ,
43- shell
46+ { logStdout : true }
4447 ) ;
4548
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+ }
4859
4960 const isSketch = async ( pathLike ) => {
5061 try {
@@ -104,5 +115,5 @@ const version = '1.10.0';
104115 JSON . stringify ( examples , null , 2 ) ,
105116 { encoding : 'utf8' }
106117 ) ;
107- shell . echo ( `Generated output to ${ path . join ( destination , 'examples.json' ) } ` ) ;
118+ console . log ( `Generated output to ${ path . join ( destination , 'examples.json' ) } ` ) ;
108119} ) ( ) ;
0 commit comments