Skip to content

Commit 5f357c9

Browse files
committed
cli(prompt): wip
1 parent f8a71c0 commit 5f357c9

File tree

1 file changed

+7
-26
lines changed

1 file changed

+7
-26
lines changed

bin/prompt-command.js

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,5 @@
11
// based on https://github.com/webpack/webpack/blob/master/bin/webpack.js
2-
module.exports = function promptForInstallation(command, options) {
3-
const cp = require("child_process");
4-
return new Promise((resolve, reject) => {
5-
const executedCommand = cp.spawn(command, options, {
6-
stdio: "inherit",
7-
shell: true
8-
});
9-
10-
executedCommand.on("error", error => {
11-
reject(error);
12-
});
13-
14-
executedCommand.on("exit", code => {
15-
if (code === 0) {
16-
resolve(true);
17-
} else {
18-
reject();
19-
}
20-
});
21-
});
22-
}
2+
module.exports = function promptForInstallation(package, ...args) {
233

244
let packageIsInstalled = false;
255
try {
@@ -44,9 +24,9 @@ if (!packageIsInstalled) {
4424

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

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

49-
console.error(`The CLI moved into a separate package: @webpack-cli/${package}`);
29+
console.error(`The command moved into a separate package: @webpack-cli/${package}`);
5030
const questionInterface = readLine.createInterface({
5131
input: process.stdin,
5232
output: process.stdout
@@ -59,7 +39,7 @@ if (!packageIsInstalled) {
5939
case "1": {
6040
runCommand(packageManager, options)
6141
.then(result => {
62-
return require(`@webpack-cli/${package}`); //eslint-disable-line
42+
return require(`@webpack-cli/${package}`)(...args); //eslint-disable-line
6343
})
6444
.catch(error => {
6545
console.error(error);
@@ -69,13 +49,14 @@ if (!packageIsInstalled) {
6949
}
7050
default: {
7151
console.error(
72-
"It needs to be installed alongside webpack to use the CLI"
52+
"It needs to be installed alongside webpack CLI to use the command"
7353
);
7454
process.exitCode = 1;
7555
break;
7656
}
7757
}
7858
});
7959
} else {
80-
require(package); // eslint-disable-line
60+
require(package)(...args); // eslint-disable-line
61+
}
8162
}

0 commit comments

Comments
 (0)