Skip to content

Commit 58b6724

Browse files
matheus1lvasokra
authored andcommitted
Refactor to scope command detection inside question
1 parent 67651ae commit 58b6724

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

‎bin/webpack.js‎

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
#!/usr/bin/env node
22

3-
const {
4-
exec
5-
} = require("child_process");
3+
const cp = require("child_process");
64
const inquirer = require("inquirer");
75

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

33-
let command;
34-
35-
if(isYarn) {
36-
command = "yarn add -D webpack-cli";
37-
} else {
38-
command = "npm install --save-dev webpack-cli";
39-
}
40-
4131
const question = {
4232
type: "confirm",
4333
name: "shouldInstall",
@@ -49,6 +39,14 @@ if(!webpackCliInstalled) {
4939
inquirer.prompt(question).then((answer) => {
5040
if(answer) {
5141
console.error("Installing webpack-cli");
42+
43+
let command;
44+
if(isYarn) {
45+
command = "yarn add -D webpack-cli";
46+
} else {
47+
command = "npm install --save-dev webpack-cli";
48+
}
49+
5250
if(runCommand(command)) {
5351
require("webpack-cli"); // eslint-disable-line node/no-missing-require, node/no-extraneous-require, node/no-unpublished-require
5452
}

0 commit comments

Comments
 (0)