Skip to content

Commit

Permalink
Merge pull request #630 from manu-chroma/init_fix
Browse files Browse the repository at this point in the history
feat: install init as global dep
  • Loading branch information
evenstensberg authored Nov 4, 2018
2 parents 4b9df8d + 1261e67 commit d8a121a
Show file tree
Hide file tree
Showing 3 changed files with 2,700 additions and 1,581 deletions.
25 changes: 23 additions & 2 deletions bin/prompt-command.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,20 @@ module.exports = function promptForInstallation(packages, ...args) {
let pathForCmd;
try {
const path = require("path");
pathForCmd = path.resolve(process.cwd(), "node_modules", "@webpack-cli", packages);
require.resolve(pathForCmd);
const fs = require("fs");
pathForCmd = path.resolve(
process.cwd(),
"node_modules",
"@webpack-cli",
packages
);
if (!fs.existsSync(pathForCmd)) {
const globalModules = require("global-modules");
pathForCmd = globalModules + "/@webpack-cli/" + packages;
require.resolve(pathForCmd);
} else {
require.resolve(pathForCmd);
}
packageIsInstalled = true;
} catch (err) {
packageIsInstalled = false;
Expand All @@ -53,6 +65,15 @@ module.exports = function promptForInstallation(packages, ...args) {
options[0] = "add";
}

if (packages === "init") {
if (isYarn) {
options.splice(1, 1); // remove '-D'
options.splice(0, 0, "global");
} else {
options[1] = "-g";
}
}

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

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

0 comments on commit d8a121a

Please sign in to comment.