2018-02-08 08:28:38 +08:00
|
|
|
const {exec} = require('child_process');
|
|
|
|
|
|
|
|
|
|
|
|
function runCommand(command) {
|
|
|
|
exec(command, (err, data) => {
|
|
|
|
if(data) {
|
|
|
|
console.log(data);
|
|
|
|
} else {
|
|
|
|
console.log(err);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2012-03-10 20:11:23 +08:00
|
|
|
|
2017-12-13 18:30:15 +08:00
|
|
|
let webpackCliInstalled = false;
|
|
|
|
try {
|
|
|
|
require.resolve("webpack-cli");
|
|
|
|
webpackCliInstalled = true;
|
2018-02-25 09:00:20 +08:00
|
|
|
} catch (e) {
|
2017-12-13 18:30:15 +08:00
|
|
|
webpackCliInstalled = false;
|
|
|
|
}
|
|
|
|
|
2018-02-25 09:00:20 +08:00
|
|
|
if (webpackCliInstalled) {
|
2018-01-04 04:06:04 +08:00
|
|
|
require("webpack-cli"); // eslint-disable-line node/no-missing-require, node/no-extraneous-require, node/no-unpublished-require
|
2017-12-13 18:30:15 +08:00
|
|
|
} else {
|
2018-02-08 08:28:38 +08:00
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs');
|
|
|
|
const isYarn = fs.existsSync(path.resolve(process.cwd(), 'yarn.lock'));
|
|
|
|
const {prompt} = require('inquirer');
|
|
|
|
let command;
|
|
|
|
|
|
|
|
|
|
|
|
const question = {
|
|
|
|
type: 'confirm',
|
|
|
|
name: 'shouldInstall',
|
|
|
|
message: 'Would you like to install webpack-cli?',
|
|
|
|
default: true
|
|
|
|
}
|
|
|
|
|
|
|
|
if(isYarn){
|
|
|
|
command = 'yarn add webpack-cli -D';
|
|
|
|
}else{
|
|
|
|
command = 'npm install --save-dev webpack-cli';
|
|
|
|
}
|
|
|
|
|
2017-12-13 18:30:15 +08:00
|
|
|
console.error("The CLI moved into a separate package: webpack-cli.");
|
2018-02-08 08:28:38 +08:00
|
|
|
prompt(question).then((anwswer) => {
|
|
|
|
if(answer){
|
|
|
|
console.error('Installing webpack-cli')
|
|
|
|
runCommand(command);
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
console.error("Please install 'webpack-cli' in addition to webpack itself to use the CLI.");
|
2017-12-13 22:05:12 +08:00
|
|
|
console.error("-> When using npm: npm install webpack-cli -D");
|
|
|
|
console.error("-> When using yarn: yarn add webpack-cli -D");
|
2017-12-13 18:30:15 +08:00
|
|
|
process.exitCode = 1;
|
|
|
|
}
|