Skip to content

Commit

Permalink
Refactor to scope command detection inside question
Browse files Browse the repository at this point in the history
  • Loading branch information
matheus1lva authored and sokra committed Mar 9, 2018
1 parent 67651ae commit 58b6724
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions bin/webpack.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
#!/usr/bin/env node

const {
exec
} = require("child_process");
const cp = require("child_process");
const inquirer = require("inquirer");

function runCommand(command) {
exec(command, (error, stdout, stderr) => {
cp.exec(command, (error, stdout, stderr) => {
if(!error) {
console.log("webpack-cli installed successfully");
return true;
Expand All @@ -30,14 +28,6 @@ if(!webpackCliInstalled) {
const fs = require("fs");
const isYarn = fs.existsSync(path.resolve(process.cwd(), "yarn.lock"));

let command;

if(isYarn) {
command = "yarn add -D webpack-cli";
} else {
command = "npm install --save-dev webpack-cli";
}

const question = {
type: "confirm",
name: "shouldInstall",
Expand All @@ -49,6 +39,14 @@ if(!webpackCliInstalled) {
inquirer.prompt(question).then((answer) => {
if(answer) {
console.error("Installing webpack-cli");

let command;
if(isYarn) {
command = "yarn add -D webpack-cli";
} else {
command = "npm install --save-dev webpack-cli";
}

if(runCommand(command)) {
require("webpack-cli"); // eslint-disable-line node/no-missing-require, node/no-extraneous-require, node/no-unpublished-require
}
Expand Down

0 comments on commit 58b6724

Please sign in to comment.