-
-
Notifications
You must be signed in to change notification settings - Fork 4k
/
prompts.js
183 lines (170 loc) · 6.43 KB
/
prompts.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
/**
* Copyright 2013-2020 the original author or authors from the JHipster project.
*
* This file is part of the JHipster project, see https://www.jhipster.tech/
* for more information.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const chalk = require('chalk');
const statistics = require('../statistics');
const packagejs = require('../../package.json');
const generatorDefaults = require('../generator-defaults').defaultConfig;
module.exports = {
askForInsightOptIn,
askForApplicationType,
askForModuleName,
askForTestOpts,
askForMoreModules,
};
async function askForInsightOptIn() {
const answers = await this.prompt({
when: () => statistics.shouldWeAskForOptIn(),
type: 'confirm',
name: 'insight',
message: `May ${chalk.cyan('JHipster')} anonymously report usage statistics to improve the tool over time?`,
default: true,
});
if (answers.insight !== undefined) {
statistics.setOptOutStatus(!answers.insight);
}
}
async function askForApplicationType() {
if (this.existingProject) return;
const applicationTypeChoices = [
{
value: 'monolith',
name: 'Monolithic application (recommended for simple projects)',
},
{
value: 'microservice',
name: 'Microservice application',
},
{
value: 'gateway',
name: 'Microservice gateway',
},
{
value: 'uaa',
name: 'JHipster UAA server',
},
];
const answers = await this.prompt([
{
type: 'list',
name: 'applicationType',
message: `Which ${chalk.yellow('*type*')} of application would you like to create?`,
choices: applicationTypeChoices,
default: generatorDefaults.applicationType,
},
{
when: answers => ['gateway', 'monolith', 'microservice'].includes(answers.applicationType),
type: 'confirm',
name: 'reactive',
message: '[Beta] Do you want to make it reactive with Spring WebFlux?',
default: generatorDefaults.reactive,
},
]);
this.applicationType = this.jhipsterConfig.applicationType = answers.applicationType;
this.reactive = this.jhipsterConfig.reactive = answers.reactive;
}
function askForModuleName() {
if (this.existingProject) return undefined;
return this.askModuleName(this);
}
async function askForTestOpts() {
if (this.existingProject) return undefined;
const choices = [];
if (!this.skipServer) {
// all server side test frameworks should be added here
choices.push({ name: 'Gatling', value: 'gatling' }, { name: 'Cucumber', value: 'cucumber' });
}
if (!this.skipClient) {
// all client side test frameworks should be added here
choices.push({ name: 'Protractor **Deprecated**', value: 'protractor' });
choices.push({ name: 'Cypress', value: 'cypress' });
}
const PROMPT = {
type: 'checkbox',
name: 'testFrameworks',
message: 'Besides JUnit and Jest, which testing frameworks would you like to use?',
choices,
default: generatorDefaults.testFrameworks,
};
const answers = await this.prompt(PROMPT);
this.testFrameworks = this.jhipsterConfig.testFrameworks = answers.testFrameworks;
return answers;
}
function askForMoreModules() {
if (this.existingProject) {
return undefined;
}
return this.prompt({
type: 'confirm',
name: 'installModules',
message: 'Would you like to install other generators from the JHipster Marketplace?',
default: false,
}).then(answers => {
if (answers.installModules) {
return new Promise(resolve => askModulesToBeInstalled(resolve, this));
}
return undefined;
});
}
function askModulesToBeInstalled(done, generator) {
const jHipsterMajorVersion = packagejs.version.match(/^(\d+)/g);
generator.httpsGet(
`https://api.npms.io/v2/search?q=keywords:jhipster-module+jhipster-${jHipsterMajorVersion}&from=0&size=50`,
body => {
try {
const moduleResponse = JSON.parse(body);
const choices = [];
moduleResponse.results.forEach(modDef => {
choices.push({
value: { name: modDef.package.name, version: modDef.package.version },
name: `(${modDef.package.name}-${modDef.package.version}) ${modDef.package.description}`,
});
});
if (choices.length > 0) {
generator
.prompt({
type: 'checkbox',
name: 'otherModules',
message: 'Which other modules would you like to use?',
choices,
default: [],
})
.then(answers => {
// [ {name: [moduleName], version:[version]}, ...]
answers.otherModules.forEach(module => {
generator.otherModules.push({ name: module.name, version: module.version });
});
generator.jhipsterConfig.otherModules = generator.otherModules;
done();
});
} else {
done();
}
} catch (err) {
generator.warning(`Error while parsing. Please install the modules manually or try again later. ${err.message}`);
generator.debug('Error:', err);
done();
}
},
error => {
generator.warning(`Unable to contact server to fetch additional modules: ${error.message}`);
generator.debug('Error:', error);
done();
}
);
}