-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Expand file tree
/
Copy pathcommand.ts
More file actions
198 lines (193 loc) · 6.32 KB
/
command.ts
File metadata and controls
198 lines (193 loc) · 6.32 KB
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
/**
* Copyright 2013-2026 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
*
* https://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.
*/
import chalk from 'chalk';
import { intersection } from 'lodash-es';
import type { JHipsterCommandDefinition } from '../../lib/command/index.ts';
import { ALPHANUMERIC_PATTERN } from '../../lib/constants/jdl.ts';
import { APPLICATION_TYPE_GATEWAY, APPLICATION_TYPE_MICROSERVICE } from '../../lib/core/application-types.ts';
import { clientFrameworkTypes, testFrameworkTypes } from '../../lib/jhipster/index.ts';
const { CYPRESS, PLAYWRIGHT } = testFrameworkTypes;
const { ANGULAR, REACT, VUE, NO: CLIENT_FRAMEWORK_NO } = clientFrameworkTypes;
const microfrontendsToPromptValue = (answer: string | { baseName: string }[]) =>
Array.isArray(answer) ? answer.map(({ baseName }) => baseName).join(',') : answer;
const promptValueToMicrofrontends = (answer: string): { baseName: string }[] =>
answer
? answer
.split(',')
.map(baseName => baseName.trim())
.filter(Boolean)
.map(baseName => ({ baseName }))
: [];
const command = {
configs: {
clientFramework: {
description: 'Provide client framework for the application',
cli: {
type: String,
},
prompt: generator => ({
type: 'select',
message: () =>
generator.jhipsterConfigWithDefaults.applicationType === APPLICATION_TYPE_MICROSERVICE
? `Which ${chalk.yellow('*framework*')} would you like to use as microfrontend?`
: `Which ${chalk.yellow('*framework*')} would you like to use for the client?`,
}),
choices: [
{ value: ANGULAR, name: 'Angular' },
{ value: REACT, name: 'React' },
{ value: VUE, name: 'Vue' },
{ value: CLIENT_FRAMEWORK_NO, name: 'No client' },
],
scope: 'storage',
},
clientTheme: {
cli: {
type: String,
hide: true,
},
scope: 'storage',
},
clientThemeVariant: {
cli: {
type: String,
hide: true,
},
choices: [
{ value: 'primary', name: 'Primary' },
{ value: 'dark', name: 'Dark' },
{ value: 'light', name: 'Light' },
],
scope: 'storage',
},
clientBundler: {
cli: {
type: String,
hide: true,
},
choices: ['webpack', 'vite', 'esbuild'],
scope: 'storage',
},
devServerPort: {
cli: {
type: Number,
hide: true,
},
scope: 'storage',
},
devServerPortProxy: {
cli: {
type: Number,
hide: true,
},
scope: 'storage',
},
microfrontend: {
description: 'Enable microfrontend support',
cli: {
type: Boolean,
},
prompt: ({ jhipsterConfigWithDefaults: config }) => ({
type: 'confirm',
when: answers =>
[ANGULAR, REACT, VUE].includes(answers.clientFramework ?? config.clientFramework) &&
config.applicationType === APPLICATION_TYPE_GATEWAY,
message: `Do you want to enable ${chalk.yellow('*microfrontends*')}?`,
default: false,
}),
scope: 'storage',
},
microfrontends: {
description: 'Microfrontends to load',
cli: {
type: (val: string) => promptValueToMicrofrontends(val),
},
prompt: ({ jhipsterConfigWithDefaults: config }) => ({
when: answers => {
const askForMicrofrontends = Boolean(
(answers.microfrontend ?? config.microfrontend) &&
(answers.applicationType ?? config.applicationType) === APPLICATION_TYPE_GATEWAY,
);
if (askForMicrofrontends && answers.microfrontends) {
answers.microfrontends = microfrontendsToPromptValue(answers.microfrontends);
} else {
answers.microfrontends = [];
}
return askForMicrofrontends;
},
type: 'input',
message: `Comma separated ${chalk.yellow('*microfrontend*')} app names.`,
filter: promptValueToMicrofrontends,
transformer: microfrontendsToPromptValue,
}),
scope: 'storage',
},
clientTestFramework: {
cli: {
type: String,
},
jdl: {
type: 'string',
tokenType: 'NAME',
tokenValuePattern: ALPHANUMERIC_PATTERN,
},
scope: 'storage',
choices: ['jest', 'vitest'],
default: ctx => (ctx?.clientFramework === 'vue' || ctx?.clientFramework === 'angular' ? 'vitest' : 'jest'),
},
clientTestFrameworks: {
description: 'Client test frameworks',
cli: {
type: Array,
hide: true,
},
prompt: ({ jhipsterConfigWithDefaults: config }) => ({
when: answers => [ANGULAR, REACT, VUE].includes(answers.clientFramework ?? config.clientFramework),
type: 'checkbox',
message: 'Besides Jest/Vitest, which testing frameworks would you like to use?',
default: () => intersection([CYPRESS, PLAYWRIGHT], config.testFrameworks),
}),
choices: [
{ name: 'Cypress', value: CYPRESS },
{ name: 'Playwright', value: PLAYWRIGHT },
],
scope: 'storage',
},
withAdminUi: {
description: 'Generate administrative user interface',
cli: {
type: Boolean,
},
prompt: ({ jhipsterConfigWithDefaults: config }) => ({
type: 'confirm',
when: answers => [ANGULAR, REACT, VUE].includes(answers.clientFramework ?? config.clientFramework),
message: 'Do you want to generate the admin UI?',
}),
scope: 'storage',
},
clientRootDir: {
description: 'Client root',
cli: {
type: String,
},
scope: 'storage',
},
},
import: ['common'],
} as const satisfies JHipsterCommandDefinition<any>;
export default command;