From 3508cc95bb55c30b2c578989c317b98d2af853c3 Mon Sep 17 00:00:00 2001 From: Felix Rieseberg Date: Thu, 19 May 2016 10:21:59 +0200 Subject: [PATCH] :wrench: Use Promises with Inquirer --- lib/upgrade.js | 26 ++++++++++++-------------- package.json | 8 ++++---- src/upgrade.js | 26 ++++++++++++-------------- 3 files changed, 28 insertions(+), 32 deletions(-) diff --git a/lib/upgrade.js b/lib/upgrade.js index def67f9..3132091 100644 --- a/lib/upgrade.js +++ b/lib/upgrade.js @@ -77,19 +77,17 @@ function displayHelp() { * Asks the user for confirmation whether or not he/she wants to upgrade */ function askForConfirmation() { - return new TPromise(function (resolve) { - inquirer.prompt({ - type: 'confirm', - name: 'c', - message: 'This tool will upgrade npm. Do you want to continue?' - }, function (response) { - if (!response.c) { - console.log(chalk.bold.green('Well then, we\'re done here. Have a nice day!')); - resolve(false); - } else { - resolve(true); - } - }); + return inquirer.prompt({ + type: 'confirm', + name: 'c', + message: 'This tool will upgrade npm. Do you want to continue?' + }).then(function (response) { + if (!response.c) { + console.log(chalk.bold.green('Well then, we\'re done here. Have a nice day!')); + return false; + } else { + return true; + } }); } @@ -393,7 +391,7 @@ function prepareUpgrade(_program) { debug('Upgrade: Got npm version list, now asking user for selection'); - inquirer.prompt(versionList, function (answer) { + inquirer.prompt(versionList).then(function (answer) { return upgrade(answer.version, program.npmPath); }); _context5.next = 53; diff --git a/package.json b/package.json index ebbf8e6..fa9f5a8 100644 --- a/package.json +++ b/package.json @@ -54,11 +54,11 @@ "load-grunt-tasks": "^3.4.0" }, "dependencies": { - "chalk": "~1.1.3", - "cli-spinner": "~0.2.5", + "chalk": "~1.1.0", + "cli-spinner": "~0.2.0", "commander": "~2.9.0", - "inquirer": "~1.0.2", - "promise": "~7.1.1", + "inquirer": "~1.0.0", + "promise": "~7.1.0", "prompt": "~1.0.0", "regenerator-runtime-only": "~0.8.38" } diff --git a/src/upgrade.js b/src/upgrade.js index d3af01e..78524cc 100644 --- a/src/upgrade.js +++ b/src/upgrade.js @@ -73,19 +73,17 @@ function displayHelp() { * Asks the user for confirmation whether or not he/she wants to upgrade */ function askForConfirmation() { - return new TPromise((resolve) => { - inquirer.prompt({ - type: 'confirm', - name: 'c', - message: 'This tool will upgrade npm. Do you want to continue?' - }, (response) => { - if (!response.c) { - console.log(chalk.bold.green('Well then, we\'re done here. Have a nice day!')); - resolve(false); - } else { - resolve(true); - } - }); + return inquirer.prompt({ + type: 'confirm', + name: 'c', + message: 'This tool will upgrade npm. Do you want to continue?' + }).then(response => { + if (!response.c) { + console.log(chalk.bold.green('Well then, we\'re done here. Have a nice day!')); + return false; + } else { + return true; + } }); } @@ -256,7 +254,7 @@ async function prepareUpgrade(_program) { }]; debug('Upgrade: Got npm version list, now asking user for selection'); - inquirer.prompt(versionList, (answer) => upgrade(answer.version, program.npmPath)); + inquirer.prompt(versionList).then(answer => upgrade(answer.version, program.npmPath)); } else if (program.npmVersion === 'latest') { // If the version is "latest", let's find out what that is const latest = await versions.getLatestNPMVersion();