1
1
// based on https://github.com/webpack/webpack/blob/master/bin/webpack.js
2
- module . exports = function promptForInstallation ( package , ...args ) {
2
+ module . exports = function promptForInstallation ( packages , ...args ) {
3
3
4
- let packageIsInstalled = false ;
5
- try {
6
- require . resolve ( package ) ;
7
- packageIsInstalled = true ;
8
- } catch ( err ) {
9
- packageIsInstalled = false ;
10
- }
4
+ let packageIsInstalled = false ;
5
+ try {
6
+ require . resolve ( packages ) ;
7
+ packageIsInstalled = true ;
8
+ } catch ( err ) {
9
+ packageIsInstalled = false ;
10
+ }
11
11
12
- if ( ! packageIsInstalled ) {
13
- const path = require ( "path" ) ;
14
- const fs = require ( "fs" ) ;
15
- const readLine = require ( "readline" ) ;
16
- const isYarn = fs . existsSync ( path . resolve ( process . cwd ( ) , "yarn.lock" ) ) ;
12
+ if ( ! packageIsInstalled ) {
13
+ const path = require ( "path" ) ;
14
+ const fs = require ( "fs" ) ;
15
+ const readLine = require ( "readline" ) ;
16
+ const isYarn = fs . existsSync ( path . resolve ( process . cwd ( ) , "yarn.lock" ) ) ;
17
17
18
- const packageManager = isYarn ? "yarn" : "npm" ;
19
- const options = [ "install" , "-D" , package ] ;
18
+ const packageManager = isYarn ? "yarn" : "npm" ;
19
+ const options = [ "install" , "-D" , packages ] ;
20
20
21
- if ( isYarn ) {
22
- options [ 0 ] = "add" ;
23
- }
21
+ if ( isYarn ) {
22
+ options [ 0 ] = "add" ;
23
+ }
24
24
25
- const commandToBeRun = `${ packageManager } ${ options . join ( " " ) } ` ;
25
+ const commandToBeRun = `${ packageManager } ${ options . join ( " " ) } ` ;
26
26
27
- const question = `Would you like to install ${ package } ? (That will run ${ commandToBeRun } ) (yes/NO)` ;
27
+ const question = `Would you like to install ${ packages } ? (That will run ${ commandToBeRun } ) (yes/NO)` ;
28
28
29
- console . error ( `The command moved into a separate package: @webpack-cli/${ package } ` ) ;
30
- const questionInterface = readLine . createInterface ( {
31
- input : process . stdin ,
32
- output : process . stdout
33
- } ) ;
34
- questionInterface . question ( question , answer => {
35
- questionInterface . close ( ) ;
36
- switch ( answer . toLowerCase ( ) ) {
37
- case "y" :
38
- case "yes" :
39
- case "1" : {
40
- runCommand ( packageManager , options )
41
- . then ( result => {
42
- return require ( `@webpack-cli/${ package } ` ) ( ...args ) ; //eslint-disable-line
43
- } )
44
- . catch ( error => {
45
- console . error ( error ) ;
46
- process . exitCode = 1 ;
47
- } ) ;
48
- break ;
29
+ console . error ( `The command moved into a separate package: @webpack-cli/${ packages } ` ) ;
30
+ const questionInterface = readLine . createInterface ( {
31
+ input : process . stdin ,
32
+ output : process . stdout
33
+ } ) ;
34
+ questionInterface . question ( question , answer => {
35
+ questionInterface . close ( ) ;
36
+ switch ( answer . toLowerCase ( ) ) {
37
+ case "y" :
38
+ case "yes" :
39
+ case "1" : {
40
+ //eslint-disable-next-line
41
+ runCommand ( packageManager , options )
42
+ . then ( result => {
43
+ return require ( `@webpack-cli/${ packages } ` ) ( ...args ) ; //eslint-disable-line
44
+ } )
45
+ . catch ( error => {
46
+ console . error ( error ) ;
47
+ process . exitCode = 1 ;
48
+ } ) ;
49
+ break ;
50
+ }
51
+ default : {
52
+ console . error (
53
+ "It needs to be installed alongside webpack CLI to use the command"
54
+ ) ;
55
+ process . exitCode = 1 ;
56
+ break ;
57
+ }
49
58
}
50
- default : {
51
- console . error (
52
- "It needs to be installed alongside webpack CLI to use the command"
53
- ) ;
54
- process . exitCode = 1 ;
55
- break ;
56
- }
57
- }
58
- } ) ;
59
- } else {
60
- require ( package ) ( ...args ) ; // eslint-disable-line
61
- }
62
- }
59
+ } ) ;
60
+ } else {
61
+ require ( packages ) ( ...args ) ; // eslint-disable-line
62
+ }
63
+ } ;
0 commit comments