Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move some prompts to command config #26008

Merged
merged 2 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions generators/app/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Options:
--jdl-store <value> JDL store
--prettier-tab-width <value> Default tab width for prettier
--skip-commit-hook Skip adding husky commit hooks
--auth <value> Provide authentication type for the application when skipping server side generation
--db <value> Provide DB name for the application when skipping server side generation
--incremental-changelog Creates incremental database changelogs
--skip-user-management Skip the user management module during app generation
Expand All @@ -38,7 +37,6 @@ Options:
--enable-swagger-codegen API first development using OpenAPI-generator
--enable-hibernate-cache Enable hibernate cache
--message-broker <value> message broker
--reactive Generate a reactive backend
--search-engine <value> Provide search engine for the application when skipping server side generation
--skip-check-length-of-identifier Skip check the length of the identifier, only for recent Oracle databases that support 30+ characters metadata
--skip-db-changelog Skip the generation of database migrations
Expand All @@ -47,6 +45,9 @@ Options:
--project-version <value> project version to use, this option is not persisted (env: JHI_PROJECT_VERSION)
--jhipster-dependencies-version <value> jhipster-dependencies version to use, this option is not persisted (env: JHIPSTER_DEPENDENCIES_VERSION)
--application-type <value> Application type to generate (choices: "monolith", "gateway", "microservice")
--reactive Generate a reactive backend
--service-discovery-type <value> Service discovery type (choices: "consul", "eureka", "no")
--auth <value> Provide authentication type for the application when skipping server side generation (choices: "jwt", "oauth2", "session")
--feign-client Generate a feign client
--sync-user-with-idp Allow relationships with User for oauth2 applications
--with-generated-flag Add a GeneratedByJHipster annotation to all generated java classes and interfaces
Expand Down
2 changes: 1 addition & 1 deletion generators/base-core/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ You can ignore this error by passing '--skip-checks' to jhipster command.`);
return Object.entries(configs)
.filter(([_name, def]) => def?.prompt)
.map(([name, def]) => {
const promptSpec = typeof def.prompt === 'function' ? def.prompt(this) : { ...def.prompt };
const promptSpec = typeof def.prompt === 'function' ? def.prompt(this as any, def) : { ...def.prompt };
let storage: any;
if ((def.scope ?? 'storage') === 'storage') {
storage = this.config;
Expand Down
2 changes: 1 addition & 1 deletion generators/base/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export type ConfigSpec = {

cli?: SetOptional<CliOptionSpec, 'name'> & { env?: string };
argument?: JHipsterArgumentConfig;
prompt?: PromptSpec | ((CoreGenerator) => PromptSpec);
prompt?: PromptSpec | ((gen: CoreGenerator & { jhipsterConfigWithDefaults: Record<string, any> }, config: ConfigSpec) => PromptSpec);
scope?: 'storage' | 'blueprint' | 'generator';
/**
* The callback receives the generator as input for 'generator' scope.
Expand Down
5 changes: 3 additions & 2 deletions generators/jdl/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,13 @@ Options:
--jdl-store <value> JDL store
--prettier-tab-width <value> Default tab width for prettier
--skip-commit-hook Skip adding husky commit hooks
--auth <value> Provide authentication type for the application when skipping server side generation
--db <value> Provide DB name for the application when skipping server side generation
--incremental-changelog Creates incremental database changelogs
--recreate-initial-changelog Recreate the initial database changelog based on the current config
--cache-provider <value> Cache provider
--enable-swagger-codegen API first development using OpenAPI-generator
--enable-hibernate-cache Enable hibernate cache
--message-broker <value> message broker
--reactive Generate a reactive backend
--search-engine <value> Provide search engine for the application when skipping server side generation
--skip-check-length-of-identifier Skip check the length of the identifier, only for recent Oracle databases that support 30+ characters metadata
--skip-db-changelog Skip the generation of database migrations
Expand All @@ -211,6 +209,9 @@ Options:
--project-version <value> project version to use, this option is not persisted (env: JHI_PROJECT_VERSION)
--jhipster-dependencies-version <value> jhipster-dependencies version to use, this option is not persisted (env: JHIPSTER_DEPENDENCIES_VERSION)
--application-type <value> Application type to generate (choices: "monolith", "gateway", "microservice")
--reactive Generate a reactive backend
--service-discovery-type <value> Service discovery type (choices: "consul", "eureka", "no")
--auth <value> Provide authentication type for the application when skipping server side generation (choices: "jwt", "oauth2", "session")
--feign-client Generate a feign client
--sync-user-with-idp Allow relationships with User for oauth2 applications
--with-generated-flag Add a GeneratedByJHipster annotation to all generated java classes and interfaces
Expand Down
11 changes: 0 additions & 11 deletions generators/server/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ import { APPLICATION_TYPE_GATEWAY, APPLICATION_TYPE_MICROSERVICE, APPLICATION_TY

const command: JHipsterCommandDefinition = {
options: {
authenticationType: {
name: 'auth',
description: 'Provide authentication type for the application when skipping server side generation',
type: String,
scope: 'storage',
},
db: {
description: 'Provide DB name for the application when skipping server side generation',
type: String,
Expand Down Expand Up @@ -67,11 +61,6 @@ const command: JHipsterCommandDefinition = {
type: String,
scope: 'storage',
},
reactive: {
description: 'Generate a reactive backend',
type: Boolean,
scope: 'storage',
},
searchEngine: {
description: 'Provide search engine for the application when skipping server side generation',
type: String,
Expand Down
72 changes: 65 additions & 7 deletions generators/spring-boot/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import chalk from 'chalk';
import { JHipsterCommandDefinition } from '../base/api.js';
import { GENERATOR_JAVA, GENERATOR_LIQUIBASE, GENERATOR_SPRING_DATA_RELATIONAL } from '../generator-list.js';
import { APPLICATION_TYPE_MICROSERVICE } from '../../jdl/index.js';

const command: JHipsterCommandDefinition = {
options: {
Expand All @@ -31,19 +31,77 @@ const command: JHipsterCommandDefinition = {
},
},
configs: {
reactive: {
cli: {
description: 'Generate a reactive backend',
type: Boolean,
},
prompt: gen => ({
when: () => ['monolith', 'microservice'].includes(gen.jhipsterConfigWithDefaults.applicationType),
type: 'confirm',
message: 'Do you want to make it reactive with Spring WebFlux?',
}),
},
serverPort: {
prompt: gen => ({
when: () => ['gateway', 'microservice'].includes(gen.jhipsterConfigWithDefaults.applicationType),
type: 'input',
validate: input => (/^([0-9]*)$/.test(input) ? true : 'This is not a valid port number.'),
message:
'As you are running in a microservice architecture, on which port would like your server to run? It should be unique to avoid port conflicts.',
default: () => gen.jhipsterConfigWithDefaults.serverPort,
}),
},
serviceDiscoveryType: {
cli: {
description: 'Service discovery type',
type: String,
},
prompt: gen => ({
when: () => ['gateway', 'microservice'].includes(gen.jhipsterConfigWithDefaults.applicationType),
type: 'list',
message: 'Which service discovery server do you want to use?',
default: 'consul',
}),
choices: [
{ value: 'consul', name: 'Consul (recommended)' },
{ value: 'eureka', name: 'JHipster Registry (legacy, uses Eureka, provides Spring Cloud Config support)' },
{ value: 'no', name: 'No service discovery' },
],
},
authenticationType: {
cli: {
name: 'auth',
description: 'Provide authentication type for the application when skipping server side generation',
type: String,
},
prompt: (gen, config) => ({
type: 'list',
message: `Which ${chalk.yellow('*type*')} of authentication would you like to use?`,
choices: () =>
gen.jhipsterConfigWithDefaults.applicationType !== 'monolith'
? (config.choices as any).filter(({ value }) => value !== 'session')
: config.choices,
default: () => gen.jhipsterConfigWithDefaults.authenticationType,
}),
choices: [
{ value: 'jwt', name: 'JWT authentication (stateless, with a token)' },
{ value: 'oauth2', name: 'OAuth 2.0 / OIDC Authentication (stateful, works with Keycloak and Okta)' },
{ value: 'session', name: 'HTTP Session Authentication (stateful, default Spring Security mechanism)' },
],
},
feignClient: {
description: 'Generate a feign client',
cli: {
type: Boolean,
},
prompt: {
prompt: gen => ({
type: 'confirm',
message: 'Do you want to generate a feign client?',
when: currentAnswer =>
currentAnswer.applicationType === APPLICATION_TYPE_MICROSERVICE &&
currentAnswer.reactive !== undefined &&
!currentAnswer.reactive,
},
when: ({ reactive }) =>
['microservice'].includes(gen.jhipsterConfigWithDefaults.applicationType) &&
(reactive ?? gen.jhipsterConfigWithDefaults.reactive) === false,
}),
default: false,
},
syncUserWithIdp: {
Expand Down
76 changes: 3 additions & 73 deletions generators/spring-boot/prompts.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,26 @@ import {
authenticationTypes,
databaseTypes,
cacheTypes,
serviceDiscoveryTypes,
testFrameworkTypes,
} from '../../jdl/jhipster/index.js';
import { MESSAGE_BROKER } from '../server/options/index.js';
import { R2DBC_DB_OPTIONS, SQL_DB_OPTIONS } from '../server/support/database.js';

const { OptionNames } = applicationOptions;
const { GATEWAY, MICROSERVICE, MONOLITH } = applicationTypes;
const { GATEWAY, MONOLITH } = applicationTypes;
const { CAFFEINE, EHCACHE, HAZELCAST, INFINISPAN, MEMCACHED, REDIS } = cacheTypes;
const { JWT, OAUTH2, SESSION } = authenticationTypes;
const { OAUTH2 } = authenticationTypes;
const { CASSANDRA, H2_DISK, H2_MEMORY, MONGODB, NEO4J, SQL, COUCHBASE } = databaseTypes;
const { CONSUL, EUREKA } = serviceDiscoveryTypes;
const {
AUTHENTICATION_TYPE,
CACHE_PROVIDER,
DATABASE_TYPE,
DEV_DATABASE_TYPE,
PROD_DATABASE_TYPE,
REACTIVE,
SERVER_PORT,
SERVICE_DISCOVERY_TYPE,
WEBSOCKET,
SEARCH_ENGINE,
ENABLE_SWAGGER_CODEGEN,
} = OptionNames;
const NO_SERVICE_DISCOVERY = serviceDiscoveryTypes.NO;
const NO_DATABASE = databaseTypes.NO;
const NO_CACHE_PROVIDER = cacheTypes.NO;
const { GATLING, CUCUMBER } = testFrameworkTypes;
Expand All @@ -77,72 +71,8 @@ const getOptionFromArray = (array, option) => {
export async function askForServerSideOpts({ control }) {
if (control.existingProject && !this.options.askAnswered) return;

const { applicationType, serverPort: defaultServerPort, reactive } = this.jhipsterConfigWithDefaults;
const { applicationType } = this.jhipsterConfigWithDefaults;
const prompts = [
{
when: () => [MONOLITH, MICROSERVICE].includes(applicationType),
type: 'confirm',
name: REACTIVE,
message: 'Do you want to make it reactive with Spring WebFlux?',
default: reactive,
},
{
when: () => applicationType === GATEWAY || applicationType === MICROSERVICE,
type: 'input',
name: SERVER_PORT,
validate: input => (/^([0-9]*)$/.test(input) ? true : 'This is not a valid port number.'),
message:
'As you are running in a microservice architecture, on which port would like your server to run? It should be unique to avoid port conflicts.',
default: defaultServerPort,
},
{
when: () => applicationType === 'gateway' || applicationType === 'microservice',
type: 'list',
name: SERVICE_DISCOVERY_TYPE,
message: 'Which service discovery server do you want to use?',
choices: [
{
value: CONSUL,
name: 'Consul (recommended)',
},
{
value: EUREKA,
name: 'JHipster Registry (legacy, uses Eureka, provides Spring Cloud Config support)',
},
{
value: NO_SERVICE_DISCOVERY,
name: 'No service discovery',
},
],
default: CONSUL,
},
{
when: answers =>
(applicationType === MONOLITH && answers.serviceDiscoveryType !== EUREKA) || [GATEWAY, MICROSERVICE].includes(applicationType),
type: 'list',
name: AUTHENTICATION_TYPE,
message: `Which ${chalk.yellow('*type*')} of authentication would you like to use?`,
choices: answers => {
const opts = [
{
value: JWT,
name: 'JWT authentication (stateless, with a token)',
},
];
opts.push({
value: OAUTH2,
name: 'OAuth 2.0 / OIDC Authentication (stateful, works with Keycloak and Okta)',
});
if (applicationType === MONOLITH && answers.serviceDiscoveryType !== EUREKA) {
opts.push({
value: SESSION,
name: 'HTTP Session Authentication (stateful, default Spring Security mechanism)',
});
}
return opts;
},
default: this.jhipsterConfigWithDefaults.authenticationType,
},
{
type: 'list',
name: DATABASE_TYPE,
Expand Down
Loading