-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.js
58 lines (49 loc) · 1.29 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var _ = require("lodash");
var util = require("util");
var inquirer = require("inquirer");
var ScreenManager = require('inquirer/lib/utils/screen-manager');
var Base = require("inquirer/lib/prompts/base");
module.exports = Prompt;
function Prompt(question, rl, answers) {
// Set defaults prompt options
this.screen = new ScreenManager(rl);
this.opt = _.defaults(_.clone(question), {
validate: function () {
return true;
},
filter: function (val) {
return val;
},
when: function () {
return true;
}
});
this.responses = [];
return this;
}
util.inherits(Prompt, Base);
Prompt.prototype.askForLoop = function () {
var ui = inquirer.prompt({
default: true,
type: 'confirm',
name: 'loop',
message: (typeof this.opt.message === 'function' ? this.opt.message() : this.opt.message) || 'Would you like to loop ?'
}).then(function (result) {
if (result.loop) {
this.askNestedQuestion();
} else {
this.done(this.responses);
}
}.bind(this));
}
Prompt.prototype.askNestedQuestion = function () {
inquirer.prompt(this.opt.prompts).then(function (result) {
this.responses.push(result);
this.askForLoop();
}.bind(this));
}
Prompt.prototype._run = function (cb) {
this.done = cb;
this.askForLoop();
return this;
};