Skip to content

Commit

Permalink
cli(prompt): wip
Browse files Browse the repository at this point in the history
  • Loading branch information
evenstensberg committed May 14, 2018
1 parent f8a71c0 commit 5f357c9
Showing 1 changed file with 7 additions and 26 deletions.
33 changes: 7 additions & 26 deletions bin/prompt-command.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,5 @@
// based on https://github.com/webpack/webpack/blob/master/bin/webpack.js
module.exports = function promptForInstallation(command, options) {
const cp = require("child_process");
return new Promise((resolve, reject) => {
const executedCommand = cp.spawn(command, options, {
stdio: "inherit",
shell: true
});

executedCommand.on("error", error => {
reject(error);
});

executedCommand.on("exit", code => {
if (code === 0) {
resolve(true);
} else {
reject();
}
});
});
}
module.exports = function promptForInstallation(package, ...args) {

let packageIsInstalled = false;
try {
Expand All @@ -44,9 +24,9 @@ if (!packageIsInstalled) {

const commandToBeRun = `${packageManager} ${options.join(" ")}`;

const question = `Would you like to install ${packageIsInstalled}? (That will run ${commandToBeRun}) (yes/NO)`;
const question = `Would you like to install ${package}? (That will run ${commandToBeRun}) (yes/NO)`;

console.error(`The CLI moved into a separate package: @webpack-cli/${package}`);
console.error(`The command moved into a separate package: @webpack-cli/${package}`);
const questionInterface = readLine.createInterface({
input: process.stdin,
output: process.stdout
Expand All @@ -59,7 +39,7 @@ if (!packageIsInstalled) {
case "1": {
runCommand(packageManager, options)
.then(result => {
return require(`@webpack-cli/${package}`); //eslint-disable-line
return require(`@webpack-cli/${package}`)(...args); //eslint-disable-line
})
.catch(error => {
console.error(error);
Expand All @@ -69,13 +49,14 @@ if (!packageIsInstalled) {
}
default: {
console.error(
"It needs to be installed alongside webpack to use the CLI"
"It needs to be installed alongside webpack CLI to use the command"
);
process.exitCode = 1;
break;
}
}
});
} else {
require(package); // eslint-disable-line
require(package)(...args); // eslint-disable-line
}
}

0 comments on commit 5f357c9

Please sign in to comment.