1
1
#!/usr/bin/env node
2
- 'use strict'
3
- const yargs_parser = require ( 'yargs-parser' )
4
- const path = require ( " path" ) ;
2
+ 'use strict' ;
3
+ const yargs_parser = require ( 'yargs-parser' ) ;
4
+ const path = require ( ' path' ) ;
5
5
const chalk = require ( 'chalk' ) ;
6
- const ora = require ( " ora" ) ;
6
+ const ora = require ( ' ora' ) ;
7
7
const { extract } = require ( 'pacote' ) ;
8
- const fs = require ( " fs-extra" ) ;
8
+ const fs = require ( ' fs-extra' ) ;
9
9
const os = require ( 'os' ) ;
10
10
const packageName = 'html5-boilerplate' ;
11
- const tempDir = os . tmpdir ( ) + `/${ packageName } -staging` ;
12
- const elapsed = require ( " elapsed-time-logger" ) ;
11
+ const tempDir = os . tmpdir ( ) + `/${ packageName } -staging` ;
12
+ const elapsed = require ( ' elapsed-time-logger' ) ;
13
13
14
14
module . exports = async ( ) => {
15
- const argv = yargs_parser ( process . argv . slice ( 2 ) , { alias :{ release : [ 'r' ] } } ) ;
16
- const timer = elapsed . start ( ) ;
17
- const version = argv [ 'release' ] || 'latest' ;
18
- const targetDir = path . resolve ( argv [ '_' ] [ 0 ] || './' ) ;
19
- const spinner = ora ( `Downloading ${ packageName } version '${ version } ' to ${ targetDir } ` ) . start ( ) ;
20
- await fs . ensureDir ( tempDir ) ;
21
- try {
22
- const { from : nameWithVersion } = await extract ( packageName + '@' + version , tempDir , { } ) ;
23
- spinner . text = `${ nameWithVersion } copied to ${ targetDir } in ${ timer . get ( ) } . Have fun!` ;
24
- } catch ( err ) {
25
- await fs . remove ( tempDir ) ;
26
- if ( err . code === 'ETARGET' ) {
27
- spinner . fail ( chalk . red ( `version '${ err . wanted } ' not found in npm registry\navailable versions:` ) ) ;
28
- console . log ( err . versions . reverse ( ) . join ( ' | ' ) ) ;
29
- process . exit ( 1 ) ;
30
- } /* istanbul ignore next */ else {
31
- spinner . fail ( 'Unexpected error' ) ;
32
- console . error ( err ) ;
33
- process . exit ( - 1 ) ;
34
- } ;
35
- return ;
36
- }
37
- await fs . copy ( tempDir + '/dist' , targetDir ) ;
38
- await fs . remove ( tempDir ) ;
39
- spinner . succeed ( ) ;
40
- return ;
41
- } ;
15
+ const argv = yargs_parser ( process . argv . slice ( 2 ) , { alias : { release : [ 'r' ] } } ) ;
16
+ const timer = elapsed . start ( ) ;
17
+ const version = argv [ 'release' ] || 'latest' ;
18
+ const targetDir = path . resolve ( argv [ '_' ] [ 0 ] || './' ) ;
19
+ const spinner = ora ( `Downloading ${ packageName } version '${ version } ' to ${ targetDir } ` ) . start ( ) ;
20
+ await fs . ensureDir ( tempDir ) ;
21
+ try {
22
+ const { from : nameWithVersion } = await extract ( packageName + '@' + version , tempDir , { } ) ;
23
+ spinner . text = `${ nameWithVersion } copied to ${ targetDir } in ${ timer . get ( ) } . Have fun!` ;
24
+ } catch ( err ) {
25
+ await fs . remove ( tempDir ) ;
26
+ if ( err . code === 'ETARGET' ) {
27
+ spinner . fail ( chalk . red ( `version '${ err . wanted } ' not found in npm registry\navailable versions:` ) ) ;
28
+ console . log ( err . versions . reverse ( ) . join ( ' | ' ) ) ;
29
+ process . exit ( 1 ) ;
30
+ } /* istanbul ignore next */ else {
31
+ spinner . fail ( 'Unexpected error' ) ;
32
+ console . error ( err ) ;
33
+ process . exit ( - 1 ) ;
34
+ }
35
+ return ;
36
+ }
37
+ await fs . copy ( tempDir + '/dist' , targetDir ) ;
38
+ await fs . remove ( tempDir ) ;
39
+ spinner . succeed ( ) ;
40
+ return ;
41
+ } ;
0 commit comments