From 2d43334863555f3ce08973fe0a5efd3d4f8539f8 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Fri, 22 Sep 2023 08:42:35 -0300 Subject: [PATCH 01/10] move microfrotend prompts to client --- .../app/__snapshots__/generator.spec.mts.snap | 1 + generators/app/prompts.mjs | 41 ------------------- generators/base/api.d.mts | 4 +- generators/client/command.mts | 40 ++++++++++++++++-- .../jdl/__snapshots__/generator.spec.mts.snap | 1 + jdl/jhipster/default-application-options.ts | 3 ++ lib/internal/config-def.mts | 2 +- 7 files changed, 46 insertions(+), 46 deletions(-) diff --git a/generators/app/__snapshots__/generator.spec.mts.snap b/generators/app/__snapshots__/generator.spec.mts.snap index 7d183681d3c8..4a12fbfbf7aa 100644 --- a/generators/app/__snapshots__/generator.spec.mts.snap +++ b/generators/app/__snapshots__/generator.spec.mts.snap @@ -49,6 +49,7 @@ Options: --dev-database-type Development database --client-framework Provide client framework for the application (choices: "angular", "react", "vue", "no") --microfrontend Enable microfrontend support + --microfrontends Microfrontends to load --with-admin-ui Generate administrative user interface --prettier-tab-width Default tab width for prettier --skip-git Skip git repository initialization diff --git a/generators/app/prompts.mjs b/generators/app/prompts.mjs index a99590c87a95..f791da3b1f72 100644 --- a/generators/app/prompts.mjs +++ b/generators/app/prompts.mjs @@ -36,16 +36,6 @@ export async function askForInsightOptIn() { } } -const microfrontendsToPromptValue = answer => (Array.isArray(answer) ? answer.map(({ baseName }) => baseName).join(',') : answer); -const promptValueToMicrofrontends = answer => - answer - ? answer - .split(',') - .map(baseName => baseName.trim()) - .filter(Boolean) - .map(baseName => ({ baseName })) - : []; - export async function askForApplicationType({ control }) { if (control.existingProject && this.options.askAnswered !== true) return; const config = this.jhipsterConfigWithDefaults; @@ -74,37 +64,6 @@ export async function askForApplicationType({ control }) { choices: applicationTypeChoices, default: config.applicationType, }, - { - when: answers => { - const { applicationType } = answers; - const askForMicrofrontend = [GATEWAY, MICROSERVICE].includes(applicationType); - if (!askForMicrofrontend) { - answers.microfrontend = false; - } - return askForMicrofrontend; - }, - type: 'confirm', - name: 'microfrontend', - message: `Do you want to enable ${chalk.yellow('*microfrontends*')}?`, - default: config.microfrontend ?? false, - }, - { - when: answers => { - const { applicationType, microfrontend, microfrontends } = answers; - const askForMicrofrontends = applicationType === GATEWAY && microfrontend; - if (askForMicrofrontends) { - answers.microfrontends = microfrontendsToPromptValue(microfrontends); - } else { - answers.microfrontends = []; - } - return askForMicrofrontends; - }, - type: 'input', - name: 'microfrontends', - message: `Comma separated ${chalk.yellow('*microfrontend*')} app names.`, - filter: promptValueToMicrofrontends, - transformer: microfrontendsToPromptValue, - }, ], this.config, ); diff --git a/generators/base/api.d.mts b/generators/base/api.d.mts index 09bb844875c9..2b608e6b2a6d 100644 --- a/generators/base/api.d.mts +++ b/generators/base/api.d.mts @@ -173,10 +173,12 @@ export type ValidationResult = { }; export type PromptSpec = { - type: 'list' | 'confirm'; + type: 'input' | 'list' | 'confirm'; message: string | ((any) => string); when?: boolean | ((any) => boolean); default?: any | ((any) => any); + filter?: any | ((any) => any); + transformer?: any | ((any) => any); }; export type ConfigSpec = { diff --git a/generators/client/command.mts b/generators/client/command.mts index 541bace575e2..b97a33a5aaca 100644 --- a/generators/client/command.mts +++ b/generators/client/command.mts @@ -22,6 +22,16 @@ import { APPLICATION_TYPE_GATEWAY, APPLICATION_TYPE_MICROSERVICE, clientFramewor const { ANGULAR, REACT, VUE, NO: CLIENT_FRAMEWORK_NO } = clientFrameworkTypes; +const microfrontendsToPromptValue = answer => (Array.isArray(answer) ? answer.map(({ baseName }) => baseName).join(',') : answer); +const promptValueToMicrofrontends = answer => + answer + ? answer + .split(',') + .map(baseName => baseName.trim()) + .filter(Boolean) + .map(baseName => ({ baseName })) + : []; + const command: JHipsterCommandDefinition = { options: {}, configs: { @@ -61,14 +71,38 @@ const command: JHipsterCommandDefinition = { cli: { type: Boolean, }, - prompt: generator => ({ + prompt: ({ jhipsterConfigWithDefaults: config }) => ({ type: 'confirm', when: answers => - (answers.clientFramework ?? generator.jhipsterConfigWithDefaults.clientFramework) !== CLIENT_FRAMEWORK_NO && - generator.jhipsterConfigWithDefaults.applicationType === APPLICATION_TYPE_GATEWAY, + (answers.clientFramework ?? config.clientFramework) !== CLIENT_FRAMEWORK_NO && + config.applicationType === APPLICATION_TYPE_GATEWAY, message: `Do you want to enable ${chalk.yellow('*microfrontends*')}?`, }), }, + microfrontends: { + description: 'Microfrontends to load', + cli: { + type: String, + }, + 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, + }), + }, withAdminUi: { description: 'Generate administrative user interface', cli: { diff --git a/generators/jdl/__snapshots__/generator.spec.mts.snap b/generators/jdl/__snapshots__/generator.spec.mts.snap index b6b0fcfa0d7a..443bc0a326fa 100644 --- a/generators/jdl/__snapshots__/generator.spec.mts.snap +++ b/generators/jdl/__snapshots__/generator.spec.mts.snap @@ -209,6 +209,7 @@ Options: --dev-database-type Development database --client-framework Provide client framework for the application (choices: "angular", "react", "vue", "no") --microfrontend Enable microfrontend support + --microfrontends Microfrontends to load --with-admin-ui Generate administrative user interface --prettier-tab-width Default tab width for prettier --skip-git Skip git repository initialization diff --git a/jdl/jhipster/default-application-options.ts b/jdl/jhipster/default-application-options.ts index c883f20254ec..0552e02f6a69 100644 --- a/jdl/jhipster/default-application-options.ts +++ b/jdl/jhipster/default-application-options.ts @@ -104,6 +104,9 @@ export function getConfigForClientApplication(options: any = {}): any { if (options[SKIP_CLIENT]) { options[CLIENT_FRAMEWORK] = NO_CLIENT_FRAMEWORK; } + if (options[OptionNames.MICROFRONTEND] === undefined) { + options[OptionNames.MICROFRONTEND] = Boolean(options[OptionNames.MICROFRONTENDS]); + } const clientFramework = options[CLIENT_FRAMEWORK]; if (clientFramework !== NO_CLIENT_FRAMEWORK) { if (!options[CLIENT_THEME]) { diff --git a/lib/internal/config-def.mts b/lib/internal/config-def.mts index eba26daae0d3..7f91ba48a883 100644 --- a/lib/internal/config-def.mts +++ b/lib/internal/config-def.mts @@ -2,7 +2,7 @@ import type { JHipsterConfigs } from '../../generators/base/api.mjs'; import { upperFirstCamelCase } from '../../generators/base/support/string.mjs'; export const convertConfigToOption = (name, config) => { - const choices = config.choices?.map(choice => (typeof choice === 'string' ? choice : choice.value)); + const choices = config?.choices?.map(choice => (typeof choice === 'string' ? choice : choice.value)); return { name, description: config.description, From 11dccd807ae09526b0783368c9a21328ddbf6737 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Fri, 22 Sep 2023 09:37:25 -0300 Subject: [PATCH 02/10] improve languages composing --- generators/angular/generator.mts | 13 +------------ generators/app/composing.spec.mts | 8 ++++---- generators/app/generator.mjs | 8 +------- generators/languages/generator.mjs | 11 +++++++++-- generators/languages/languages.spec.mjs | 7 +++++-- generators/react/generator.mjs | 16 +--------------- generators/vue/generator.mjs | 13 +------------ 7 files changed, 22 insertions(+), 54 deletions(-) diff --git a/generators/angular/generator.mts b/generators/angular/generator.mts index 00f855ee61b3..03bbc8f9119f 100644 --- a/generators/angular/generator.mts +++ b/generators/angular/generator.mts @@ -55,23 +55,12 @@ export default class AngularGenerator extends BaseApplicationGenerator { async beforeQueue() { await this.dependsOnJHipster(GENERATOR_CLIENT); + await this.dependsOnJHipster(GENERATOR_LANGUAGES); if (!this.fromBlueprint) { await this.composeWithBlueprints(GENERATOR_ANGULAR); } } - get composing() { - return this.asComposingTaskGroup({ - async composing() { - await this.composeWithJHipster(GENERATOR_LANGUAGES); - }, - }); - } - - get [BaseApplicationGenerator.COMPOSING]() { - return this.asComposingTaskGroup(this.delegateTasksToBlueprint(() => this.composing)); - } - get loading() { return this.asLoadingTaskGroup({ loadPackageJson({ application }) { diff --git a/generators/app/composing.spec.mts b/generators/app/composing.spec.mts index 499445845cda..e7f6f49499bb 100644 --- a/generators/app/composing.spec.mts +++ b/generators/app/composing.spec.mts @@ -38,9 +38,9 @@ describe('generator - app - composing', () => { const ClientGenerator = runResult.mockedGenerators['jhipster:client']; assert(ClientGenerator.calledOnce); }); - it('should compose with languages generator', () => { + it('should not compose with languages generator', () => { const LanguagesGenerator = runResult.mockedGenerators['jhipster:languages']; - assert(LanguagesGenerator.calledOnce); + assert.equal(LanguagesGenerator.callCount, 0); }); it('should not compose with entities generator', () => { const MockedGenerator = runResult.mockedGenerators['jhipster:entities']; @@ -83,9 +83,9 @@ describe('generator - app - composing', () => { const ClientGenerator = runResult.mockedGenerators['jhipster:client']; assert.equal(ClientGenerator.callCount, 0); }); - it('should compose with languages generator', () => { + it('should not compose with languages generator', () => { const LanguagesGenerator = runResult.mockedGenerators['jhipster:languages']; - assert(LanguagesGenerator.calledOnce); + assert.equal(LanguagesGenerator.callCount, 0); }); it('should not compose with entities generator', () => { const MockedGenerator = runResult.mockedGenerators['jhipster:entities']; diff --git a/generators/app/generator.mjs b/generators/app/generator.mjs index 4e2025493583..e6af4d51c335 100644 --- a/generators/app/generator.mjs +++ b/generators/app/generator.mjs @@ -28,7 +28,6 @@ import statistics from '../statistics.mjs'; import { GENERATOR_APP, GENERATOR_COMMON, - GENERATOR_LANGUAGES, GENERATOR_CLIENT, GENERATOR_PAGE, GENERATOR_SERVER, @@ -128,13 +127,8 @@ export default class JHipsterAppGenerator extends BaseApplicationGenerator { * - composeCommon (app) -> initializing (common) -> prompting (common) -> ... -> composeServer (app) -> initializing (server) -> ... */ async compose() { - const { enableTranslation, skipServer, skipClient } = this.jhipsterConfigWithDefaults; + const { skipServer, skipClient } = this.jhipsterConfigWithDefaults; await this.composeWithJHipster(GENERATOR_COMMON); - if (enableTranslation) { - await this.composeWithJHipster(GENERATOR_LANGUAGES, { - generatorOptions: { regenerate: true }, - }); - } if (!skipServer) { await this.composeWithJHipster(GENERATOR_SERVER); } diff --git a/generators/languages/generator.mjs b/generators/languages/generator.mjs index d77ea77e01be..6385f8c25638 100644 --- a/generators/languages/generator.mjs +++ b/generators/languages/generator.mjs @@ -55,6 +55,13 @@ export default class LanguagesGenerator extends BaseApplicationGenerator { */ languagesToApply; composedBlueprints; + languageCommand; + + constructor(args, options, features) { + super(args, options, features); + + this.languageCommand = this.options.commandName === 'languages'; + } async beforeQueue() { await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION); @@ -123,7 +130,7 @@ export default class LanguagesGenerator extends BaseApplicationGenerator { return this.asPromptingTaskGroup({ checkPrompts({ control }) { const { enableTranslation, languages } = this.jhipsterConfig; - const showPrompts = this.options.askAnswered || this.env.rootGenerator() === this; + const showPrompts = this.options.askAnswered || this.languageCommand; this.askForNativeLanguage = showPrompts || (!control.existingProject && !this.jhipsterConfig.nativeLanguage); this.askForMoreLanguages = enableTranslation !== false && (showPrompts || (!control.existingProject && (languages?.length ?? 0) < 1)); @@ -182,7 +189,7 @@ export default class LanguagesGenerator extends BaseApplicationGenerator { return this.asPreparingTaskGroup({ prepareForTemplates({ application, source }) { if (application.enableTranslation) { - if (this.options.regenerate) { + if (!this.languageCommand) { this.languagesToApply = application.languages; } else { this.languagesToApply = [...new Set(this.languagesToApply || [])]; diff --git a/generators/languages/languages.spec.mjs b/generators/languages/languages.spec.mjs index 7bc4b6722627..38b6f5f88392 100644 --- a/generators/languages/languages.spec.mjs +++ b/generators/languages/languages.spec.mjs @@ -125,7 +125,7 @@ describe('generator - languages', () => { helpers .run(generatorPath) .withJHipsterConfig({ enableTranslation: true, nativeLanguage: 'fr', languages: ['fr'], baseName: 'jhipster' }) - .withOptions({ ignoreNeedlesError: true }), + .withOptions({ commandName: 'languages', ignoreNeedlesError: true }), ); noLanguageFiles('fr'); }); @@ -134,7 +134,7 @@ describe('generator - languages', () => { helpers .run(generatorPath) .withJHipsterConfig({ enableTranslation: true, nativeLanguage: 'fr', languages: ['en', 'fr'] }) - .withOptions({ ignoreNeedlesError: true, skipPrompts: true, baseName: 'jhipster' }), + .withOptions({ commandName: 'languages', ignoreNeedlesError: true }), ); noLanguageFiles('fr'); noLanguageFiles('en'); @@ -257,6 +257,9 @@ describe('generator - languages', () => { .withAnswers({ languages: ['fr', 'de'], }) + .withOptions({ + commandName: 'languages', + }) .run(); }); describe('for native language translation', () => { diff --git a/generators/react/generator.mjs b/generators/react/generator.mjs index 646d6486a931..1c52b823cba1 100644 --- a/generators/react/generator.mjs +++ b/generators/react/generator.mjs @@ -47,26 +47,12 @@ const { REACT } = clientFrameworkTypes; export default class ReactGenerator extends BaseApplicationGenerator { async beforeQueue() { await this.dependsOnJHipster(GENERATOR_CLIENT); + await this.dependsOnJHipster(GENERATOR_LANGUAGES); if (!this.fromBlueprint) { await this.composeWithBlueprints(GENERATOR_REACT); } } - get composing() { - return this.asComposingTaskGroup({ - async composing() { - const { enableTranslation } = this.jhipsterConfigWithDefaults; - if (!enableTranslation) { - await this.composeWithJHipster(GENERATOR_LANGUAGES); - } - }, - }); - } - - get [BaseApplicationGenerator.COMPOSING]() { - return this.asComposingTaskGroup(this.delegateTasksToBlueprint(() => this.composing)); - } - get loading() { return this.asLoadingTaskGroup({ loadPackageJson({ application }) { diff --git a/generators/vue/generator.mjs b/generators/vue/generator.mjs index 49f8654dc4cb..67154bd2fe71 100644 --- a/generators/vue/generator.mjs +++ b/generators/vue/generator.mjs @@ -44,23 +44,12 @@ const TYPE_BOOLEAN = CommonDBTypes.BOOLEAN; export default class VueGenerator extends BaseApplicationGenerator { async beforeQueue() { await this.dependsOnJHipster(GENERATOR_CLIENT); + await this.dependsOnJHipster(GENERATOR_LANGUAGES); if (!this.fromBlueprint) { await this.composeWithBlueprints(GENERATOR_VUE); } } - get composing() { - return this.asComposingTaskGroup({ - async composing() { - await this.composeWithJHipster(GENERATOR_LANGUAGES); - }, - }); - } - - get [BaseApplicationGenerator.COMPOSING]() { - return this.delegateTasksToBlueprint(() => this.composing); - } - get loading() { return this.asLoadingTaskGroup({ loadPackageJson({ application }) { From 0c091697ae338ca804ee46bbb307bf083dfcc7d3 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Fri, 22 Sep 2023 09:53:24 -0300 Subject: [PATCH 03/10] move applicationType prompt to server --- .../app/__snapshots__/generator.spec.mts.snap | 2 +- generators/app/command.mts | 16 +------- generators/app/prompts.mjs | 41 ------------------- .../jdl/__snapshots__/generator.spec.mts.snap | 2 +- generators/server/command.mts | 29 ++++++++++++- 5 files changed, 31 insertions(+), 59 deletions(-) diff --git a/generators/app/__snapshots__/generator.spec.mts.snap b/generators/app/__snapshots__/generator.spec.mts.snap index 4a12fbfbf7aa..b4b6cfb6d725 100644 --- a/generators/app/__snapshots__/generator.spec.mts.snap +++ b/generators/app/__snapshots__/generator.spec.mts.snap @@ -29,7 +29,6 @@ Options: --pk-type Default primary key type (beta) --client-package-manager Force an unsupported client package manager --test-frameworks Test frameworks to be generated - --application-type Application type to generate (choices: "monolith", "gateway", "microservice") --skip-cache Do not remember prompt answers (default: false) --skip-install Do not automatically install dependencies (default: false) --force-install Fail on install dependencies error (default: false) @@ -45,6 +44,7 @@ Options: --websocket Provide websocket option for the application when skipping server side generation --project-version project version to use, this option is not persisted (env: JHI_PROJECT_VERSION) --jhipster-dependencies-version jhipster-dependencies version to use, this option is not persisted (env: JHIPSTER_DEPENDENCIES_VERSION) + --application-type Application type to generate (choices: "monolith", "gateway", "microservice") --with-generated-flag Add a GeneratedByJHipster annotation to all generated java classes and interfaces --dev-database-type Development database --client-framework Provide client framework for the application (choices: "angular", "react", "vue", "no") diff --git a/generators/app/command.mts b/generators/app/command.mts index 9036b7ee3383..a1fedb42b465 100644 --- a/generators/app/command.mts +++ b/generators/app/command.mts @@ -16,7 +16,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import chalk from 'chalk'; import { JHipsterCommandDefinition } from '../base/api.mjs'; import { GENERATOR_BOOTSTRAP, @@ -27,7 +26,6 @@ import { GENERATOR_LANGUAGES, GENERATOR_SERVER, } from '../generator-list.mjs'; -import { APPLICATION_TYPE_GATEWAY, APPLICATION_TYPE_MICROSERVICE, APPLICATION_TYPE_MONOLITH } from '../../jdl/index.js'; const command: JHipsterCommandDefinition = { options: { @@ -138,19 +136,7 @@ const command: JHipsterCommandDefinition = { type: Array, }, }, - configs: { - applicationType: { - description: 'Application type to generate', - cli: { - type: String, - }, - prompt: { - type: 'list', - message: `Which ${chalk.yellow('*type*')} of application would you like to create?`, - }, - choices: [APPLICATION_TYPE_MONOLITH, APPLICATION_TYPE_GATEWAY, APPLICATION_TYPE_MICROSERVICE], - }, - }, + configs: {}, loadGeneratorOptions: true, import: [ GENERATOR_BOOTSTRAP, diff --git a/generators/app/prompts.mjs b/generators/app/prompts.mjs index f791da3b1f72..6fe9731fc123 100644 --- a/generators/app/prompts.mjs +++ b/generators/app/prompts.mjs @@ -19,10 +19,6 @@ import chalk from 'chalk'; import statistics from '../statistics.mjs'; -import { applicationTypes } from '../../jdl/jhipster/index.mjs'; - -const { GATEWAY, MONOLITH, MICROSERVICE } = applicationTypes; - export async function askForInsightOptIn() { if (!statistics.shouldWeAskForOptIn()) return; const answers = await this.prompt({ @@ -35,40 +31,3 @@ export async function askForInsightOptIn() { statistics.setOptOutStatus(!answers.insight); } } - -export async function askForApplicationType({ control }) { - if (control.existingProject && this.options.askAnswered !== true) return; - const config = this.jhipsterConfigWithDefaults; - - const applicationTypeChoices = [ - { - value: MONOLITH, - name: 'Monolithic application (recommended for simple projects)', - }, - { - value: GATEWAY, - name: 'Gateway application', - }, - { - value: MICROSERVICE, - name: 'Microservice application', - }, - ]; - - await this.prompt( - [ - { - type: 'list', - name: 'applicationType', - message: `Which ${chalk.yellow('*type*')} of application would you like to create?`, - choices: applicationTypeChoices, - default: config.applicationType, - }, - ], - this.config, - ); - - const { applicationType } = this.jhipsterConfig; - // TODO drop for v8, setting the generator with config is deprecated - this.applicationType = applicationType; -} diff --git a/generators/jdl/__snapshots__/generator.spec.mts.snap b/generators/jdl/__snapshots__/generator.spec.mts.snap index 443bc0a326fa..6a9419a0cafe 100644 --- a/generators/jdl/__snapshots__/generator.spec.mts.snap +++ b/generators/jdl/__snapshots__/generator.spec.mts.snap @@ -193,7 +193,6 @@ Options: --pk-type Default primary key type (beta) --client-package-manager Force an unsupported client package manager --test-frameworks Test frameworks to be generated - --application-type Application type to generate (choices: "monolith", "gateway", "microservice") --build Provide build tool for the application when skipping server side generation --cache-provider Cache provider --enable-swagger-codegen API first development using OpenAPI-generator @@ -205,6 +204,7 @@ Options: --websocket Provide websocket option for the application when skipping server side generation --project-version project version to use, this option is not persisted (env: JHI_PROJECT_VERSION) --jhipster-dependencies-version jhipster-dependencies version to use, this option is not persisted (env: JHIPSTER_DEPENDENCIES_VERSION) + --application-type Application type to generate (choices: "monolith", "gateway", "microservice") --with-generated-flag Add a GeneratedByJHipster annotation to all generated java classes and interfaces --dev-database-type Development database --client-framework Provide client framework for the application (choices: "angular", "react", "vue", "no") diff --git a/generators/server/command.mts b/generators/server/command.mts index 9996f499c155..843c472570e3 100644 --- a/generators/server/command.mts +++ b/generators/server/command.mts @@ -16,8 +16,10 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import chalk from 'chalk'; import { JHipsterCommandDefinition } from '../base/api.mjs'; import { GENERATOR_JAVA, GENERATOR_LIQUIBASE, GENERATOR_SPRING_DATA_RELATIONAL } from '../generator-list.mjs'; +import { APPLICATION_TYPE_GATEWAY, APPLICATION_TYPE_MICROSERVICE, APPLICATION_TYPE_MONOLITH } from '../../jdl/index.js'; const command: JHipsterCommandDefinition = { options: { @@ -86,7 +88,32 @@ const command: JHipsterCommandDefinition = { hide: true, }, }, - configs: {}, + configs: { + applicationType: { + description: 'Application type to generate', + cli: { + type: String, + }, + prompt: { + type: 'list', + message: `Which ${chalk.yellow('*type*')} of application would you like to create?`, + }, + choices: [ + { + value: APPLICATION_TYPE_MONOLITH, + name: 'Monolithic application (recommended for simple projects)', + }, + { + value: APPLICATION_TYPE_GATEWAY, + name: 'Gateway application', + }, + { + value: APPLICATION_TYPE_MICROSERVICE, + name: 'Microservice application', + }, + ], + }, + }, import: [GENERATOR_JAVA, GENERATOR_LIQUIBASE, GENERATOR_SPRING_DATA_RELATIONAL], }; From 1f0fa39071e284a6c403afa69d5fa8a9a42c192b Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Fri, 22 Sep 2023 13:11:11 -0300 Subject: [PATCH 04/10] options reorganization --- .../app/__snapshots__/generator.spec.mts.snap | 24 +++++---- generators/app/command.mts | 51 ------------------- generators/app/generator.mjs | 6 ++- generators/app/support/config.mts | 11 ++-- .../generator.mts | 4 ++ generators/client/generator.mjs | 6 ++- generators/common/command.mts | 5 ++ generators/common/generator.mjs | 17 ++++++- .../jdl/__snapshots__/generator.spec.mts.snap | 19 +++---- generators/languages/command.mts | 15 ++++-- generators/languages/index.mts | 1 + generators/server/command.mts | 34 +++++++++++++ generators/server/generator.mjs | 7 ++- 13 files changed, 115 insertions(+), 85 deletions(-) diff --git a/generators/app/__snapshots__/generator.spec.mts.snap b/generators/app/__snapshots__/generator.spec.mts.snap index b4b6cfb6d725..80a723f16ab6 100644 --- a/generators/app/__snapshots__/generator.spec.mts.snap +++ b/generators/app/__snapshots__/generator.spec.mts.snap @@ -10,22 +10,12 @@ Options: --defaults Execute jhipster with default config --skip-client Skip the client-side application generation --skip-server Skip the server-side application generation - --skip-commit-hook Skip adding husky commit hooks - --skip-user-management Skip the user management module during app generation - --skip-check-length-of-identifier Skip check the length of the identifier, only for recent Oracle databases that support 30+ characters metadata - --skip-fake-data Skip generation of fake data for development --jhi-prefix Add prefix before services, controllers and states name --entity-suffix Add suffix after entities name --dto-suffix Add suffix after dtos name - --auth Provide authentication type for the application when skipping server side generation - --db Provide DB name for the application when skipping server side generation --blueprint DEPRECATED: Specify a generator blueprint to use for the sub generators --blueprints A comma separated list of one or more generator blueprints to use for the sub generators, e.g. --blueprints kotlin,vuejs - --incremental-changelog Creates incremental database changelogs - --recreate-initial-changelog Recreate the initial database changelog based on the current config --ignore-errors Don't fail on prettier errors. - --enable-translation Enable translation - -l, --language Language to be added to application (existing languages are not removed) --pk-type Default primary key type (beta) --client-package-manager Force an unsupported client package manager --test-frameworks Test frameworks to be generated @@ -33,6 +23,11 @@ Options: --skip-install Do not automatically install dependencies (default: false) --force-install Fail on install dependencies error (default: false) --ask-answered Show prompts for already configured options (default: false) + --auth Provide authentication type for the application when skipping server side generation + --db 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 + --recreate-initial-changelog Recreate the initial database changelog based on the current config --build Provide build tool for the application when skipping server side generation --cache-provider Cache provider --enable-swagger-codegen API first development using OpenAPI-generator @@ -40,7 +35,9 @@ Options: --message-broker message broker --reactive Generate a reactive backend --search-engine 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 + --skip-fake-data Skip generation of fake data for development --websocket Provide websocket option for the application when skipping server side generation --project-version project version to use, this option is not persisted (env: JHI_PROJECT_VERSION) --jhipster-dependencies-version jhipster-dependencies version to use, this option is not persisted (env: JHIPSTER_DEPENDENCIES_VERSION) @@ -52,10 +49,14 @@ Options: --microfrontends Microfrontends to load --with-admin-ui Generate administrative user interface --prettier-tab-width Default tab width for prettier + --skip-commit-hook Skip adding husky commit hooks --skip-git Skip git repository initialization --monorepository Use monorepository --cypress-coverage Enable Cypress code coverage report generation --cypress-audit Enable cypress-audit/lighthouse report generation + --enable-translation Enable translation + -l, --language Language to be added to application (existing languages are not removed) + -n, --native-language [value] Set application native language -h, --help display help for command " `; @@ -86,6 +87,7 @@ exports[`generator - app with default config should match snapshot 1`] = ` "addSpringMilestoneRepository": false, "angularLocaleId": "en", "applicationType": "monolith", + "applicationTypeAny": true, "applicationTypeGateway": false, "applicationTypeMicroservice": false, "applicationTypeMonolith": true, @@ -638,6 +640,7 @@ exports[`generator - app with gateway should match snapshot 1`] = ` "addSpringMilestoneRepository": false, "angularLocaleId": "en", "applicationType": "gateway", + "applicationTypeAny": true, "applicationTypeGateway": true, "applicationTypeMicroservice": false, "applicationTypeMonolith": false, @@ -1190,6 +1193,7 @@ exports[`generator - app with microservice should match snapshot 1`] = ` "VUE": "vue", "addSpringMilestoneRepository": false, "applicationType": "microservice", + "applicationTypeAny": true, "applicationTypeGateway": false, "applicationTypeMicroservice": true, "applicationTypeMonolith": false, diff --git a/generators/app/command.mts b/generators/app/command.mts index a1fedb42b465..ff13ad83d31f 100644 --- a/generators/app/command.mts +++ b/generators/app/command.mts @@ -43,26 +43,6 @@ const command: JHipsterCommandDefinition = { type: Boolean, scope: 'storage', }, - skipCommitHook: { - description: 'Skip adding husky commit hooks', - type: Boolean, - scope: 'storage', - }, - skipUserManagement: { - description: 'Skip the user management module during app generation', - type: Boolean, - scope: 'storage', - }, - skipCheckLengthOfIdentifier: { - description: 'Skip check the length of the identifier, only for recent Oracle databases that support 30+ characters metadata', - type: Boolean, - scope: 'storage', - }, - skipFakeData: { - description: 'Skip generation of fake data for development', - type: Boolean, - scope: 'storage', - }, jhiPrefix: { description: 'Add prefix before services, controllers and states name', type: String, @@ -78,16 +58,6 @@ const command: JHipsterCommandDefinition = { type: String, scope: 'storage', }, - 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, - }, blueprint: { description: 'DEPRECATED: Specify a generator blueprint to use for the sub generators', type: Array, @@ -97,30 +67,10 @@ const command: JHipsterCommandDefinition = { 'A comma separated list of one or more generator blueprints to use for the sub generators, e.g. --blueprints kotlin,vuejs', type: String, }, - incrementalChangelog: { - description: 'Creates incremental database changelogs', - type: Boolean, - scope: 'storage', - }, - recreateInitialChangelog: { - description: 'Recreate the initial database changelog based on the current config', - type: Boolean, - }, ignoreErrors: { description: "Don't fail on prettier errors.", type: Boolean, }, - enableTranslation: { - description: 'Enable translation', - type: Boolean, - required: false, - scope: 'storage', - }, - language: { - alias: 'l', - description: 'Language to be added to application (existing languages are not removed)', - type: Array, - }, pkType: { description: 'Default primary key type (beta)', type: String, @@ -137,7 +87,6 @@ const command: JHipsterCommandDefinition = { }, }, configs: {}, - loadGeneratorOptions: true, import: [ GENERATOR_BOOTSTRAP, GENERATOR_SERVER, diff --git a/generators/app/generator.mjs b/generators/app/generator.mjs index e6af4d51c335..3c094b0e9a1a 100644 --- a/generators/app/generator.mjs +++ b/generators/app/generator.mjs @@ -41,6 +41,8 @@ const { MICROSERVICE } = applicationTypes; const { JHI_PREFIX, BASE_NAME, JWT_SECRET_KEY, PACKAGE_NAME, PACKAGE_FOLDER, REMEMBER_ME_KEY } = applicationOptions.OptionNames; export default class JHipsterAppGenerator extends BaseApplicationGenerator { + command = command; + async beforeQueue() { loadStoredAppOptions.call(this); @@ -65,7 +67,7 @@ export default class JHipsterAppGenerator extends BaseApplicationGenerator { } }, loadOptions() { - this.parseJHipsterCommand(command); + this.parseJHipsterCommand(this.command); }, validate() { @@ -85,7 +87,7 @@ export default class JHipsterAppGenerator extends BaseApplicationGenerator { askForInsightOptIn, async prompting({ control }) { if (control.existingProject && this.options.askAnswered !== true) return; - await this.prompt(this.prepareQuestions(command.configs)); + await this.prompt(this.prepareQuestions(this.command.configs)); }, }); } diff --git a/generators/app/support/config.mts b/generators/app/support/config.mts index 246fc9b13fb5..6f9742b76971 100644 --- a/generators/app/support/config.mts +++ b/generators/app/support/config.mts @@ -4,9 +4,11 @@ import { applicationTypes, authenticationTypes, databaseTypes, testFrameworkType import { getHipster, upperFirstCamelCase } from '../../base/support/index.mjs'; import { getDBTypeFromDBValue } from '../../server/support/index.mjs'; import detectLanguage from '../../languages/support/detect-language.mjs'; +import { loadConfig, loadDerivedConfig } from '../../../lib/internal/index.mjs'; +import serverCommand from '../../server/command.mjs'; const { GATLING, CUCUMBER, CYPRESS } = testFrameworkTypes; -const { GATEWAY, MICROSERVICE, MONOLITH } = applicationTypes; +const { GATEWAY, MONOLITH } = applicationTypes; const { JWT, OAUTH2, SESSION } = authenticationTypes; const { CASSANDRA, NO: NO_DATABASE } = databaseTypes; @@ -77,6 +79,8 @@ export const loadAppConfig = ({ application: any; useVersionPlaceholders?: boolean; }) => { + loadConfig(serverCommand.configs, { config, application }); + if (useVersionPlaceholders) { application.nodeVersion = 'NODE_VERSION'; } else { @@ -85,7 +89,6 @@ export const loadAppConfig = ({ application.jhipsterVersion = config.jhipsterVersion; application.baseName = config.baseName; - application.applicationType = config.applicationType; application.reactive = config.reactive; application.jhiPrefix = config.jhiPrefix; application.skipFakeData = config.skipFakeData; @@ -127,11 +130,9 @@ export const loadAppConfig = ({ * @param {Object} dest - destination context to use default is context */ export const loadDerivedAppConfig = ({ application }: { application: any }) => { + loadDerivedConfig(serverCommand.configs, { application }); application.jhiPrefixCapitalized = _.upperFirst(application.jhiPrefix); application.jhiPrefixDashed = _.kebabCase(application.jhiPrefix); - application.applicationTypeGateway = application.applicationType === GATEWAY; - application.applicationTypeMonolith = application.applicationType === MONOLITH; - application.applicationTypeMicroservice = application.applicationType === MICROSERVICE; // Application name modified, using each technology's conventions if (application.baseName) { diff --git a/generators/bootstrap-application-server/generator.mts b/generators/bootstrap-application-server/generator.mts index 8b25667651d0..efe9bcf768cb 100644 --- a/generators/bootstrap-application-server/generator.mts +++ b/generators/bootstrap-application-server/generator.mts @@ -47,6 +47,8 @@ import { GRADLE_VERSION } from '../gradle/constants.mjs'; import { normalizePathEnd } from '../base/support/path.mjs'; import { getFrontendAppName } from '../base/support/index.mjs'; import { getMainClassName } from '../java/support/index.mjs'; +import { loadConfig, loadDerivedConfig } from '../../lib/internal/index.mjs'; +import serverCommand from '../server/command.mjs'; export default class BoostrapApplicationServer extends BaseApplicationGenerator { constructor(args: any, options: any, features: any) { @@ -60,6 +62,7 @@ export default class BoostrapApplicationServer extends BaseApplicationGenerator get loading() { return this.asLoadingTaskGroup({ async loadApplication({ application }) { + loadConfig(serverCommand.configs, { config: this.jhipsterConfigWithDefaults, application }); loadServerConfig({ config: this.jhipsterConfigWithDefaults, application }); (application as any).gradleVersion = this.useVersionPlaceholders ? 'GRADLE_VERSION' : GRADLE_VERSION; @@ -99,6 +102,7 @@ export default class BoostrapApplicationServer extends BaseApplicationGenerator get preparing() { return this.asPreparingTaskGroup({ prepareApplication({ application }) { + loadDerivedConfig(serverCommand.configs, { application }); loadDerivedServerConfig({ application }); }, prepareForTemplates({ application: app }) { diff --git a/generators/client/generator.mjs b/generators/client/generator.mjs index ff41cf292264..cb00cee20fd5 100644 --- a/generators/client/generator.mjs +++ b/generators/client/generator.mjs @@ -41,6 +41,8 @@ const { CYPRESS } = testFrameworkTypes; * @extends {BaseApplicationGenerator} */ export default class JHipsterClientGenerator extends BaseApplicationGenerator { + command = command; + async beforeQueue() { loadStoredAppOptions.call(this); @@ -56,7 +58,7 @@ export default class JHipsterClientGenerator extends BaseApplicationGenerator { get initializing() { return this.asInitializingTaskGroup({ loadOptions() { - this.parseJHipsterCommand(command); + this.parseJHipsterCommand(this.command); }, }); } @@ -69,7 +71,7 @@ export default class JHipsterClientGenerator extends BaseApplicationGenerator { return this.asPromptingTaskGroup({ async prompting({ control }) { if (control.existingProject && this.options.askAnswered !== true) return; - await this.prompt(this.prepareQuestions(command.configs)); + await this.prompt(this.prepareQuestions(this.command.configs)); }, askForClientTestOpts, askForClientTheme, diff --git a/generators/common/command.mts b/generators/common/command.mts index cf687ae254ab..0eec88e9d2d9 100644 --- a/generators/common/command.mts +++ b/generators/common/command.mts @@ -25,6 +25,11 @@ const command: JHipsterCommandDefinition = { type: Number, scope: 'storage', }, + skipCommitHook: { + description: 'Skip adding husky commit hooks', + type: Boolean, + scope: 'storage', + }, }, }; diff --git a/generators/common/generator.mjs b/generators/common/generator.mjs index 6ccebe6664b6..cd3ad7ce2620 100644 --- a/generators/common/generator.mjs +++ b/generators/common/generator.mjs @@ -37,6 +37,8 @@ import { loadStoredAppOptions } from '../app/support/index.mjs'; const { REACT, ANGULAR } = clientFrameworkTypes; export default class CommonGenerator extends BaseApplicationGenerator { + command = command; + async beforeQueue() { loadStoredAppOptions.call(this); @@ -51,7 +53,7 @@ export default class CommonGenerator extends BaseApplicationGenerator { get initializing() { return this.asInitializingTaskGroup({ loadOptions() { - this.parseJHipsterOptions(command.options); + this.parseJHipsterCommand(this.command); }, }); } @@ -60,6 +62,19 @@ export default class CommonGenerator extends BaseApplicationGenerator { return this.delegateTasksToBlueprint(() => this.initializing); } + get prompting() { + return this.asPromptingTaskGroup({ + async prompting({ control }) { + if (control.existingProject && this.options.askAnswered !== true) return; + await this.prompt(this.prepareQuestions(this.command.configs)); + }, + }); + } + + get [BaseApplicationGenerator.PROMPTING]() { + return this.asPromptingTaskGroup(this.delegateTasksToBlueprint(() => this.prompting)); + } + // Public API method used by the getter and also by Blueprints get configuring() { return { diff --git a/generators/jdl/__snapshots__/generator.spec.mts.snap b/generators/jdl/__snapshots__/generator.spec.mts.snap index 6a9419a0cafe..840270ae41df 100644 --- a/generators/jdl/__snapshots__/generator.spec.mts.snap +++ b/generators/jdl/__snapshots__/generator.spec.mts.snap @@ -175,24 +175,19 @@ Options: --defaults Execute jhipster with default config --skip-client Skip the client-side application generation --skip-server Skip the server-side application generation - --skip-commit-hook Skip adding husky commit hooks - --skip-check-length-of-identifier Skip check the length of the identifier, only for recent Oracle databases that support 30+ characters metadata - --skip-fake-data Skip generation of fake data for development --jhi-prefix Add prefix before services, controllers and states name --entity-suffix Add suffix after entities name --dto-suffix Add suffix after dtos name - --auth Provide authentication type for the application when skipping server side generation - --db Provide DB name for the application when skipping server side generation --blueprint DEPRECATED: Specify a generator blueprint to use for the sub generators --blueprints A comma separated list of one or more generator blueprints to use for the sub generators, e.g. --blueprints kotlin,vuejs - --incremental-changelog Creates incremental database changelogs - --recreate-initial-changelog Recreate the initial database changelog based on the current config --ignore-errors Don't fail on prettier errors. - --enable-translation Enable translation - -l, --language Language to be added to application (existing languages are not removed) --pk-type Default primary key type (beta) --client-package-manager Force an unsupported client package manager --test-frameworks Test frameworks to be generated + --auth Provide authentication type for the application when skipping server side generation + --db 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 --build Provide build tool for the application when skipping server side generation --cache-provider Cache provider --enable-swagger-codegen API first development using OpenAPI-generator @@ -200,7 +195,9 @@ Options: --message-broker message broker --reactive Generate a reactive backend --search-engine 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 + --skip-fake-data Skip generation of fake data for development --websocket Provide websocket option for the application when skipping server side generation --project-version project version to use, this option is not persisted (env: JHI_PROJECT_VERSION) --jhipster-dependencies-version jhipster-dependencies version to use, this option is not persisted (env: JHIPSTER_DEPENDENCIES_VERSION) @@ -212,10 +209,14 @@ Options: --microfrontends Microfrontends to load --with-admin-ui Generate administrative user interface --prettier-tab-width Default tab width for prettier + --skip-commit-hook Skip adding husky commit hooks --skip-git Skip git repository initialization --monorepository Use monorepository --cypress-coverage Enable Cypress code coverage report generation --cypress-audit Enable cypress-audit/lighthouse report generation + --enable-translation Enable translation + -l, --language Language to be added to application (existing languages are not removed) + -n, --native-language [value] Set application native language --workspaces-folders Folders to use as monorepository workspace (default: []) --workspaces Generate workspaces for multiples applications -h, --help display help for command diff --git a/generators/languages/command.mts b/generators/languages/command.mts index 08c7f98129af..b919733dee67 100644 --- a/generators/languages/command.mts +++ b/generators/languages/command.mts @@ -27,16 +27,23 @@ const command: JHipsterCommandDefinition = { }, }, options: { + enableTranslation: { + description: 'Enable translation', + type: Boolean, + required: false, + scope: 'storage', + }, + language: { + alias: 'l', + description: 'Language to be added to application (existing languages are not removed)', + type: Array, + }, nativeLanguage: { alias: 'n', description: 'Set application native language', type: String, required: false, }, - regenerate: { - description: 'Regenerate languages files', - type: Boolean, - }, }, }; diff --git a/generators/languages/index.mts b/generators/languages/index.mts index 709452a8f58e..b98e6972347b 100644 --- a/generators/languages/index.mts +++ b/generators/languages/index.mts @@ -17,4 +17,5 @@ * limitations under the License. */ export { default } from './generator.mjs'; +export { default as command } from './command.mjs'; export { default as upgradeFilesTask } from './upgrade-files-task.mjs'; diff --git a/generators/server/command.mts b/generators/server/command.mts index 843c472570e3..71c6417b164e 100644 --- a/generators/server/command.mts +++ b/generators/server/command.mts @@ -23,6 +23,30 @@ 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, + }, + incrementalChangelog: { + description: 'Creates incremental database changelogs', + type: Boolean, + scope: 'storage', + }, + skipUserManagement: { + description: 'Skip the user management module during app generation', + type: Boolean, + scope: 'storage', + }, + recreateInitialChangelog: { + description: 'Recreate the initial database changelog based on the current config', + type: Boolean, + }, buildTool: { name: 'build', description: 'Provide build tool for the application when skipping server side generation', @@ -59,10 +83,20 @@ const command: JHipsterCommandDefinition = { type: String, scope: 'storage', }, + skipCheckLengthOfIdentifier: { + description: 'Skip check the length of the identifier, only for recent Oracle databases that support 30+ characters metadata', + type: Boolean, + scope: 'storage', + }, skipDbChangelog: { description: 'Skip the generation of database migrations', type: Boolean, }, + skipFakeData: { + description: 'Skip generation of fake data for development', + type: Boolean, + scope: 'storage', + }, websocket: { description: 'Provide websocket option for the application when skipping server side generation', type: String, diff --git a/generators/server/generator.mjs b/generators/server/generator.mjs index 1be396725d8e..ebab4b4d5e63 100644 --- a/generators/server/generator.mjs +++ b/generators/server/generator.mjs @@ -154,6 +154,7 @@ export default class JHipsterServerGenerator extends BaseApplicationGenerator { /** @type {string} */ projectVersion; fakeKeytool; + command = command; async beforeQueue() { loadStoredAppOptions.call(this); @@ -191,7 +192,7 @@ export default class JHipsterServerGenerator extends BaseApplicationGenerator { get initializing() { return this.asInitializingTaskGroup({ loadConfig() { - this.parseJHipsterCommand(command); + this.parseJHipsterCommand(this.command); }, }); } @@ -202,6 +203,10 @@ export default class JHipsterServerGenerator extends BaseApplicationGenerator { get prompting() { return this.asPromptingTaskGroup({ + async prompting({ control }) { + if (control.existingProject && this.options.askAnswered !== true) return; + await this.prompt(this.prepareQuestions(this.command.configs)); + }, askForServerTestOpts, askForServerSideOpts, askForOptionalItems, From 6ce8d1c7edc6b6f177a5f726a5b5bb5da8dd9808 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Fri, 22 Sep 2023 13:34:41 -0300 Subject: [PATCH 05/10] app generator adjusts. --- generators/app/generator.mjs | 31 ++++++++++++++---------------- generators/base-core/generator.mts | 2 +- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/generators/app/generator.mjs b/generators/app/generator.mjs index 3c094b0e9a1a..f81e64324d9a 100644 --- a/generators/app/generator.mjs +++ b/generators/app/generator.mjs @@ -121,29 +121,32 @@ export default class JHipsterAppGenerator extends BaseApplicationGenerator { * Composing with others generators, must be executed after `configuring` priority to let others * generators `configuring` priority to run. * - * Generators `server`, `client`, `common`, `languages` depends on each other. - * We are composing in the same task so every priority are executed in parallel. - * - compose (app) -> initializing (common) -> initializing (server) -> ... - * - * When composing in different tasks the result would be: + * Composing in different tasks the result would be: * - composeCommon (app) -> initializing (common) -> prompting (common) -> ... -> composeServer (app) -> initializing (server) -> ... + * + * This behaviour allows a more consistent blueprint support. */ - async compose() { - const { skipServer, skipClient } = this.jhipsterConfigWithDefaults; + async composeCommon() { await this.composeWithJHipster(GENERATOR_COMMON); - if (!skipServer) { + }, + async composeServer() { + if (!this.jhipsterConfigWithDefaults.skipServer) { await this.composeWithJHipster(GENERATOR_SERVER); } - if (!skipClient) { + }, + async composeClient() { + if (!this.jhipsterConfigWithDefaults.skipClient) { await this.composeWithJHipster(GENERATOR_CLIENT); } }, - /** * At this point every other generator should already be configured, so, enforce defaults fallback. */ saveConfigWithDefaults() { - this._validateAppConfiguration(); + const config = this.jhipsterConfigWithDefaults; + if (config.entitySuffix === config.dtoSuffix) { + throw new Error('Entities cannot be generated as the entity suffix and DTO suffix are equals !'); + } }, async composePages() { @@ -192,10 +195,4 @@ export default class JHipsterAppGenerator extends BaseApplicationGenerator { get [BaseApplicationGenerator.WRITING]() { return this.delegateTasksToBlueprint(() => this.writing); } - - _validateAppConfiguration(config = this.jhipsterConfigWithDefaults) { - if (config.entitySuffix === config.dtoSuffix) { - throw new Error('Entities cannot be generated as the entity suffix and DTO suffix are equals !'); - } - } } diff --git a/generators/base-core/generator.mts b/generators/base-core/generator.mts index 0b4d7c3a88bc..dc3cb5cf9607 100644 --- a/generators/base-core/generator.mts +++ b/generators/base-core/generator.mts @@ -332,7 +332,7 @@ export default class CoreGenerator extends YeomanGenerator def.prompt) .map(([name, def]) => { From a38f8fde504f3303ab0f198a0c46f7b5faaae699 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Fri, 22 Sep 2023 13:40:32 -0300 Subject: [PATCH 06/10] prettier fix --- generators/app/generator.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generators/app/generator.mjs b/generators/app/generator.mjs index f81e64324d9a..d19715a3008d 100644 --- a/generators/app/generator.mjs +++ b/generators/app/generator.mjs @@ -146,7 +146,7 @@ export default class JHipsterAppGenerator extends BaseApplicationGenerator { const config = this.jhipsterConfigWithDefaults; if (config.entitySuffix === config.dtoSuffix) { throw new Error('Entities cannot be generated as the entity suffix and DTO suffix are equals !'); - } + } }, async composePages() { From 61af71bd0fad49397d10d88adeb3cf11b7cf3c92 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Fri, 22 Sep 2023 13:55:33 -0300 Subject: [PATCH 07/10] don't ignore cypress generator tests --- generators/generate-blueprint/templates/vitest.config.ts.ejs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/generators/generate-blueprint/templates/vitest.config.ts.ejs b/generators/generate-blueprint/templates/vitest.config.ts.ejs index f8790202bbbf..1093baf5dd96 100644 --- a/generators/generate-blueprint/templates/vitest.config.ts.ejs +++ b/generators/generate-blueprint/templates/vitest.config.ts.ejs @@ -4,6 +4,6 @@ export default defineConfig({ test: { threads: false, hookTimeout: 15000, - exclude: [...defaultExclude, '**/templates/**', '**/resources/**'], + exclude: [...defaultExclude.filter(val => val !== '**/cypress/**'), '**/templates/**', '**/resources/**'], }, }); From d2951e5f2c226b4a7d79665ea2c51eb06e4b4e37 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Fri, 22 Sep 2023 14:04:23 -0300 Subject: [PATCH 08/10] use npm script at heroku --- generators/heroku/generator.mjs | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/generators/heroku/generator.mjs b/generators/heroku/generator.mjs index 7e8718ab80d5..fb6a20a5ed8b 100644 --- a/generators/heroku/generator.mjs +++ b/generators/heroku/generator.mjs @@ -43,7 +43,6 @@ import { mavenProfileContent } from './templates.mjs'; import { createPomStorage } from '../maven/support/pom-store.mjs'; import { addGradlePluginCallback, applyFromGradleCallback } from '../gradle/internal/needles.mjs'; import { getFrontendAppName } from '../base/support/index.mjs'; -import { buildApplication } from '../server/internal/index.mjs'; import { loadAppConfig, loadDerivedAppConfig } from '../app/support/index.mjs'; import { loadDerivedPlatformConfig, loadDerivedServerConfig, loadPlatformConfig, loadServerConfig } from '../server/support/index.mjs'; import { loadLanguagesConfig } from '../languages/support/index.mjs'; @@ -629,7 +628,7 @@ export default class HerokuGenerator extends BaseGenerator { } get end() { - return { + return this.asEndTaskGroup({ makeScriptExecutable() { if (this.abort) return; if (this.useOkta) { @@ -644,7 +643,7 @@ export default class HerokuGenerator extends BaseGenerator { } } }, - productionBuild: runAsync(function () { + async productionBuild() { if (this.abort) return; if (this.herokuSkipBuild || this.herokuDeployType === 'git') { @@ -652,23 +651,11 @@ export default class HerokuGenerator extends BaseGenerator { return; } - const done = this.async(); this.log.log(chalk.bold('\nBuilding application')); - const child = buildApplication(this.buildTool, 'prod', false, err => { - if (err) { - this.abort = true; - this.log.error(err); - } - done(); - }); - - this.buildCmd = child.buildCmd; - - child.stdout.on('data', data => { - process.stdout.write(data.toString()); - }); - }), + // Use npm script so blueprints just need to override it. + await this.spawnCommand('npm run java:jar:prod', { stdio: 'inherit' }); + }, async productionDeploy() { if (this.abort) return; @@ -889,7 +876,7 @@ export default class HerokuGenerator extends BaseGenerator { } } }, - }; + }); } get [BaseGenerator.END]() { From 53e2a6020305fff457d3e2ad1682deaf99bd82b8 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Fri, 22 Sep 2023 14:08:07 -0300 Subject: [PATCH 09/10] run info at generate-sample --- .../templates/.blueprint/generate-sample/generator.mjs.ejs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/generators/generate-blueprint/templates/.blueprint/generate-sample/generator.mjs.ejs b/generators/generate-blueprint/templates/.blueprint/generate-sample/generator.mjs.ejs index 357ba1c93110..72617afde117 100644 --- a/generators/generate-blueprint/templates/.blueprint/generate-sample/generator.mjs.ejs +++ b/generators/generate-blueprint/templates/.blueprint/generate-sample/generator.mjs.ejs @@ -54,6 +54,9 @@ export default class extends BaseGenerator { }, }); }, + async jhipsterInfo() { + await this.composeWithJHipster('info'); + }, }); } } From 4985b49c3709ce00d0be70d9dc1980a0cccec33a Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Fri, 22 Sep 2023 15:36:28 -0300 Subject: [PATCH 10/10] test adjusts --- cli/cli.spec.mts | 2 +- test/needle-api/needle-client-react-generator.spec.mts | 1 + test/needle-api/needle-client-react.spec.mts | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/cli/cli.spec.mts b/cli/cli.spec.mts index fccf7a9b109f..eb5c0924e659 100644 --- a/cli/cli.spec.mts +++ b/cli/cli.spec.mts @@ -586,7 +586,7 @@ describe('cli', () => { expect(stdout).toMatch('Usage: jhipster run jhipster:app [options]'); }); it('should print options', () => { - expect(stdout).toMatch('--application-type '); + expect(stdout).toMatch('--defaults'); }); it('should exit with code 0', () => { expect(exitCode).toBe(0); diff --git a/test/needle-api/needle-client-react-generator.spec.mts b/test/needle-api/needle-client-react-generator.spec.mts index 2117e0fd66db..b795f6875e2d 100644 --- a/test/needle-api/needle-client-react-generator.spec.mts +++ b/test/needle-api/needle-client-react-generator.spec.mts @@ -46,6 +46,7 @@ describe('needle API React: JHipster client generator with blueprint', () => { auth: 'jwt', db: 'mysql', blueprint: 'myblueprint', + ignoreNeedlesError: true, }) .withGenerators([[mockReactBlueprintSubGen, { namespace: 'jhipster-myblueprint:react' }]]) .withAnswers({ diff --git a/test/needle-api/needle-client-react.spec.mts b/test/needle-api/needle-client-react.spec.mts index f29e9884c878..4730483ff0fd 100644 --- a/test/needle-api/needle-client-react.spec.mts +++ b/test/needle-api/needle-client-react.spec.mts @@ -39,6 +39,7 @@ describe('needle API React: JHipster react generator with blueprint', () => { auth: 'jwt', db: 'mysql', blueprint: 'myblueprint', + ignoreNeedlesError: true, }) .withGenerators([[mockBlueprintSubGen, { namespace: 'jhipster-myblueprint:react' }]]) .withAnswers({