From d4d1e1497bdece244dd4f70798debdb426be65d7 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Mon, 2 Sep 2024 15:30:53 -0300 Subject: [PATCH] add initial command integration to jdl --- generators/base/api.d.ts | 2 ++ generators/base/internal/command.ts | 6 ++++ .../server/jdl/application-definition.ts | 6 ++-- generators/server/options/feign-client.ts | 28 ------------------- generators/server/options/index.ts | 1 - generators/spring-boot/command.ts | 4 +++ .../options/feign-client.spec.ts | 3 +- 7 files changed, 18 insertions(+), 32 deletions(-) delete mode 100644 generators/server/options/feign-client.ts rename generators/{server => spring-boot}/options/feign-client.spec.ts (92%) diff --git a/generators/base/api.d.ts b/generators/base/api.d.ts index 89bc68d56703..09accd207153 100644 --- a/generators/base/api.d.ts +++ b/generators/base/api.d.ts @@ -1,6 +1,7 @@ import type { ArgumentSpec, BaseFeatures, BaseOptions, CliOptionSpec } from 'yeoman-generator'; import type { RequireAtLeastOne, SetOptional, Simplify, TaggedUnion, TupleToUnion, ValueOf } from 'type-fest'; import type CoreGenerator from '../base-core/index.js'; +import { JHipsterOptionDefinition } from '../../jdl/types/types.js'; import { MergeUnion } from './internal/merge-union.js'; type ConfigScope = 'storage' | 'blueprint' | 'control' | 'generator'; @@ -233,6 +234,7 @@ export type ConfigSpec = { readonly prompt?: | PromptSpec | ((gen: CoreGenerator & { jhipsterConfigWithDefaults: Record }, config: ConfigSpec) => PromptSpec); + readonly jdl?: Omit; readonly scope?: 'storage' | 'blueprint' | 'generator'; /** * The callback receives the generator as input for 'generator' scope. diff --git a/generators/base/internal/command.ts b/generators/base/internal/command.ts index 3b90542ce4ce..d02fdf28e584 100644 --- a/generators/base/internal/command.ts +++ b/generators/base/internal/command.ts @@ -1,3 +1,4 @@ +import { JHipsterOptionDefinition } from '../../../jdl/types/types.js'; import { JHipsterArguments, JHipsterConfigs } from '../api.js'; export const extractArgumentsFromConfigs = (configs: JHipsterConfigs | undefined): JHipsterArguments => { @@ -14,3 +15,8 @@ export const extractArgumentsFromConfigs = (configs: JHipsterConfigs | undefined ]), ) as JHipsterArguments; }; + +export const extractJdlDefinitionFromCommand = (configs: JHipsterConfigs = {}): JHipsterOptionDefinition[] => + Object.entries(configs) + .filter(([_name, def]) => def.jdl) + .map(([name, def]) => ({ name, ...def.jdl })); diff --git a/generators/server/jdl/application-definition.ts b/generators/server/jdl/application-definition.ts index 037ba1839c20..f412514954d1 100644 --- a/generators/server/jdl/application-definition.ts +++ b/generators/server/jdl/application-definition.ts @@ -20,15 +20,17 @@ import { snakeCase, upperCase } from 'lodash-es'; import { JDLApplicationConfig, JHipsterOptionDefinition } from '../../../jdl/types/types.js'; import databaseMigrationOption from '../options/database-migration.js'; import messageBrokerOption from '../options/message-broker.js'; -import { feignClientDefinition, syncUserWithIdpDefinition } from '../options/index.js'; +import { syncUserWithIdpDefinition } from '../options/index.js'; import { jdlRoutesOptions } from '../../spring-cloud/generators/gateway/jdl/jdl-routes-option.js'; +import command from '../../spring-boot/command.js'; +import { extractJdlDefinitionFromCommand } from '../../base/internal/command.js'; const jdlOptions: JHipsterOptionDefinition[] = [ databaseMigrationOption, messageBrokerOption, - feignClientDefinition, syncUserWithIdpDefinition, jdlRoutesOptions, + ...extractJdlDefinitionFromCommand(command.configs), ]; const applicationConfig: JDLApplicationConfig = { diff --git a/generators/server/options/feign-client.ts b/generators/server/options/feign-client.ts deleted file mode 100644 index aef1d5cb5b7d..000000000000 --- a/generators/server/options/feign-client.ts +++ /dev/null @@ -1,28 +0,0 @@ -/** - * Copyright 2013-2024 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 { JHipsterOptionDefinition } from '../../../jdl/types/types.js'; - -export const FEIGN_CLIENT = 'feignClient'; - -export const feignClientDefinition: JHipsterOptionDefinition = { - name: FEIGN_CLIENT, - type: 'boolean', - tokenType: 'BOOLEAN', -}; diff --git a/generators/server/options/index.ts b/generators/server/options/index.ts index 1820b16da131..ca90eaab7319 100644 --- a/generators/server/options/index.ts +++ b/generators/server/options/index.ts @@ -19,5 +19,4 @@ export * from './database-migration.js'; export * from './message-broker.js'; -export * from './feign-client.js'; export * from './sync-user-with-idp.js'; diff --git a/generators/spring-boot/command.ts b/generators/spring-boot/command.ts index 3bbc4c48220b..a79e9d034548 100644 --- a/generators/spring-boot/command.ts +++ b/generators/spring-boot/command.ts @@ -125,6 +125,10 @@ const command: JHipsterCommandDefinition = { [MICROSERVICE].includes(gen.jhipsterConfigWithDefaults.applicationType) && (reactive ?? gen.jhipsterConfigWithDefaults.reactive) === false, }), + jdl: { + type: 'boolean', + tokenType: 'BOOLEAN', + }, default: false, }, syncUserWithIdp: { diff --git a/generators/server/options/feign-client.spec.ts b/generators/spring-boot/options/feign-client.spec.ts similarity index 92% rename from generators/server/options/feign-client.spec.ts rename to generators/spring-boot/options/feign-client.spec.ts index 349ecab2425b..aecbb567465f 100644 --- a/generators/server/options/feign-client.spec.ts +++ b/generators/spring-boot/options/feign-client.spec.ts @@ -1,6 +1,7 @@ import { before, describe, expect, it } from 'esmocha'; import { ImportState, createImporterFromContent } from '../../../jdl/jdl-importer.js'; -import { FEIGN_CLIENT as optionName } from './index.js'; + +const optionName = 'feignClient'; describe(`generators - server - jdl - ${optionName}`, () => { [true, false].forEach(optionValue => {