File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- #!/usr/bin/env node
1+ const { exec} = require ( 'child_process' ) ;
2+
3+
4+ function runCommand ( command ) {
5+ exec ( command , ( err , data ) => {
6+ if ( data ) {
7+ console . log ( data ) ;
8+ } else {
9+ console . log ( err ) ;
10+ }
11+ } ) ;
12+ }
213
314let webpackCliInstalled = false ;
415try {
@@ -11,10 +22,35 @@ try {
1122if ( webpackCliInstalled ) {
1223 require ( "webpack-cli" ) ; // eslint-disable-line node/no-missing-require, node/no-extraneous-require, node/no-unpublished-require
1324} else {
25+ const path = require ( 'path' ) ;
26+ const fs = require ( 'fs' ) ;
27+ const isYarn = fs . existsSync ( path . resolve ( process . cwd ( ) , 'yarn.lock' ) ) ;
28+ const { prompt} = require ( 'inquirer' ) ;
29+ let command ;
30+
31+
32+ const question = {
33+ type : 'confirm' ,
34+ name : 'shouldInstall' ,
35+ message : 'Would you like to install webpack-cli?' ,
36+ default : true
37+ }
38+
39+ if ( isYarn ) {
40+ command = 'yarn add webpack-cli -D' ;
41+ } else {
42+ command = 'npm install --save-dev webpack-cli' ;
43+ }
44+
1445 console . error ( "The CLI moved into a separate package: webpack-cli." ) ;
15- console . error (
16- "Please install 'webpack-cli' in addition to webpack itself to use the CLI."
17- ) ;
46+ prompt ( question ) . then ( ( anwswer ) => {
47+ if ( answer ) {
48+ console . error ( 'Installing webpack-cli' )
49+ runCommand ( command ) ;
50+ }
51+ } )
52+
53+ console . error ( "Please install 'webpack-cli' in addition to webpack itself to use the CLI." ) ;
1854 console . error ( "-> When using npm: npm install webpack-cli -D" ) ;
1955 console . error ( "-> When using yarn: yarn add webpack-cli -D" ) ;
2056 process . exitCode = 1 ;
Original file line number Diff line number Diff line change 4141 "file-loader" : " ^1.1.6" ,
4242 "glob" : " ^7.1.2" ,
4343 "i18n-webpack-plugin" : " ^1.0.0" ,
44+ "inquire" : " ^0.4.8" ,
4445 "istanbul" : " ^0.4.5" ,
4546 "jade" : " ^1.11.0" ,
4647 "jade-loader" : " ~0.8.0" ,
You can’t perform that action at this time.
0 commit comments