From 4b130bb97cfb3d5a6cf7d1bc122e25efa569c27a Mon Sep 17 00:00:00 2001 From: Rishabh Chawla Date: Mon, 16 Jul 2018 12:39:15 +0530 Subject: [PATCH 1/6] docs: init documentaion Add setup walk through and add usage description --- INIT.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/INIT.md b/INIT.md index c4536c55f3d..82ebf110a3d 100644 --- a/INIT.md +++ b/INIT.md @@ -6,13 +6,13 @@ A. **Local setup** Follow given steps to locally setup `webpack-cli init` by installing dependencies: -1. Create `package.json` through npm +1. Create `package.json` through npm. ```shell $ npm init ``` -2. Install `webpack` and `webpack-cli` as devDependencies +2. Install `webpack` and `webpack-cli` as devDependencies. ```shell $ npm install --save-dev webpack webpack-cli @@ -27,7 +27,7 @@ Follow given steps to locally setup `webpack-cli init` by installing dependencie B. **Global Setup** Follow following steps to setup `webpack-cli init` globally: -1. Install `webpack` and `webpack-cli` globally +1. Install `webpack` and `webpack-cli` globally. ```shell $ npm install -g webpack webpack-cli ``` From 1cab3cbc92234748b3e2f20d70f09d20212561f1 Mon Sep 17 00:00:00 2001 From: Rishabh Chawla Date: Fri, 25 Jan 2019 20:27:07 +0530 Subject: [PATCH 2/6] fix(init): update prompt command --- bin/prompt-command.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/bin/prompt-command.js b/bin/prompt-command.js index bd38d320cfe..09a941950b5 100644 --- a/bin/prompt-command.js +++ b/bin/prompt-command.js @@ -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 @@ -87,11 +86,20 @@ module.exports = function promptForInstallation(packages, ...args) { //eslint-disable-next-line runCommand(packageManager, options) .then(result => { - pathForCmd = path.resolve(process.cwd(), "node_modules", "@webpack-cli", packages); - if (packages === "serve") { - return require(pathForCmd).default.serve(); + if (packages === "init") { + runCommand("webpack-cli", ["init"]) + .then(_=>{}) + .catch(err => { + console.error(err); + process.exitCode = 1; + }); + } else { + pathForCmd = path.resolve(process.cwd(), "node_modules", "@webpack-cli", packages); + if (packages === "serve") { + return require(pathForCmd).default.serve(); + } + return require(pathForCmd).default(...args); //eslint-disable-line } - return require(pathForCmd).default(...args); //eslint-disable-line }) .catch(error => { console.error(error); From c1c07396cd4969de12b771b6139886c754b24e5f Mon Sep 17 00:00:00 2001 From: Rishabh Chawla Date: Fri, 25 Jan 2019 20:36:07 +0530 Subject: [PATCH 3/6] fix(init): update prompt command --- INIT.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/INIT.md b/INIT.md index 82ebf110a3d..c4536c55f3d 100644 --- a/INIT.md +++ b/INIT.md @@ -6,13 +6,13 @@ A. **Local setup** Follow given steps to locally setup `webpack-cli init` by installing dependencies: -1. Create `package.json` through npm. +1. Create `package.json` through npm ```shell $ npm init ``` -2. Install `webpack` and `webpack-cli` as devDependencies. +2. Install `webpack` and `webpack-cli` as devDependencies ```shell $ npm install --save-dev webpack webpack-cli @@ -27,7 +27,7 @@ Follow given steps to locally setup `webpack-cli init` by installing dependencie B. **Global Setup** Follow following steps to setup `webpack-cli init` globally: -1. Install `webpack` and `webpack-cli` globally. +1. Install `webpack` and `webpack-cli` globally ```shell $ npm install -g webpack webpack-cli ``` From 48b3b23237bcc7890afc3c27cfc4b0fc6b3574db Mon Sep 17 00:00:00 2001 From: Rishabh Chawla Date: Wed, 6 Feb 2019 09:09:36 +0530 Subject: [PATCH 4/6] fix(init): revert to local installation --- bin/prompt-command.js | 30 ++++++------------------------ 1 file changed, 6 insertions(+), 24 deletions(-) diff --git a/bin/prompt-command.js b/bin/prompt-command.js index 09a941950b5..a657fa3ff46 100644 --- a/bin/prompt-command.js +++ b/bin/prompt-command.js @@ -59,15 +59,6 @@ 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)`; @@ -83,23 +74,14 @@ module.exports = function promptForInstallation(packages, ...args) { case "y": case "yes": case "1": { - //eslint-disable-next-line + runCommand(packageManager, options) - .then(result => { - if (packages === "init") { - runCommand("webpack-cli", ["init"]) - .then(_=>{}) - .catch(err => { - console.error(err); - process.exitCode = 1; - }); - } else { - pathForCmd = path.resolve(process.cwd(), "node_modules", "@webpack-cli", packages); - if (packages === "serve") { - return require(pathForCmd).default.serve(); - } - return require(pathForCmd).default(...args); //eslint-disable-line + .then(_=> { + pathForCmd = path.resolve(process.cwd(), "node_modules", "@webpack-cli", packages); + if (packages === "serve") { + return require(pathForCmd).default.serve(); } + return require(pathForCmd).default(...args); //eslint-disable-line }) .catch(error => { console.error(error); From 1cb0166b19c438e64fe186c7fafb834edb97f050 Mon Sep 17 00:00:00 2001 From: rishabh3112 Date: Tue, 5 Mar 2019 13:21:51 +0530 Subject: [PATCH 5/6] fix(init): support global installation --- bin/prompt-command.js | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/bin/prompt-command.js b/bin/prompt-command.js index a657fa3ff46..2d810acbdf5 100644 --- a/bin/prompt-command.js +++ b/bin/prompt-command.js @@ -27,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; @@ -59,9 +69,18 @@ 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)`; + 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({ @@ -77,6 +96,22 @@ module.exports = function promptForInstallation(packages, ...args) { runCommand(packageManager, options) .then(_=> { + if (packages == "init") { + npmGlobalRoot() + .then((root) => { + 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(); From 20aab48f61a239437e697c832bd515e3acfb643f Mon Sep 17 00:00:00 2001 From: rishabh3112 Date: Sat, 9 Mar 2019 14:09:07 +0530 Subject: [PATCH 6/6] fix(init): lint code --- bin/prompt-command.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/bin/prompt-command.js b/bin/prompt-command.js index 2d810acbdf5..021fa90527b 100644 --- a/bin/prompt-command.js +++ b/bin/prompt-command.js @@ -31,11 +31,11 @@ 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)); - }) -} + 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; @@ -69,7 +69,7 @@ module.exports = function promptForInstallation(packages, ...args) { options[0] = "add"; } - if (packages == 'init') { + if (packages === "init") { if (isYarn) { options.splice(1, 1); // remove '-D' options.splice(0, 0, "global"); @@ -96,10 +96,10 @@ module.exports = function promptForInstallation(packages, ...args) { runCommand(packageManager, options) .then(_=> { - if (packages == "init") { + if (packages === "init") { npmGlobalRoot() .then((root) => { - pathtoInit = path.resolve(root.trim(), "@webpack-cli", "init"); + const pathtoInit = path.resolve(root.trim(), "@webpack-cli", "init"); return pathtoInit; }) .then((pathForInit) => { @@ -108,7 +108,7 @@ module.exports = function promptForInstallation(packages, ...args) { .catch((error) => { console.error(error); process.exitCode = 1; - }) + }); return; }