Skip to content

Commit b02070d

Browse files
committed
chore(rebase): refactor stuff
1 parent 2b3035c commit b02070d

File tree

125 files changed

+19295
-6988
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+19295
-6988
lines changed

bin/prompt-command.js

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,34 @@
11
// based on https://github.com/webpack/webpack/blob/master/bin/webpack.js
2-
module.exports = function promptForInstallation(packages, ...args) {
32

3+
/**
4+
* @param {string} command process to run
5+
* @param {string[]} args commandline arguments
6+
* @returns {Promise<void>} promise
7+
*/
8+
const runCommand = (command, args) => {
9+
const cp = require("child_process");
10+
return new Promise((resolve, reject) => {
11+
resolve();
12+
const executedCommand = cp.spawn(command, args, {
13+
stdio: "inherit",
14+
shell: true
15+
});
16+
17+
executedCommand.on("error", error => {
18+
reject(error);
19+
});
20+
21+
executedCommand.on("exit", code => {
22+
if (code === 0) {
23+
resolve();
24+
} else {
25+
reject();
26+
}
27+
});
28+
});
29+
};
30+
31+
module.exports = function promptForInstallation(packages, ...args) {
432
let packageIsInstalled = false;
533
try {
634
require.resolve(packages);
@@ -16,7 +44,8 @@ module.exports = function promptForInstallation(packages, ...args) {
1644
const isYarn = fs.existsSync(path.resolve(process.cwd(), "yarn.lock"));
1745

1846
const packageManager = isYarn ? "yarn" : "npm";
19-
const options = ["install", "-D", packages];
47+
const nameOfPackage = "@webpack-cli/" + packages;
48+
const options = ["install", "-D", nameOfPackage];
2049

2150
if (isYarn) {
2251
options[0] = "add";
@@ -26,7 +55,9 @@ module.exports = function promptForInstallation(packages, ...args) {
2655

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

29-
console.error(`The command moved into a separate package: @webpack-cli/${packages}`);
58+
console.error(
59+
`The command moved into a separate package: ${nameOfPackage}`
60+
);
3061
const questionInterface = readLine.createInterface({
3162
input: process.stdin,
3263
output: process.stdout
@@ -40,6 +71,9 @@ module.exports = function promptForInstallation(packages, ...args) {
4071
//eslint-disable-next-line
4172
runCommand(packageManager, options)
4273
.then(result => {
74+
if (packages === "serve") {
75+
return require(`@webpack-cli/${packages}`).serve();
76+
}
4377
return require(`@webpack-cli/${packages}`)(...args); //eslint-disable-line
4478
})
4579
.catch(error => {
@@ -50,7 +84,7 @@ module.exports = function promptForInstallation(packages, ...args) {
5084
}
5185
default: {
5286
console.error(
53-
"It needs to be installed alongside webpack CLI to use the command"
87+
`${nameOfPackage} needs to be installed in order to run the command.`
5488
);
5589
process.exitCode = 1;
5690
break;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
],
2727
"scripts": {
2828
"lint": "eslint ./bin/*.js ./packages/**/*.js ./test/**/*.js",
29-
"format": "prettier-eslint ./utils/**/*.js ./cli.js ./test/**/*.js ./packages/**/*.js --write",
29+
"format": "prettier-eslint ./bin/*.js ./test/**/*.js ./packages/**/*.js --write",
3030
"lint:codeOnly": "eslint \"{utils}/**/!(__testfixtures__)/*.js\" \"{utils}/**.js\"",
3131
"precommit": "lint-staged",
3232
"pretest": "npm run lint",

0 commit comments

Comments
 (0)