@@ -12,32 +12,42 @@ const tempDir = os.tmpdir() + `/${packageName}-staging`;
12
12
const elapsed = require ( "elapsed-time-logger" ) ;
13
13
14
14
module . exports = async ( ) => {
15
- const argv = yargs_parser ( process . argv . slice ( 2 ) , {
16
- alias : { release : [ "r" ] } ,
17
- } ) ;
18
- const timer = elapsed . start ( ) ;
19
- const version = argv [ "release" ] || "latest" ;
20
- const targetDir = path . resolve ( argv [ "_" ] [ 0 ] || "./" ) ;
21
- const spinner = ora ( `Downloading ${ packageName } version '${ version } ' to ${ targetDir } ` ) . start ( ) ;
22
- await fs . ensureDir ( tempDir ) ;
23
- try {
24
- const { from : nameWithVersion } = await extract ( packageName + "@" + version , tempDir , { } ) ;
25
- spinner . text = `${ nameWithVersion } copied to ${ targetDir } in ${ timer . get ( ) } . Have fun!` ;
26
- } catch ( err ) {
27
- await fs . remove ( tempDir ) ;
28
- if ( err . code === "ETARGET" ) {
29
- spinner . fail ( chalk . red ( `version '${ err . wanted } ' not found in npm registry\navailable versions:` ) ) ;
30
- console . log ( err . versions . reverse ( ) . join ( " | " ) ) ;
31
- process . exit ( 1 ) ;
32
- } /* istanbul ignore next */ else {
33
- spinner . fail ( "Unexpected error" ) ;
34
- console . error ( err ) ;
35
- process . exit ( - 1 ) ;
36
- }
37
- return ;
38
- }
39
- await fs . copy ( tempDir + "/dist" , targetDir ) ;
40
- await fs . remove ( tempDir ) ;
41
- spinner . succeed ( ) ;
42
- return ;
15
+ const argv = yargs_parser ( process . argv . slice ( 2 ) , {
16
+ alias : { release : [ "r" ] } ,
17
+ } ) ;
18
+ const timer = elapsed . start ( ) ;
19
+ const version = argv [ "release" ] || "latest" ;
20
+ const targetDir = path . resolve ( argv [ "_" ] [ 0 ] || "./" ) ;
21
+ const spinner = ora (
22
+ `Downloading ${ packageName } version '${ version } ' to ${ targetDir } `
23
+ ) . start ( ) ;
24
+ await fs . ensureDir ( tempDir ) ;
25
+ try {
26
+ const { from : nameWithVersion } = await extract (
27
+ packageName + "@" + version ,
28
+ tempDir ,
29
+ { }
30
+ ) ;
31
+ spinner . text = `${ nameWithVersion } copied to ${ targetDir } in ${ timer . get ( ) } . Have fun!` ;
32
+ } catch ( err ) {
33
+ await fs . remove ( tempDir ) ;
34
+ if ( err . code === "ETARGET" ) {
35
+ spinner . fail (
36
+ chalk . red (
37
+ `version '${ err . wanted } ' not found in npm registry\navailable versions:`
38
+ )
39
+ ) ;
40
+ console . log ( err . versions . reverse ( ) . join ( " | " ) ) ;
41
+ process . exit ( 1 ) ;
42
+ } /* istanbul ignore next */ else {
43
+ spinner . fail ( "Unexpected error" ) ;
44
+ console . error ( err ) ;
45
+ process . exit ( - 1 ) ;
46
+ }
47
+ return ;
48
+ }
49
+ await fs . copy ( tempDir + "/dist" , targetDir ) ;
50
+ await fs . remove ( tempDir ) ;
51
+ spinner . succeed ( ) ;
52
+ return ;
43
53
} ;
0 commit comments