-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
49 lines (40 loc) · 1.19 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
'use strict';
var inquirer = require('inquirer-bluebird');
var Promise = require('bluebird');
module.exports = function(appName) {
var config = require('dot-file-config')(appName);
return {
config: config,
run: function(questions) {
var unknown = questions.filter(function(question) {
return typeof config.data[question.name] === 'undefined';
});
if (unknown.length === 0) {
return Promise.resolve(config);
}
return Promise
.reduce(unknown, function(result, question) {
if (question.hint) {
console.log(question.hint);
}
if (question.env && process.env[question.env]) {
config.data[question.name] = process.env[question.env];
return true;
}
question.message = question.name;
return inquirer
.prompt(question)
.then(function(answers) {
Object.keys(answers).forEach(function(name) {
config.data[name] = answers[name];
});
config.save();
return true;
});
}, 0)
.then(function() {
return config;
});
}
};
};