Skip to content

Commit

Permalink
Merge pull request #742 from rishabh3112/fix/init
Browse files Browse the repository at this point in the history
fix(init): fix init prompt installation
  • Loading branch information
evenstensberg committed Mar 10, 2019
2 parents e2c9dd7 + 20aab48 commit 6aec4c3
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions bin/prompt-command.js
Expand Up @@ -8,7 +8,6 @@
const runCommand = (command, args) => {
const cp = require("child_process");
return new Promise((resolve, reject) => {
resolve();
const executedCommand = cp.spawn(command, args, {
stdio: "inherit",
shell: true
Expand All @@ -28,6 +27,16 @@ const runCommand = (command, args) => {
});
};

const npmGlobalRoot = () => {
const cp = require("child_process");
return new Promise((resolve, reject) => {
const command = cp.spawn("npm", ["root", "-g"]);
command.on("error", (error) => reject(error));
command.stdout.on("data", (data) => resolve(data.toString()));
command.stderr.on("data", (data) => reject(data));
});
};

module.exports = function promptForInstallation(packages, ...args) {
const nameOfPackage = "@webpack-cli/" + packages;
let packageIsInstalled = false;
Expand Down Expand Up @@ -71,7 +80,7 @@ module.exports = function promptForInstallation(packages, ...args) {

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

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

console.error(`The command moved into a separate package: ${nameOfPackage}`);
const questionInterface = readLine.createInterface({
Expand All @@ -84,9 +93,25 @@ module.exports = function promptForInstallation(packages, ...args) {
case "y":
case "yes":
case "1": {
//eslint-disable-next-line

runCommand(packageManager, options)
.then(result => {
.then(_=> {
if (packages === "init") {
npmGlobalRoot()
.then((root) => {
const pathtoInit = path.resolve(root.trim(), "@webpack-cli", "init");
return pathtoInit;
})
.then((pathForInit) => {
return require(pathForInit).default(...args);
})
.catch((error) => {
console.error(error);
process.exitCode = 1;
});
return;
}

pathForCmd = path.resolve(process.cwd(), "node_modules", "@webpack-cli", packages);
if (packages === "serve") {
return require(pathForCmd).default.serve();
Expand Down

0 comments on commit 6aec4c3

Please sign in to comment.