1
1
// based on https://github.com/webpack/webpack/blob/master/bin/webpack.js
2
- module . exports = function promptForInstallation ( command , options ) {
3
- const cp = require ( "child_process" ) ;
4
- return new Promise ( ( resolve , reject ) => {
5
- const executedCommand = cp . spawn ( command , options , {
6
- stdio : "inherit" ,
7
- shell : true
8
- } ) ;
9
-
10
- executedCommand . on ( "error" , error => {
11
- reject ( error ) ;
12
- } ) ;
13
-
14
- executedCommand . on ( "exit" , code => {
15
- if ( code === 0 ) {
16
- resolve ( true ) ;
17
- } else {
18
- reject ( ) ;
19
- }
20
- } ) ;
21
- } ) ;
22
- }
2
+ module . exports = function promptForInstallation ( package , ...args ) {
23
3
24
4
let packageIsInstalled = false ;
25
5
try {
@@ -44,9 +24,9 @@ if (!packageIsInstalled) {
44
24
45
25
const commandToBeRun = `${ packageManager } ${ options . join ( " " ) } ` ;
46
26
47
- const question = `Would you like to install ${ packageIsInstalled } ? (That will run ${ commandToBeRun } ) (yes/NO)` ;
27
+ const question = `Would you like to install ${ package } ? (That will run ${ commandToBeRun } ) (yes/NO)` ;
48
28
49
- console . error ( `The CLI moved into a separate package: @webpack-cli/${ package } ` ) ;
29
+ console . error ( `The command moved into a separate package: @webpack-cli/${ package } ` ) ;
50
30
const questionInterface = readLine . createInterface ( {
51
31
input : process . stdin ,
52
32
output : process . stdout
@@ -59,7 +39,7 @@ if (!packageIsInstalled) {
59
39
case "1" : {
60
40
runCommand ( packageManager , options )
61
41
. then ( result => {
62
- return require ( `@webpack-cli/${ package } ` ) ; //eslint-disable-line
42
+ return require ( `@webpack-cli/${ package } ` ) ( ... args ) ; //eslint-disable-line
63
43
} )
64
44
. catch ( error => {
65
45
console . error ( error ) ;
@@ -69,13 +49,14 @@ if (!packageIsInstalled) {
69
49
}
70
50
default : {
71
51
console . error (
72
- "It needs to be installed alongside webpack to use the CLI "
52
+ "It needs to be installed alongside webpack CLI to use the command "
73
53
) ;
74
54
process . exitCode = 1 ;
75
55
break ;
76
56
}
77
57
}
78
58
} ) ;
79
59
} else {
80
- require ( package ) ; // eslint-disable-line
60
+ require ( package ) ( ...args ) ; // eslint-disable-line
61
+ }
81
62
}
0 commit comments