-
-
Notifications
You must be signed in to change notification settings - Fork 4k
/
prompts.js
190 lines (170 loc) · 5.81 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
184
185
186
187
188
189
190
/**
* 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 constants = require('../generator-constants');
const { clientDefaultConfig } = require('../generator-defaults');
const ANGULAR = constants.SUPPORTED_CLIENT_FRAMEWORKS.ANGULAR;
const REACT = constants.SUPPORTED_CLIENT_FRAMEWORKS.REACT;
const VUE = constants.SUPPORTED_CLIENT_FRAMEWORKS.VUE;
module.exports = {
askForModuleName,
askForClient,
askForClientTheme,
askForClientThemeVariant,
};
function askForModuleName() {
if (this.jhipsterConfig.baseName) return undefined;
return this.askModuleName(this);
}
function askForClient() {
if (this.existingProject) return true;
const applicationType = this.applicationType;
const choices = [
{
value: ANGULAR,
name: 'Angular',
},
{
value: REACT,
name: 'React',
},
{
value: VUE,
name: 'Vue',
},
{
value: 'no',
name: 'No client',
},
];
const PROMPT = {
type: 'list',
name: 'clientFramework',
when: response => applicationType !== 'microservice' && applicationType !== 'uaa',
message: `Which ${chalk.yellow('*Framework*')} would you like to use for the client?`,
choices,
default: clientDefaultConfig.clientFramework,
};
return this.prompt(PROMPT).then(prompt => {
this.clientFramework = this.jhipsterConfig.clientFramework = prompt.clientFramework;
if (this.clientFramework === 'no') {
this.skipClient = this.jhipsterConfig.skipClient = true;
}
});
}
function askForClientTheme() {
if (this.existingProject) {
return;
}
const skipClient = this.skipClient;
const defaultChoices = [
{
value: 'none',
name: 'Default JHipster',
},
{ value: 'cerulean', name: 'Cerulean' },
{ value: 'cosmo', name: 'Cosmo' },
{ value: 'cerulean', name: 'Cyborg' },
{ value: 'darkly', name: 'Darkly' },
{ value: 'flatly', name: 'Flatly' },
{ value: 'journal', name: 'Journal' },
{ value: 'litera', name: 'Litera' },
{ value: 'lumen', name: 'Lumen' },
{ value: 'lux', name: 'Lux' },
{ value: 'materia', name: 'Materia' },
{ value: 'minty', name: 'Minty' },
{ value: 'pulse', name: 'Pulse' },
{ value: 'sandstone', name: 'Sandstone' },
{ value: 'simplex', name: 'Simplex' },
{ value: 'sketchy', name: 'Sketchy' },
{ value: 'slate', name: 'Slate' },
{ value: 'solar', name: 'Solar' },
{ value: 'spacelab', name: 'Spacelab' },
{ value: 'superhero', name: 'Superhero' },
{ value: 'united', name: 'United' },
{ value: 'yeti', name: 'Yeti' },
];
const PROMPT = {
type: 'list',
name: 'clientTheme',
when: () => !skipClient,
message: 'Would you like to use a Bootswatch theme (https://bootswatch.com/)?',
choices: defaultChoices,
default: clientDefaultConfig.clientTheme,
};
const self = this;
const promptClientTheme = function (PROMPT) {
return self.prompt(PROMPT).then(prompt => {
self.clientTheme = self.jhipsterConfig.clientTheme = prompt.clientTheme;
});
};
const done = this.async();
this.httpsGet(
'https://bootswatch.com/api/4.json',
// eslint-disable-next-line consistent-return
body => {
try {
const { themes } = JSON.parse(body);
PROMPT.choices = [
{
value: 'none',
name: 'Default JHipster',
},
...themes.map(theme => ({
value: theme.name.toLowerCase(),
name: theme.name,
})),
];
} catch (err) {
this.warning('Could not fetch bootswatch themes from API. Using default ones.');
}
done(undefined, promptClientTheme(PROMPT));
},
() => {
this.warning('Could not fetch bootswatch themes from API. Using default ones.');
done(undefined, promptClientTheme(PROMPT));
}
);
}
function askForClientThemeVariant() {
if (this.existingProject) {
return undefined;
}
if (this.clientTheme === 'none') {
this.clientThemeVariant = '';
return undefined;
}
const skipClient = this.skipClient;
const choices = [
{ value: 'primary', name: 'Primary' },
{ value: 'dark', name: 'Dark' },
{ value: 'light', name: 'Light' },
];
const PROMPT = {
type: 'list',
name: 'clientThemeVariant',
when: () => !skipClient,
message: 'Choose a Bootswatch variant navbar theme (https://bootswatch.com/)?',
choices,
default: clientDefaultConfig.clientThemeVariant,
};
return this.prompt(PROMPT).then(prompt => {
this.clientThemeVariant = this.jhipsterConfig.clientThemeVariant = prompt.clientThemeVariant;
});
}