From 74fb7593ad21a9daadecafcb2d086a01087d5fa0 Mon Sep 17 00:00:00 2001 From: Sendil Kumar Date: Tue, 15 May 2018 10:20:57 +0200 Subject: [PATCH] fix(monorepo): fix lint errors --- bin/cli.js | 2 +- bin/prompt-command.js | 107 +++++++++++++++++++++--------------------- 2 files changed, 55 insertions(+), 54 deletions(-) diff --git a/bin/cli.js b/bin/cli.js index 97d248287dc..757a8220cd8 100755 --- a/bin/cli.js +++ b/bin/cli.js @@ -41,7 +41,7 @@ }); if (NON_COMPILATION_CMD) { - return require('./prompt-command')(NON_COMPILATION_CMD, ...process.argv); + return require("./prompt-command")(NON_COMPILATION_CMD, ...process.argv); } const yargs = require("yargs").usage(`webpack-cli ${ diff --git a/bin/prompt-command.js b/bin/prompt-command.js index d5787d09f5b..9916183acb1 100644 --- a/bin/prompt-command.js +++ b/bin/prompt-command.js @@ -1,62 +1,63 @@ // based on https://github.com/webpack/webpack/blob/master/bin/webpack.js -module.exports = function promptForInstallation(package, ...args) { +module.exports = function promptForInstallation(packages, ...args) { -let packageIsInstalled = false; -try { - require.resolve(package); - packageIsInstalled = true; -} catch (err) { - packageIsInstalled = false; -} + let packageIsInstalled = false; + try { + require.resolve(packages); + packageIsInstalled = true; + } catch (err) { + packageIsInstalled = false; + } -if (!packageIsInstalled) { - const path = require("path"); - const fs = require("fs"); - const readLine = require("readline"); - const isYarn = fs.existsSync(path.resolve(process.cwd(), "yarn.lock")); + if (!packageIsInstalled) { + const path = require("path"); + const fs = require("fs"); + const readLine = require("readline"); + const isYarn = fs.existsSync(path.resolve(process.cwd(), "yarn.lock")); - const packageManager = isYarn ? "yarn" : "npm"; - const options = ["install", "-D", package]; + const packageManager = isYarn ? "yarn" : "npm"; + const options = ["install", "-D", packages]; - if (isYarn) { - options[0] = "add"; - } + if (isYarn) { + options[0] = "add"; + } - const commandToBeRun = `${packageManager} ${options.join(" ")}`; + const commandToBeRun = `${packageManager} ${options.join(" ")}`; - const question = `Would you like to install ${package}? (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: @webpack-cli/${package}`); - const questionInterface = readLine.createInterface({ - input: process.stdin, - output: process.stdout - }); - questionInterface.question(question, answer => { - questionInterface.close(); - switch (answer.toLowerCase()) { - case "y": - case "yes": - case "1": { - runCommand(packageManager, options) - .then(result => { - return require(`@webpack-cli/${package}`)(...args); //eslint-disable-line - }) - .catch(error => { - console.error(error); - process.exitCode = 1; - }); - break; + console.error(`The command moved into a separate package: @webpack-cli/${packages}`); + const questionInterface = readLine.createInterface({ + input: process.stdin, + output: process.stdout + }); + questionInterface.question(question, answer => { + questionInterface.close(); + switch (answer.toLowerCase()) { + case "y": + case "yes": + case "1": { + //eslint-disable-next-line + runCommand(packageManager, options) + .then(result => { + return require(`@webpack-cli/${packages}`)(...args); //eslint-disable-line + }) + .catch(error => { + console.error(error); + process.exitCode = 1; + }); + break; + } + default: { + console.error( + "It needs to be installed alongside webpack CLI to use the command" + ); + process.exitCode = 1; + break; + } } - default: { - console.error( - "It needs to be installed alongside webpack CLI to use the command" - ); - process.exitCode = 1; - break; - } - } - }); -} else { - require(package)(...args); // eslint-disable-line -} -} \ No newline at end of file + }); + } else { + require(packages)(...args); // eslint-disable-line + } +};