Skip to content
This repository has been archived by the owner on Sep 11, 2021. It is now read-only.

Commit

Permalink
🔧 Use Promises with Inquirer
Browse files Browse the repository at this point in the history
  • Loading branch information
felixrieseberg committed May 19, 2016
1 parent b9d33c2 commit 3508cc9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 32 deletions.
26 changes: 12 additions & 14 deletions lib/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
}

Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down
26 changes: 12 additions & 14 deletions src/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
});
}

Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 3508cc9

Please sign in to comment.