/
prompt.js
232 lines (216 loc) · 5.96 KB
/
prompt.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
'use strict';
const slug = require('slug');
slug.defaults.mode = 'rfc3986';
slug.defaults.modes['rfc3986'] = {
replacement: '-', // replace spaces with replacement
symbols: true, // replace unicode symbols or not
remove: null, // (optional) regex to remove characters
lower: true, // result in lower case
charmap: slug.charmap, // replace special characters
multicharmap: slug.multicharmap // replace multi-characters
};
//We need to add sub-prompts for application specifics:
//- node app port
//- node app id
//- node repl port
//- node repl enabled
//Then ask for modules:
//We should pull list from NPM? Or freehand? should each
//plugin bring it's own prompt?
//persistence?
//data-manager
//filesync
//express?
//auth?
let packages = {
'server': 'core.io-express-server',
'authentication': 'core.io-express-auth',
'persistence': 'core.io-persistence',
'filesync': 'core.io-filesync',
'data-manager': 'core.io-data-manager',
};
let questions = [{
type: 'directory',
name: 'target',
message: 'Where you like to put create this project?',
//this should be relative to the application
//we should be able to inject
basePath: './'
},
{
type: 'input',
name: 'nodeVersion',
default: function(answer) {
return process.version;
},
message: 'What node version do you want to use?'
},
{
type: 'input',
name: 'name',
default: function(answer) {
return answer.target;
},
message: 'What\'s the project\'s name?'
},
{
type: 'input',
name: 'moduleName',
default: function(answer) {
return slug(answer.name);
},
message: 'What\'s the module\'s name?'
},
{
type: 'input',
name: 'license',
message: 'What\'s is the license',
default: function() {
//Look into generating a license file:
//https://github.com/Daniel1of1/license
return 'MIT';
}
},
{
type: 'input',
name: 'description',
message: 'Short project description',
default: function() {
return 'Awesome souce';
}
},
{
type: 'confirm',
name: 'versions',
message: 'Do you want to specify package versions? If not we use the latest "*"'
},
{
type: 'confirm',
name: 'server',
message: 'Do you need an express server?'
},
{
type: 'input',
name: 'server-version',
message: 'What version of core.io-express-server?',
default: '*',
when: function(answers) {
return answers.versions && answers.server;
}
},
{
type: 'confirm',
name: 'authentication',
message: 'Do you need authentication support?',
when: function(answers) {
return answers.versions && answers.server;
}
},
{
type: 'input',
name: 'authentication-version',
message: 'What version of core.io-express-auth?',
default: '*',
when: function(answers) {
return answers.versions && answers.authentication;
}
},
{
type: 'confirm',
name: 'persistence',
message: 'Do you need an waterline persistence?'
},
{
type: 'input',
name: 'persistence-version',
message: 'What version of core.io-persistence?',
default: '*',
when: function(answers) {
return answers.versions && answers.persistence;
}
},
{
type: 'confirm',
name: 'data-manager',
message: 'Do you want to integrate data manager?',
when: function(answers) {
return answers.persistence;
}
},
{
type: 'input',
name: 'data-manager-version',
message: 'What version of core.io-data-manager?',
default: '*',
when: function(answers) {
return answers.versions && answers['data-manager'];
}
},
{
type: 'confirm',
name: 'filesync',
message: 'Do you want to update your data store when seed files change?',
when: function(answers) {
return answers['data-manager'] && answers.persistence;
}
},
{
type: 'input',
name: 'filesync-version',
message: 'What version of core.io-filesync?',
default: '*',
when: function(answers) {
return answers.versions && answers.filesync;
}
},
];
module.exports = questions;
module.exports.postprocess = function(context, answers) {
answers.optionals = {};
answers.dependencies = {};
answers.dependents = {};
/*
* Process prompt answers to include
* dependencies versions.
*
* We also have to remove the optionals
* that we are not using.
*/
Object.keys(answers).map(key => {
if (!packages[key]) return;
let vkey = `${key}-version`;
let value = answers[key];
/**
* We don't want this dependency.
*/
if (value === false) return;
let pkg = packages[key];
let version = answers[vkey];
delete answers[key];
delete answers[vkey];
/**
* Store our dependency version,
* if we did not specify one, just
* use latest.
*/
answers.dependencies[pkg] = version || '*';
/**
* Store our optional key, the actual
* value is not relevant.
* Note that we are just adding an optional
* for all modules, even if they do not have
* an optional file(s).
*/
answers.optionals[key] = pkg;
});
if (answers.optionals.server && answers.optionals.persistence) {
answers.dependents = {
server: ['persistence']
};
}
return answers;
};
/**
* List of optional packages
*/
module.exports.optionals = packages;