Skip to content

Commit 846fd3c

Browse files
authored
Bump inquirer (#429)
1 parent 3be725b commit 846fd3c

12 files changed

+197
-188
lines changed

lib/routes/clear-config.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ module.exports = function (app) {
4848
});
4949
}
5050

51-
inquirer.prompt([{
51+
return inquirer.prompt([{
5252
name: 'whatNext',
5353
type: 'list',
5454
message: 'Which store would you like to clear?',
5555
choices: _.flatten([
5656
generatorList,
5757
defaultChoices
5858
])
59-
}], function (answer) {
59+
}]).then(function (answer) {
6060
app.insight.track('yoyo', 'clearGlobalConfig', answer);
6161

6262
if (answer.whatNext === 'home') {

lib/routes/help.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ var opn = require('opn');
55
module.exports = function (app) {
66
app.insight.track('yoyo', 'help');
77

8-
inquirer.prompt([{
8+
return inquirer.prompt([{
99
name: 'whereTo',
1010
type: 'list',
1111
message: 'Here are a few helpful resources.\n' +
@@ -23,7 +23,7 @@ module.exports = function (app) {
2323
name: 'Take me back home, Yo!',
2424
value: 'home'
2525
}]
26-
}], function (answer) {
26+
}]).then(function (answer) {
2727
app.insight.track('yoyo', 'help', answer);
2828

2929
if (answer.whereTo === 'home') {

lib/routes/home.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ module.exports = function (app) {
5353

5454
app.insight.track('yoyo', 'home');
5555

56-
fullname().then(function (name) {
56+
return fullname().then(function (name) {
5757
var allo = name ? '\'Allo ' + name.split(' ')[0] + '! ' : '\'Allo! ';
5858

59-
inquirer.prompt([{
59+
return inquirer.prompt([{
6060
name: 'whatNext',
6161
type: 'list',
6262
message: allo + 'What would you like to do?',
@@ -67,7 +67,7 @@ module.exports = function (app) {
6767
defaultChoices,
6868
new inquirer.Separator()
6969
])
70-
}], function (answer) {
70+
}]).then(function (answer) {
7171
if (answer.whatNext.method === 'run') {
7272
app.navigate('run', answer.whatNext.generator);
7373
return;

lib/routes/install.js

Lines changed: 32 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
'use strict';
2+
var _ = require('lodash');
23
var async = require('async');
34
var chalk = require('chalk');
45
var inquirer = require('inquirer');
56
var spawn = require('cross-spawn');
7+
var Promise = require('pinkie-promise');
68
var sortOn = require('sort-on');
79
var figures = require('figures');
810
var npmKeyword = require('npm-keyword');
@@ -32,49 +34,28 @@ var OFFICIAL_GENERATORS = [
3234
module.exports = function (app) {
3335
app.insight.track('yoyo', 'install');
3436

35-
inquirer.prompt([{
37+
return inquirer.prompt([{
3638
name: 'searchTerm',
3739
message: 'Search npm for generators:'
38-
}], function (answers) {
39-
searchNpm(app, answers.searchTerm, function (err) {
40-
if (err) {
41-
throw err;
42-
}
43-
});
40+
}]).then(function (answers) {
41+
return searchNpm(app, answers.searchTerm);
4442
});
4543
};
4644

47-
var getAllGenerators = (function () {
48-
var allGenerators;
49-
50-
return function (cb) {
51-
if (allGenerators) {
52-
return cb(null, allGenerators);
53-
}
54-
55-
npmKeyword('yeoman-generator').then(function (packages) {
56-
cb(null, packages.map(function (el) {
57-
el.match = function (term) {
58-
return (el.name + ' ' + el.description).indexOf(term) >= 0;
59-
};
45+
function generatorMatchTerm(generator, term) {
46+
return (generator.name + ' ' + generator.description).indexOf(term) >= 0;
47+
}
6048

61-
return el;
62-
}));
63-
}).catch(cb);
64-
};
65-
})();
49+
var getAllGenerators = _.memoize(function () {
50+
return npmKeyword('yeoman-generator');
51+
});
6652

6753
function searchMatchingGenerators(app, term, cb) {
6854
got('yeoman.io/blacklist.json', {json: true}, function (err, data) {
6955
var blacklist = err ? [] : data;
7056
var installedGenerators = app.env.getGeneratorNames();
7157

72-
getAllGenerators(function (err2, allGenerators) {
73-
if (err2) {
74-
cb(err2);
75-
return;
76-
}
77-
58+
getAllGenerators().then(function (allGenerators) {
7859
cb(null, allGenerators.filter(function (generator) {
7960
if (blacklist.indexOf(generator.name) !== -1) {
8061
return false;
@@ -84,9 +65,9 @@ function searchMatchingGenerators(app, term, cb) {
8465
return false;
8566
}
8667

87-
return generator.match(term);
68+
return generatorMatchTerm(generator, term);
8869
}));
89-
});
70+
}, cb);
9071
});
9172
}
9273

@@ -105,23 +86,28 @@ function fetchGeneratorInfo(generator, cb) {
10586
}).catch(cb);
10687
}
10788

108-
function searchNpm(app, term, cb) {
109-
searchMatchingGenerators(app, term, function (err, matches) {
110-
if (err) {
111-
cb(err);
112-
return;
113-
}
114-
115-
async.map(matches, fetchGeneratorInfo, function (err2, choices) {
116-
if (err2) {
117-
cb(err2);
89+
function searchNpm(app, term) {
90+
var promise = new Promise(function (resolve, reject) {
91+
searchMatchingGenerators(app, term, function (err, matches) {
92+
if (err) {
93+
reject(err);
11894
return;
11995
}
12096

121-
promptInstallOptions(app, sortOn(choices, ['official', 'name']));
122-
cb();
97+
async.map(matches, fetchGeneratorInfo, function (err2, choices) {
98+
if (err2) {
99+
reject(err2);
100+
return;
101+
}
102+
103+
resolve(choices);
104+
});
123105
});
124106
});
107+
108+
return promise.then(function (choices) {
109+
return promptInstallOptions(app, sortOn(choices, ['official', 'name']));
110+
});
125111
}
126112

127113
function promptInstallOptions(app, choices) {
@@ -144,7 +130,7 @@ function promptInstallOptions(app, choices) {
144130
}])
145131
}];
146132

147-
inquirer.prompt(resultsPrompt, function (answer) {
133+
return inquirer.prompt(resultsPrompt).then(function (answer) {
148134
if (answer.toInstall === 'home' || answer.toInstall === 'install') {
149135
return app.navigate(answer.toInstall);
150136
}

lib/routes/update.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ function updateGenerators(app, pkgs) {
2323

2424
module.exports = function (app) {
2525
app.insight.track('yoyo', 'update');
26-
inquirer.prompt([{
26+
return inquirer.prompt([{
2727
name: 'generators',
2828
message: 'Generators to update',
2929
type: 'checkbox',
@@ -36,7 +36,7 @@ module.exports = function (app) {
3636
checked: true
3737
};
3838
})
39-
}], function (answer) {
39+
}]).then(function (answer) {
4040
updateGenerators(app, answer.generators);
4141
});
4242
};

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,15 @@
5050
"fullname": "^2.0.0",
5151
"got": "^5.0.0",
5252
"humanize-string": "^1.0.0",
53-
"inquirer": "^0.11.0",
53+
"inquirer": "^1.0.2",
5454
"insight": "^0.7.0",
5555
"lodash": "^3.2.0",
5656
"meow": "^3.0.0",
5757
"npm-keyword": "^4.1.0",
5858
"opn": "^3.0.2",
5959
"package-json": "^2.1.0",
6060
"parse-help": "^0.1.1",
61+
"pinkie-promise": "^2.0.1",
6162
"read-pkg-up": "^1.0.1",
6263
"repeating": "^2.0.0",
6364
"root-check": "^1.0.0",
@@ -77,7 +78,7 @@
7778
"gulp-coveralls": "^0.1.0",
7879
"gulp-eslint": "^2.0.0",
7980
"gulp-exclude-gitignore": "^1.0.0",
80-
"gulp-istanbul": "^0.10.4",
81+
"gulp-istanbul": "^1.0.0",
8182
"gulp-mocha": "^2.0.0",
8283
"gulp-nsp": "^2.1.0",
8384
"gulp-plumber": "^1.0.0",

test/cli.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,16 @@ describe('bin', function () {
5353
});
5454

5555
it('should return the version', function (cb) {
56-
var cp = execFile('node', [path.join(__dirname, '../', pkg.bin.yo), '--version', '--no-insight', '--no-update-notifier']);
56+
var cp = execFile('node', [
57+
path.join(__dirname, '../', pkg.bin.yo),
58+
'--version',
59+
'--no-insight',
60+
'--no-update-notifier'
61+
]);
5762
var expected = pkg.version;
5863

5964
cp.stdout.on('data', function (data) {
60-
assert.equal(data.replace(/\r\n|\n/g, ''), expected);
65+
assert.equal(data.toString().replace(/\r\n|\n/g, ''), expected);
6166
cb();
6267
});
6368
});

test/route-clear-config.js

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var assert = require('assert');
33
var proxyquire = require('proxyquire');
44
var sinon = require('sinon');
55
var _ = require('lodash');
6+
var Promise = require('pinkie-promise');
67
var inquirer = require('inquirer');
78
var Router = require('../lib/router');
89
var helpers = require('./helpers');
@@ -56,56 +57,59 @@ describe('clear config route', function () {
5657
});
5758

5859
it('allow returning home', function () {
59-
this.sandbox.stub(inquirer, 'prompt', function (arg, cb) {
60-
cb({whereTo: 'home'});
61-
});
62-
this.router.navigate('clearConfig');
63-
sinon.assert.calledOnce(this.homeRoute);
60+
this.sandbox.stub(inquirer, 'prompt').returns(Promise.resolve({whatNext: 'home'}));
61+
return this.router.navigate('clearConfig').then(function () {
62+
sinon.assert.calledOnce(this.homeRoute);
63+
}.bind(this));
6464
});
6565

6666
it('track page and answer', function () {
67-
this.sandbox.stub(inquirer, 'prompt', function (arg, cb) {
68-
cb({whatNext: 'generator-angular:0.0.0'});
69-
});
70-
this.router.navigate('clearConfig');
71-
sinon.assert.calledWith(this.insight.track, 'yoyo', 'clearGlobalConfig');
72-
sinon.assert.calledWith(this.insight.track, 'yoyo', 'clearGlobalConfig', {whatNext: 'generator-angular:0.0.0'});
67+
this.sandbox.stub(inquirer, 'prompt').returns(
68+
Promise.resolve({whatNext: 'generator-angular:0.0.0'})
69+
);
70+
return this.router.navigate('clearConfig').then(function () {
71+
sinon.assert.calledWith(this.insight.track, 'yoyo', 'clearGlobalConfig');
72+
sinon.assert.calledWith(
73+
this.insight.track,
74+
'yoyo',
75+
'clearGlobalConfig',
76+
{whatNext: 'generator-angular:0.0.0'}
77+
);
78+
}.bind(this));
7379
});
7480

7581
it('allows clearing a generator and return user to home screen', function () {
76-
this.sandbox.stub(inquirer, 'prompt', function (arg, cb) {
77-
cb({whatNext: 'foo'});
78-
});
79-
this.router.navigate('clearConfig');
80-
sinon.assert.calledOnce(this.globalConfig.remove);
81-
sinon.assert.calledWith(this.globalConfig.remove, 'foo');
82-
sinon.assert.calledOnce(this.homeRoute);
82+
this.sandbox.stub(inquirer, 'prompt').returns(Promise.resolve({whatNext: 'foo'}));
83+
this.router.navigate('clearConfig').then(function () {
84+
sinon.assert.calledOnce(this.globalConfig.remove);
85+
sinon.assert.calledWith(this.globalConfig.remove, 'foo');
86+
sinon.assert.calledOnce(this.homeRoute);
87+
}.bind(this));
8388
});
8489

8590
it('allows clearing all generators and return user to home screen', function () {
86-
this.sandbox.stub(inquirer, 'prompt', function (arg, cb) {
87-
cb({whatNext: '*'});
88-
});
89-
this.router.navigate('clearConfig');
90-
sinon.assert.calledOnce(this.globalConfig.removeAll);
91-
sinon.assert.calledOnce(this.homeRoute);
91+
this.sandbox.stub(inquirer, 'prompt').returns(Promise.resolve({whatNext: '*'}));
92+
return this.router.navigate('clearConfig').then(function () {
93+
sinon.assert.calledOnce(this.globalConfig.removeAll);
94+
sinon.assert.calledOnce(this.homeRoute);
95+
}.bind(this));
9296
});
9397

9498
it('shows generator with global config entry', function () {
9599
var choices = [];
96100

97-
this.sandbox.stub(inquirer, 'prompt', function (arg, cb) {
101+
this.sandbox.stub(inquirer, 'prompt', function (arg) {
98102
choices = arg[0].choices;
99-
cb({whatNext: 'foo'});
103+
return Promise.resolve({whatNext: 'foo'});
100104
});
101-
this.router.navigate('clearConfig');
102-
103-
// Clear all generators entry is present
104-
assert.ok(_.find(choices, {value: '*'}));
105+
return this.router.navigate('clearConfig').then(function () {
106+
// Clear all generators entry is present
107+
assert.ok(_.find(choices, {value: '*'}));
105108

106-
assert.ok(_.find(choices, {value: 'generator-unicorn'}));
107-
assert.ok(_.find(choices, {value: 'generator-phoenix'}));
108-
assert.ok(_.find(choices, {name: 'Unicorn'}));
109-
assert.ok(_.find(choices, {name: 'phoenix\u001b[31m (not installed anymore)\u001b[39m'}));
109+
assert.ok(_.find(choices, {value: 'generator-unicorn'}));
110+
assert.ok(_.find(choices, {value: 'generator-phoenix'}));
111+
assert.ok(_.find(choices, {name: 'Unicorn'}));
112+
assert.ok(_.find(choices, {name: 'phoenix\u001b[31m (not installed anymore)\u001b[39m'}));
113+
});
110114
});
111115
});

0 commit comments

Comments
 (0)