6
6
'use strict'
7
7
8
8
/*
9
- * This script removes the specified folders.
9
+ * This script removes the specified folders.
10
10
* Used to perform a clean compile, which is useful for things like:
11
11
* - flushing out stale test files.
12
12
* - updating dependencies after changing branches
13
13
*/
14
14
15
- const fs = require ( 'fs' ) ;
16
- const _path = require ( 'path' ) ;
15
+ const fs = require ( 'fs' )
16
+ const _path = require ( 'path' )
17
17
const util = require ( 'util' )
18
18
19
19
const readdir = util . promisify ( fs . readdir )
@@ -24,39 +24,40 @@ const unlink = util.promisify(fs.unlink)
24
24
// Recursive delete without requiring a third-party library. This allows the script
25
25
// to be run before `npm install`.
26
26
async function rdelete ( path ) {
27
- const stats = await stat ( path ) ;
27
+ const stats = await stat ( path )
28
28
if ( stats . isFile ( ) ) {
29
- await unlink ( path ) ;
29
+ await unlink ( path )
30
30
} else if ( stats . isDirectory ( ) ) {
31
- const promises = ( await readdir ( path ) )
32
- . map ( child => rdelete ( _path . join ( path , child ) ) ) ;
31
+ const promises = ( await readdir ( path ) ) . map ( child => rdelete ( _path . join ( path , child ) ) )
33
32
34
- await Promise . all ( promises ) ;
35
- await rmdir ( path ) ;
33
+ await Promise . all ( promises )
34
+ await rmdir ( path )
36
35
} else {
37
- throw new Error ( `Could not delete '${ path } ' because it is neither a file nor directory` ) ;
36
+ throw new Error ( `Could not delete '${ path } ' because it is neither a file nor directory` )
38
37
}
39
38
}
40
39
41
- ( async ( ) => {
40
+ ; ( async ( ) => {
42
41
for ( const arg of process . argv . slice ( 2 ) ) {
43
42
try {
44
- const directory = _path . join ( __dirname , '..' , arg ) ;
43
+ const directory = _path . join ( __dirname , '..' , arg )
45
44
46
45
try {
47
- fs . accessSync ( directory ) ;
46
+ fs . accessSync ( directory )
48
47
} catch ( e ) {
49
- console . log ( `Could not access '${ directory } ', probably because it does not exist. Skipping clean for this directory.` ) ;
50
- return ;
48
+ console . log (
49
+ `Could not access '${ directory } ', probably because it does not exist. Skipping clean for this directory.`
50
+ )
51
+ return
51
52
}
52
53
53
- console . log ( `Removing ${ directory } ...` ) ;
54
+ console . log ( `Removing ${ directory } ...` )
54
55
55
- await rdelete ( directory ) ;
56
+ await rdelete ( directory )
56
57
57
- console . log ( 'Done' ) ;
58
+ console . log ( 'Done' )
58
59
} catch ( e ) {
59
- console . error ( `Could not clean '${ arg } ': ${ String ( e ) } ` ) ;
60
+ console . error ( `Could not clean '${ arg } ': ${ String ( e ) } ` )
60
61
}
61
62
}
62
- } ) ( ) ;
63
+ } ) ( )
0 commit comments