From 9289c85a32a2625b0f4e3fbc3e3f968acafa55a9 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 30 Aug 2023 07:48:41 -0300 Subject: [PATCH 1/8] remove todo methods --- generators/base/generator-base-todo.mts | 32 ------------------------- generators/liquibase/generator.mts | 32 ++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/generators/base/generator-base-todo.mts b/generators/base/generator-base-todo.mts index b9a3ba9d2a95..6a9e5dc390c1 100644 --- a/generators/base/generator-base-todo.mts +++ b/generators/base/generator-base-todo.mts @@ -20,8 +20,6 @@ import JHipsterBaseCoreGenerator from '../base-core/index.mjs'; import { formatDateForChangelog, parseCreationTimestamp } from './support/index.mjs'; import { loadLanguagesConfig } from '../languages/support/index.mjs'; import { - getFKConstraintName, - getUXConstraintName, loadDerivedPlatformConfig, loadDerivedServerConfig, loadPlatformConfig, @@ -106,36 +104,6 @@ export default abstract class JHipsterBaseGenerator extends JHipsterBaseCoreGene return formatDateForChangelog(now); } - /** - * @private - * get a foreign key constraint name for tables in JHipster preferred style. - * - * @param {string} entityName - name of the entity - * @param {string} relationshipName - name of the related entity - * @param {string} prodDatabaseType - database type - * @param {boolean} noSnakeCase - do not convert names to snakecase - */ - getFKConstraintName(entityName, relationshipName, prodDatabaseType, noSnakeCase) { - const result = getFKConstraintName(entityName, relationshipName, { prodDatabaseType, noSnakeCase }); - (this as any).validateResult(result); - return result.value; - } - - /** - * @private - * get a unique constraint name for tables in JHipster preferred style. - * - * @param {string} entityName - name of the entity - * @param {string} columnName - name of the column - * @param {string} prodDatabaseType - database type - * @param {boolean} noSnakeCase - do not convert names to snakecase - */ - getUXConstraintName(entityName, columnName, prodDatabaseType, noSnakeCase) { - const result = getUXConstraintName(entityName, columnName, { prodDatabaseType, noSnakeCase }); - (this as any).validateResult(result); - return result.value; - } - /** * Parse runtime options. * @deprecated diff --git a/generators/liquibase/generator.mts b/generators/liquibase/generator.mts index f4994b4791a0..6c943aaefe43 100644 --- a/generators/liquibase/generator.mts +++ b/generators/liquibase/generator.mts @@ -28,7 +28,7 @@ import { prepareRelationshipForLiquibase, liquibaseComment, } from './support/index.mjs'; -import { prepareEntity as prepareEntityForServer } from '../server/support/index.mjs'; +import { getFKConstraintName, getUXConstraintName, prepareEntity as prepareEntityForServer } from '../server/support/index.mjs'; import { prepareEntityPrimaryKeyForTemplates, prepareRelationship, @@ -664,4 +664,34 @@ export default class LiquibaseGenerator extends BaseEntityChangesGenerator { } return undefined; } + + /** + * @private + * get a foreign key constraint name for tables in JHipster preferred style. + * + * @param {string} entityName - name of the entity + * @param {string} relationshipName - name of the related entity + * @param {string} prodDatabaseType - database type + * @param {boolean} noSnakeCase - do not convert names to snakecase + */ + getFKConstraintName(entityName, relationshipName, prodDatabaseType, noSnakeCase) { + const result = getFKConstraintName(entityName, relationshipName, { prodDatabaseType, noSnakeCase }); + (this as any).validateResult(result); + return result.value; + } + + /** + * @private + * get a unique constraint name for tables in JHipster preferred style. + * + * @param {string} entityName - name of the entity + * @param {string} columnName - name of the column + * @param {string} prodDatabaseType - database type + * @param {boolean} noSnakeCase - do not convert names to snakecase + */ + getUXConstraintName(entityName, columnName, prodDatabaseType, noSnakeCase) { + const result = getUXConstraintName(entityName, columnName, { prodDatabaseType, noSnakeCase }); + (this as any).validateResult(result); + return result.value; + } } From 2d4134e188bea5c59bea04f8ad35fcbc108c8509 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 30 Aug 2023 07:50:05 -0300 Subject: [PATCH 2/8] todo cleanups --- .../app/__snapshots__/generator.spec.mts.snap | 1 - generators/app/generator.mjs | 6 -- generators/app/support/config.mts | 14 +--- .../generator-core.spec.mts} | 4 +- generators/base-core/generator.mts | 57 ++++++++++++++++- .../__snapshots__/generator.spec.mts.snap | 1 + generators/base/api.d.mts | 2 +- generators/base/command.mts | 6 ++ generators/base/generator-base-todo.mts | 64 ++----------------- .../jdl/__snapshots__/generator.spec.mts.snap | 1 - 10 files changed, 69 insertions(+), 87 deletions(-) rename generators/{base/generator-base-todo.spec.mts => base-core/generator-core.spec.mts} (97%) diff --git a/generators/app/__snapshots__/generator.spec.mts.snap b/generators/app/__snapshots__/generator.spec.mts.snap index 79904e559015..ad5a6dc2b7ba 100644 --- a/generators/app/__snapshots__/generator.spec.mts.snap +++ b/generators/app/__snapshots__/generator.spec.mts.snap @@ -33,7 +33,6 @@ Options: --search-engine Provide search engine 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 - --creation-timestamp Project creation timestamp (used for reproducible builds) --incremental-changelog Creates incremental database changelogs --recreate-initial-changelog Recreate the initial database changelog based on the current config --legacy-db-names Generate database names with jhipster 6 compatibility. diff --git a/generators/app/generator.mjs b/generators/app/generator.mjs index 87784daf39c3..1eada056e457 100644 --- a/generators/app/generator.mjs +++ b/generators/app/generator.mjs @@ -166,12 +166,6 @@ export default class JHipsterAppGenerator extends BaseApplicationGenerator { type: String, }); - // This adds support for a `--creation-timestamp` flag which can be used create reproducible builds - this.option('creation-timestamp', { - description: 'Project creation timestamp (used for reproducible builds)', - type: String, - }); - this.option('incremental-changelog', { description: 'Creates incremental database changelogs', type: Boolean, diff --git a/generators/app/support/config.mts b/generators/app/support/config.mts index ddd9e54b5ce5..e23cc15c4aa9 100644 --- a/generators/app/support/config.mts +++ b/generators/app/support/config.mts @@ -1,7 +1,7 @@ import _ from 'lodash'; import { NODE_VERSION } from '../../generator-constants.mjs'; import { applicationTypes, authenticationTypes, databaseTypes, testFrameworkTypes } from '../../../jdl/index.js'; -import { getHipster, parseCreationTimestamp, upperFirstCamelCase } from '../../base/support/index.mjs'; +import { getHipster, upperFirstCamelCase } from '../../base/support/index.mjs'; import { getDBTypeFromDBValue } from '../../server/support/index.mjs'; import detectLanguage from '../../languages/support/detect-language.mjs'; @@ -121,18 +121,6 @@ export const loadStoredAppOptions = ({ options, sharedData, jhipsterConfig, log } } - if (options.creationTimestamp) { - const creationTimestamp = parseCreationTimestamp(options.creationTimestamp); - if (creationTimestamp) { - sharedData.get('configOptions').creationTimestamp = creationTimestamp; - if (jhipsterConfig.creationTimestamp === undefined) { - jhipsterConfig.creationTimestamp = creationTimestamp; - } - } else { - log?.warn(`Error parsing creationTimestamp ${options.creationTimestamp}.`); - } - } - if (options.pkType) { jhipsterConfig.pkType = options.pkType; } diff --git a/generators/base/generator-base-todo.spec.mts b/generators/base-core/generator-core.spec.mts similarity index 97% rename from generators/base/generator-base-todo.spec.mts rename to generators/base-core/generator-core.spec.mts index 6f25cf84b596..691aeab84c29 100644 --- a/generators/base/generator-base-todo.spec.mts +++ b/generators/base-core/generator-core.spec.mts @@ -3,8 +3,8 @@ import { expect } from 'chai'; import { basicHelpers as helpers, result as runResult } from '../../test/support/index.mjs'; import Base from './index.mjs'; -import { parseChangelog } from './support/timestamp.mjs'; -import { createJHipsterLogger } from './support/logger.mjs'; +import { parseChangelog } from '../base/support/timestamp.mjs'; +import { createJHipsterLogger } from '../base/support/logger.mjs'; const BaseGenerator: any = Base.prototype; diff --git a/generators/base-core/generator.mts b/generators/base-core/generator.mts index 66dc7e99254d..fdb3e48d2fe6 100644 --- a/generators/base-core/generator.mts +++ b/generators/base-core/generator.mts @@ -33,7 +33,7 @@ import YeomanGenerator, { type ComposeOptions, type Storage } from 'yeoman-gener import latestVersion from 'latest-version'; import SharedData from '../base/shared-data.mjs'; import { CUSTOM_PRIORITIES, PRIORITY_NAMES, PRIORITY_PREFIX } from '../base/priorities.mjs'; -import { createJHipster7Context, joinCallbacks, Logger } from '../base/support/index.mjs'; +import { createJHipster7Context, formatDateForChangelog, joinCallbacks, Logger } from '../base/support/index.mjs'; import type { JHipsterGeneratorOptions, @@ -141,12 +141,14 @@ export default class CoreGenerator extends YeomanGenerator lastLiquibaseTimestamp) { + this.config.set('lastLiquibaseTimestamp', now.getTime()); + } + } else { + // Get and store lastLiquibaseTimestamp, a future timestamp can be used + let lastLiquibaseTimestamp = this.jhipsterConfig.lastLiquibaseTimestamp; + if (lastLiquibaseTimestamp) { + lastLiquibaseTimestamp = new Date(lastLiquibaseTimestamp); + if (lastLiquibaseTimestamp >= now) { + now = lastLiquibaseTimestamp; + now.setSeconds(now.getSeconds() + 1); + now.setMilliseconds(0); + } + } + this.jhipsterConfig.lastLiquibaseTimestamp = now.getTime(); + } + return formatDateForChangelog(now); + } + /** * Alternative templatePath that fetches from the blueprinted generator, instead of the blueprint. */ diff --git a/generators/base/__snapshots__/generator.spec.mts.snap b/generators/base/__snapshots__/generator.spec.mts.snap index 384df4c6c265..db921ed105a9 100644 --- a/generators/base/__snapshots__/generator.spec.mts.snap +++ b/generators/base/__snapshots__/generator.spec.mts.snap @@ -19,6 +19,7 @@ Options: --experimental Enable experimental features. Please note that these features may be unstable and may undergo breaking changes at any time -d, --debug Enable debugger --skip-jhipster-dependencies Don't write jhipster dependencies to package.json. + --creation-timestamp Project creation timestamp (used for reproducible builds) -h, --help display help for command Commands: diff --git a/generators/base/api.d.mts b/generators/base/api.d.mts index 9757eab7b7b7..490be6af0ad0 100644 --- a/generators/base/api.d.mts +++ b/generators/base/api.d.mts @@ -11,6 +11,7 @@ export type ApplicationWithConfig = { export type JHipsterGeneratorOptions = BaseOptions & { applicationWithConfig?: ApplicationWithConfig; + creationTimestamp?: string; positionalArguments?: unknown[]; jhipsterContext?: any; skipYoResolve?: boolean; @@ -19,7 +20,6 @@ export type JHipsterGeneratorOptions = BaseOptions & { applicationWithEntities?: any; blueprints?: string; blueprint?: any; - configOptions: any; reproducible?: boolean; applicationId?: string; sharedData: any; diff --git a/generators/base/command.mts b/generators/base/command.mts index bcf0536a7c3a..b81df9915251 100644 --- a/generators/base/command.mts +++ b/generators/base/command.mts @@ -17,6 +17,7 @@ * limitations under the License. */ import { JHipsterCommandDefinition } from '../base/api.mjs'; +import { parseCreationTimestamp } from './support/timestamp.mjs'; const command: JHipsterCommandDefinition = { options: { @@ -50,6 +51,11 @@ const command: JHipsterCommandDefinition = { type: Boolean, scope: 'storage', }, + creationTimestamp: { + description: 'Project creation timestamp (used for reproducible builds)', + type: parseCreationTimestamp, + scope: 'storage', + }, }, }; diff --git a/generators/base/generator-base-todo.mts b/generators/base/generator-base-todo.mts index 6a9e5dc390c1..05d4382b211e 100644 --- a/generators/base/generator-base-todo.mts +++ b/generators/base/generator-base-todo.mts @@ -17,7 +17,7 @@ * limitations under the License. */ import JHipsterBaseCoreGenerator from '../base-core/index.mjs'; -import { formatDateForChangelog, parseCreationTimestamp } from './support/index.mjs'; +import { parseCreationTimestamp } from './support/index.mjs'; import { loadLanguagesConfig } from '../languages/support/index.mjs'; import { loadDerivedPlatformConfig, @@ -57,53 +57,6 @@ export default abstract class JHipsterBaseGenerator extends JHipsterBaseCoreGene this.needleApi.clientWebpack.addWebpackConfig(config, clientFramework); } - /** - * Generate a date to be used by Liquibase changelogs. - * - * @param {Boolean} [reproducible=true] - Set true if the changelog date can be reproducible. - * Set false to create a changelog date incrementing the last one. - * @return {String} Changelog date. - */ - dateFormatForLiquibase(reproducible = this.sharedData.get('configOptions').reproducible) { - const configOptions = this.sharedData.get('configOptions'); - let now = new Date(); - // Miliseconds is ignored for changelogDate. - now.setMilliseconds(0); - // Run reproducible timestamp when regenerating the project with with-entities option. - if (reproducible || configOptions.creationTimestamp) { - if (configOptions.reproducibleLiquibaseTimestamp) { - // Counter already started. - now = configOptions.reproducibleLiquibaseTimestamp; - } else { - // Create a new counter - const creationTimestamp = configOptions.creationTimestamp || this.config.get('creationTimestamp'); - now = creationTimestamp ? new Date(creationTimestamp) : now; - now.setMilliseconds(0); - } - now.setMinutes(now.getMinutes() + 1); - configOptions.reproducibleLiquibaseTimestamp = now; - - // Reproducible build can create future timestamp, save it. - const lastLiquibaseTimestamp = this.jhipsterConfig.lastLiquibaseTimestamp; - if (!lastLiquibaseTimestamp || now.getTime() > lastLiquibaseTimestamp) { - this.config.set('lastLiquibaseTimestamp', now.getTime()); - } - } else { - // Get and store lastLiquibaseTimestamp, a future timestamp can be used - let lastLiquibaseTimestamp = this.jhipsterConfig.lastLiquibaseTimestamp; - if (lastLiquibaseTimestamp) { - lastLiquibaseTimestamp = new Date(lastLiquibaseTimestamp); - if (lastLiquibaseTimestamp >= now) { - now = lastLiquibaseTimestamp; - now.setSeconds(now.getSeconds() + 1); - now.setMilliseconds(0); - } - } - this.jhipsterConfig.lastLiquibaseTimestamp = now.getTime(); - } - return formatDateForChangelog(now); - } - /** * Parse runtime options. * @deprecated @@ -115,22 +68,16 @@ export default abstract class JHipsterBaseGenerator extends JHipsterBaseCoreGene if (options.debug !== undefined) { dest.isDebugEnabled = options.debug; } - if (options.skipPrompts !== undefined) { - dest.skipPrompts = options.skipPrompts; - } - if (options.skipClient !== undefined) { - dest.skipClient = options.skipClient; - } - if (dest.creationTimestamp === undefined && options.creationTimestamp) { + if (this.sharedData.get('creationTimestamp') === undefined && options.creationTimestamp) { const creationTimestamp = parseCreationTimestamp(options.creationTimestamp); if (creationTimestamp) { - dest.creationTimestamp = creationTimestamp; + this.sharedData.set('creationTimestamp', creationTimestamp); } else { this.log.warn(`Error parsing creationTimestamp ${options.creationTimestamp}.`); } } if (options.reproducible !== undefined) { - dest.reproducible = options.reproducible; + this.sharedData.set('reproducible', options.reproducible); } } @@ -149,9 +96,6 @@ export default abstract class JHipsterBaseGenerator extends JHipsterBaseCoreGene loadRuntimeOptions(config = this.sharedData.get('configOptions'), dest: any = this) { dest.withEntities = config.withEntities; dest.isDebugEnabled = config.isDebugEnabled; - dest.logo = config.logo; - config.backendName = config.backendName || 'Java'; - dest.backendName = config.backendName; } /** diff --git a/generators/jdl/__snapshots__/generator.spec.mts.snap b/generators/jdl/__snapshots__/generator.spec.mts.snap index 6fb9ecc1e400..425417ba69c1 100644 --- a/generators/jdl/__snapshots__/generator.spec.mts.snap +++ b/generators/jdl/__snapshots__/generator.spec.mts.snap @@ -195,7 +195,6 @@ Options: --search-engine Provide search engine 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 - --creation-timestamp Project creation timestamp (used for reproducible builds) --incremental-changelog Creates incremental database changelogs --recreate-initial-changelog Recreate the initial database changelog based on the current config --legacy-db-names Generate database names with jhipster 6 compatibility. From 2d11e54c821f814579406233f7e39f062bd5a636 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 30 Aug 2023 09:02:27 -0300 Subject: [PATCH 3/8] cleanup --- generators/base/generator-base-todo.mts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/generators/base/generator-base-todo.mts b/generators/base/generator-base-todo.mts index 05d4382b211e..48e58dfcc571 100644 --- a/generators/base/generator-base-todo.mts +++ b/generators/base/generator-base-todo.mts @@ -65,9 +65,6 @@ export default abstract class JHipsterBaseGenerator extends JHipsterBaseCoreGene if (options.withEntities !== undefined) { dest.withEntities = options.withEntities; } - if (options.debug !== undefined) { - dest.isDebugEnabled = options.debug; - } if (this.sharedData.get('creationTimestamp') === undefined && options.creationTimestamp) { const creationTimestamp = parseCreationTimestamp(options.creationTimestamp); if (creationTimestamp) { @@ -95,7 +92,6 @@ export default abstract class JHipsterBaseGenerator extends JHipsterBaseCoreGene */ loadRuntimeOptions(config = this.sharedData.get('configOptions'), dest: any = this) { dest.withEntities = config.withEntities; - dest.isDebugEnabled = config.isDebugEnabled; } /** From 231e9a29d6d9778bd1152f611cb928345557c730 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 30 Aug 2023 09:12:16 -0300 Subject: [PATCH 4/8] more cleanups --- generators/base/generator-base-todo.mts | 32 ------------------- generators/docker/generator.mjs | 23 +++++++++++++ generators/kubernetes-helm/generator.mjs | 23 +++++++++++++ generators/kubernetes-knative/generator.mjs | 12 +++++++ generators/kubernetes/generator.mjs | 23 +++++++++++++ generators/openshift/generator.mjs | 12 +++++++ .../spring-data-relational/generator.mts | 23 +++++++++++++ 7 files changed, 116 insertions(+), 32 deletions(-) diff --git a/generators/base/generator-base-todo.mts b/generators/base/generator-base-todo.mts index 48e58dfcc571..70770802e57c 100644 --- a/generators/base/generator-base-todo.mts +++ b/generators/base/generator-base-todo.mts @@ -17,7 +17,6 @@ * limitations under the License. */ import JHipsterBaseCoreGenerator from '../base-core/index.mjs'; -import { parseCreationTimestamp } from './support/index.mjs'; import { loadLanguagesConfig } from '../languages/support/index.mjs'; import { loadDerivedPlatformConfig, @@ -26,7 +25,6 @@ import { loadServerAndPlatformConfig, loadServerConfig, } from '../server/support/index.mjs'; -import { getJdbcUrl, getR2dbcUrl } from '../spring-data-relational/support/index.mjs'; import { loadClientConfig, loadDerivedClientConfig } from '../client/support/index.mjs'; import { loadAppConfig, loadDerivedAppConfig, loadStoredAppOptions } from '../app/support/index.mjs'; @@ -65,14 +63,6 @@ export default abstract class JHipsterBaseGenerator extends JHipsterBaseCoreGene if (options.withEntities !== undefined) { dest.withEntities = options.withEntities; } - if (this.sharedData.get('creationTimestamp') === undefined && options.creationTimestamp) { - const creationTimestamp = parseCreationTimestamp(options.creationTimestamp); - if (creationTimestamp) { - this.sharedData.set('creationTimestamp', creationTimestamp); - } else { - this.log.warn(`Error parsing creationTimestamp ${options.creationTimestamp}.`); - } - } if (options.reproducible !== undefined) { this.sharedData.set('reproducible', options.reproducible); } @@ -166,26 +156,4 @@ export default abstract class JHipsterBaseGenerator extends JHipsterBaseCoreGene loadDerivedPlatformConfig({ application }); (this as any).loadServerAndPlatformConfig(application); } - - /** - * @private - * Returns the JDBC URL for a databaseType - * - * @param {string} databaseType - * @param {*} options: databaseName, and required infos that depends of databaseType (hostname, localDirectory, ...) - */ - getJDBCUrl(databaseType, options = {}) { - return getJdbcUrl(databaseType, options); - } - - /** - * @private - * Returns the R2DBC URL for a databaseType - * - * @param {string} databaseType - * @param {*} options: databaseName, and required infos that depends of databaseType (hostname, localDirectory, ...) - */ - getR2DBCUrl(databaseType, options = {}) { - return getR2dbcUrl(databaseType, options); - } } diff --git a/generators/docker/generator.mjs b/generators/docker/generator.mjs index 66f3d046c53f..4c3a345fa3c8 100644 --- a/generators/docker/generator.mjs +++ b/generators/docker/generator.mjs @@ -23,6 +23,7 @@ import { GENERATOR_BOOTSTRAP_APPLICATION_SERVER, GENERATOR_DOCKER } from '../gen import { dockerFiles } from './files.mjs'; import { SERVICE_COMPLETED_SUCCESSFULLY, SERVICE_HEALTHY } from './constants.mjs'; import { stringHashCode, createFaker } from '../base/support/index.mjs'; +import { getJdbcUrl, getR2dbcUrl } from '../spring-data-relational/support/index.mjs'; export default class DockerGenerator extends BaseApplicationGenerator { hasServicesFile = false; @@ -239,4 +240,26 @@ export default class DockerGenerator extends BaseApplicationGenerator { get [BaseApplicationGenerator.POST_WRITING]() { return this.asPostWritingTaskGroup(this.delegateToBlueprint ? {} : this.postWriting); } + + /** + * @private + * Returns the JDBC URL for a databaseType + * + * @param {string} databaseType + * @param {*} options: databaseName, and required infos that depends of databaseType (hostname, localDirectory, ...) + */ + getJDBCUrl(databaseType, options = {}) { + return getJdbcUrl(databaseType, options); + } + + /** + * @private + * Returns the R2DBC URL for a databaseType + * + * @param {string} databaseType + * @param {*} options: databaseName, and required infos that depends of databaseType (hostname, localDirectory, ...) + */ + getR2DBCUrl(databaseType, options = {}) { + return getR2dbcUrl(databaseType, options); + } } diff --git a/generators/kubernetes-helm/generator.mjs b/generators/kubernetes-helm/generator.mjs index cde501d40c8a..2dd18a475d79 100644 --- a/generators/kubernetes-helm/generator.mjs +++ b/generators/kubernetes-helm/generator.mjs @@ -37,6 +37,7 @@ import { } from '../kubernetes/kubernetes-base.mjs'; import statistics from '../statistics.mjs'; import { messageBrokerTypes } from '../../jdl/jhipster/index.mjs'; +import { getJdbcUrl, getR2dbcUrl } from '../spring-data-relational/support/index.mjs'; const { KAFKA } = messageBrokerTypes; @@ -190,4 +191,26 @@ export default class KubernetesHelmGenerator extends BaseDockerGenerator { get [BaseDockerGenerator.END]() { return this.delegateTasksToBlueprint(() => this.end); } + + /** + * @private + * Returns the JDBC URL for a databaseType + * + * @param {string} databaseType + * @param {*} options: databaseName, and required infos that depends of databaseType (hostname, localDirectory, ...) + */ + getJDBCUrl(databaseType, options = {}) { + return getJdbcUrl(databaseType, options); + } + + /** + * @private + * Returns the R2DBC URL for a databaseType + * + * @param {string} databaseType + * @param {*} options: databaseName, and required infos that depends of databaseType (hostname, localDirectory, ...) + */ + getR2DBCUrl(databaseType, options = {}) { + return getR2dbcUrl(databaseType, options); + } } diff --git a/generators/kubernetes-knative/generator.mjs b/generators/kubernetes-knative/generator.mjs index 92f2648c4bd6..32d3c01b7dab 100644 --- a/generators/kubernetes-knative/generator.mjs +++ b/generators/kubernetes-knative/generator.mjs @@ -39,6 +39,7 @@ import { } from '../kubernetes/kubernetes-base.mjs'; import statistics from '../statistics.mjs'; import { kubernetesPlatformTypes, buildToolTypes, messageBrokerTypes } from '../../jdl/jhipster/index.mjs'; +import { getJdbcUrl } from '../spring-data-relational/support/index.mjs'; const { GeneratorTypes } = kubernetesPlatformTypes; const { MAVEN } = buildToolTypes; @@ -241,4 +242,15 @@ export default class KubernetesKnativeGenerator extends BaseDockerGenerator { get [BaseDockerGenerator.END]() { return this.delegateTasksToBlueprint(() => this.end); } + + /** + * @private + * Returns the JDBC URL for a databaseType + * + * @param {string} databaseType + * @param {*} options: databaseName, and required infos that depends of databaseType (hostname, localDirectory, ...) + */ + getJDBCUrl(databaseType, options = {}) { + return getJdbcUrl(databaseType, options); + } } diff --git a/generators/kubernetes/generator.mjs b/generators/kubernetes/generator.mjs index c55397789b7f..9ee89088eef6 100644 --- a/generators/kubernetes/generator.mjs +++ b/generators/kubernetes/generator.mjs @@ -36,6 +36,7 @@ import { setupKubernetesConstants, derivedKubernetesPlatformProperties, } from './kubernetes-base.mjs'; +import { getJdbcUrl, getR2dbcUrl } from '../spring-data-relational/support/index.mjs'; const { KAFKA } = messageBrokerTypes; const { MAVEN } = buildToolTypes; @@ -219,4 +220,26 @@ export default class KubernetesGenerator extends BaseDockerGenerator { get [BaseDockerGenerator.END]() { return this.delegateTasksToBlueprint(() => this.end); } + + /** + * @private + * Returns the JDBC URL for a databaseType + * + * @param {string} databaseType + * @param {*} options: databaseName, and required infos that depends of databaseType (hostname, localDirectory, ...) + */ + getJDBCUrl(databaseType, options = {}) { + return getJdbcUrl(databaseType, options); + } + + /** + * @private + * Returns the R2DBC URL for a databaseType + * + * @param {string} databaseType + * @param {*} options: databaseName, and required infos that depends of databaseType (hostname, localDirectory, ...) + */ + getR2DBCUrl(databaseType, options = {}) { + return getR2dbcUrl(databaseType, options); + } } diff --git a/generators/openshift/generator.mjs b/generators/openshift/generator.mjs index 07f79961e112..b2867e3d1077 100644 --- a/generators/openshift/generator.mjs +++ b/generators/openshift/generator.mjs @@ -39,6 +39,7 @@ import { serviceDiscoveryTypes, } from '../../jdl/jhipster/index.mjs'; import { writeFiles } from './files.mjs'; +import { getJdbcUrl } from '../spring-data-relational/support/index.mjs'; const { KAFKA } = messageBrokerTypes; const { PROMETHEUS } = monitoringTypes; @@ -288,4 +289,15 @@ export default class OpenshiftGenerator extends BaseDockerGenerator { dest.storageTypeEphemeral = dest.storageType === EPHEMERAL; dest.storageTypePersistent = dest.storageType === PERSISTENT; } + + /** + * @private + * Returns the JDBC URL for a databaseType + * + * @param {string} databaseType + * @param {*} options: databaseName, and required infos that depends of databaseType (hostname, localDirectory, ...) + */ + getJDBCUrl(databaseType, options = {}) { + return getJdbcUrl(databaseType, options); + } } diff --git a/generators/spring-data-relational/generator.mts b/generators/spring-data-relational/generator.mts index a4daf040ec75..de74edf100a0 100644 --- a/generators/spring-data-relational/generator.mts +++ b/generators/spring-data-relational/generator.mts @@ -34,6 +34,7 @@ import { getReactiveMavenDefinition, } from './internal/dependencies.mjs'; import { hibernateSnakeCase } from '../server/support/string.mjs'; +import { getJdbcUrl, getR2dbcUrl } from './support/index.mjs'; const { SQL } = databaseTypes; @@ -161,4 +162,26 @@ export default class SqlGenerator extends BaseApplicationGenerator Date: Wed, 30 Aug 2023 10:18:43 -0300 Subject: [PATCH 5/8] reimplement addEntityTranslationKey needle --- generators/base-application/generator.mts | 3 +- generators/base-core/generator.mts | 9 ++ generators/base/generator-base-todo.mts | 12 --- .../client/needle-api/needle-client-i18n.mts | 42 --------- .../__snapshots__/generator.spec.mts.snap | 86 +++++++++++++++++++ generators/languages/entity-files.mjs | 4 - .../languages/generator-needles.spec.mts | 25 +++--- generators/languages/generator.mjs | 40 ++++++++- generators/languages/types.d.ts | 7 ++ generators/needle-api.mjs | 2 - 10 files changed, 153 insertions(+), 77 deletions(-) delete mode 100644 generators/client/needle-api/needle-client-i18n.mts rename test/needle-api/needle-client-i18n.spec.mts => generators/languages/generator-needles.spec.mts (65%) create mode 100644 generators/languages/types.d.ts diff --git a/generators/base-application/generator.mts b/generators/base-application/generator.mts index e1ab9a0b2c42..f566e3357d4b 100644 --- a/generators/base-application/generator.mts +++ b/generators/base-application/generator.mts @@ -28,6 +28,7 @@ import type { BaseApplication, CommonClientServerApplication } from './types.mjs import { getEntitiesFromDir } from './support/index.mjs'; import { SpringBootSourceType } from '../server/types.mjs'; import { ClientSourceType } from '../client/types.mjs'; +import { LanguageSourceType } from '../languages/types.js'; const { upperFirst } = _; @@ -63,7 +64,7 @@ const { const asPriority = BaseGenerator.asPriority; -export type BaseApplicationSource = Record any> & SpringBootSourceType & ClientSourceType; +export type BaseApplicationSource = Record any> & SpringBootSourceType & ClientSourceType & LanguageSourceType; export type JHipsterApplication = BaseApplication & Partial; diff --git a/generators/base-core/generator.mts b/generators/base-core/generator.mts index fdb3e48d2fe6..1e85f0fa8110 100644 --- a/generators/base-core/generator.mts +++ b/generators/base-core/generator.mts @@ -864,6 +864,15 @@ templates: ${JSON.stringify(existingTemplates, null, 2)}`; }); } + /** + * Merge value to an existing json and write to destination + */ + mergeDestinationJson(filepath: string, value: Record) { + this.editFile(filepath, { create: true }, content => { + return JSON.stringify(merge(content ? JSON.parse(content) : {}, value), null, 2); + }); + } + /** * Shallow clone or convert dependencies to placeholder if needed. */ diff --git a/generators/base/generator-base-todo.mts b/generators/base/generator-base-todo.mts index 70770802e57c..aaa0f8b04ee7 100644 --- a/generators/base/generator-base-todo.mts +++ b/generators/base/generator-base-todo.mts @@ -34,18 +34,6 @@ import { loadAppConfig, loadDerivedAppConfig, loadStoredAppOptions } from '../ap export default abstract class JHipsterBaseGenerator extends JHipsterBaseCoreGenerator { abstract get jhipsterConfigWithDefaults(): any; - /** - * @private - * Add a new entity in the "global.json" translations. - * - * @param {string} key - Key for the entity name - * @param {string} value - Default translated value - * @param {string} language - The language to which this translation should be added - */ - addEntityTranslationKey(key, value, language, webappSrcDir = this.sharedData.getApplication().clientSrcDir) { - this.needleApi.clientI18n.addEntityTranslationKey(key, value, language, webappSrcDir); - } - /** * Add webpack config. * diff --git a/generators/client/needle-api/needle-client-i18n.mts b/generators/client/needle-api/needle-client-i18n.mts deleted file mode 100644 index c0ad7b8cae68..000000000000 --- a/generators/client/needle-api/needle-client-i18n.mts +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright 2013-2023 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 needleClient from './needle-client.mjs'; - -export default class extends needleClient { - addEntityTranslationKey(key: string, value: string, language: string, webappSrcDir: string) { - const errorMessage = ' not added as a new entity in the menu.'; - this._addTranslationKey(key, value, language, errorMessage, 'jhipster-needle-menu-add-entry', webappSrcDir); - } - - _addTranslationKey( - key: string, - value: string, - language: string, - errorMessage: string, - needle: string, - webappSrcDir: string = this.clientSrcDir, - ) { - const fullErrorMessage = `${chalk.yellow(' Reference to ') + language} ${chalk.yellow(errorMessage)}`; - const fullPath = `${webappSrcDir}i18n/${language}/global.json`; - const rewriteFileModel = this.generateFileModel(fullPath, needle, `"${key}": "${value}",`); - - this.addBlockContentToFile(rewriteFileModel, fullErrorMessage); - } -} diff --git a/generators/entities/__snapshots__/generator.spec.mts.snap b/generators/entities/__snapshots__/generator.spec.mts.snap index d131186567c9..5678859c9926 100644 --- a/generators/entities/__snapshots__/generator.spec.mts.snap +++ b/generators/entities/__snapshots__/generator.spec.mts.snap @@ -322,6 +322,38 @@ exports[`generator - entities regenerating all entities should match source call "relationships": [], }, ], + "addEntityTranslationKey": [ + { + "language": "en", + "translationKey": "foo", + "translationValue": "Foo", + }, + { + "language": "fr", + "translationKey": "foo", + "translationValue": "Foo", + }, + { + "language": "en", + "translationKey": "bar", + "translationValue": "Bar", + }, + { + "language": "fr", + "translationKey": "bar", + "translationValue": "Bar", + }, + { + "language": "en", + "translationKey": "skip", + "translationValue": "Skip", + }, + { + "language": "fr", + "translationKey": "skip", + "translationValue": "Skip", + }, + ], "addLiquibaseChangelog": [ { "changelogName": "20160926101210_added_entity_Foo", @@ -661,6 +693,38 @@ exports[`generator - entities regenerating selected entities with writeEveryEnti "relationships": [], }, ], + "addEntityTranslationKey": [ + { + "language": "en", + "translationKey": "foo", + "translationValue": "Foo", + }, + { + "language": "fr", + "translationKey": "foo", + "translationValue": "Foo", + }, + { + "language": "en", + "translationKey": "bar", + "translationValue": "Bar", + }, + { + "language": "fr", + "translationKey": "bar", + "translationValue": "Bar", + }, + { + "language": "en", + "translationKey": "skip", + "translationValue": "Skip", + }, + { + "language": "fr", + "translationKey": "skip", + "translationValue": "Skip", + }, + ], "addLiquibaseChangelog": [ { "changelogName": "20160926101210_added_entity_Foo", @@ -905,6 +969,28 @@ exports[`generator - entities regenerating some entities should match source cal "relationships": [], }, ], + "addEntityTranslationKey": [ + { + "language": "en", + "translationKey": "foo", + "translationValue": "Foo", + }, + { + "language": "fr", + "translationKey": "foo", + "translationValue": "Foo", + }, + { + "language": "en", + "translationKey": "bar", + "translationValue": "Bar", + }, + { + "language": "fr", + "translationKey": "bar", + "translationValue": "Bar", + }, + ], "addLiquibaseChangelog": [ { "changelogName": "20160926101210_added_entity_Foo", diff --git a/generators/languages/entity-files.mjs b/generators/languages/entity-files.mjs index fe08dc1a2a21..5f90ebeae017 100644 --- a/generators/languages/entity-files.mjs +++ b/generators/languages/entity-files.mjs @@ -16,11 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import _ from 'lodash'; import { getEnumInfo } from '../base-application/support/index.mjs'; -const { startCase } = _; - /** * The default is to use a file path string. It implies use of the template method. * For any other config an object { file:.., method:.., template:.. } can be used @@ -91,7 +88,6 @@ export function writeEntityFiles() { for (const entity of entitiesToWriteTranslationFor) { for (const lang of this.languagesToApply) { await this.writeFiles({ sections: entityClientI18nFiles, context: { ...entity, clientSrcDir, frontendAppName, lang } }); - this.addEntityTranslationKey(entity.entityTranslationKeyMenu, entity.entityClassHumanized || startCase(entity.entityClass), lang); } } }, diff --git a/test/needle-api/needle-client-i18n.spec.mts b/generators/languages/generator-needles.spec.mts similarity index 65% rename from test/needle-api/needle-client-i18n.spec.mts rename to generators/languages/generator-needles.spec.mts index 7ce256fc0927..f27cd24e2a13 100644 --- a/test/needle-api/needle-client-i18n.spec.mts +++ b/generators/languages/generator-needles.spec.mts @@ -1,8 +1,8 @@ -import { defaultHelpers as helpers, result as runResult } from '../support/helpers.mjs'; +import { defaultHelpers as helpers, result as runResult } from '../../test/support/helpers.mjs'; -import LanguagesGenerator from '../../generators/languages/index.mjs'; -import { CLIENT_MAIN_SRC_DIR } from '../../generators/generator-constants.mjs'; -import { getGenerator } from '../support/index.mjs'; +import LanguagesGenerator from './index.mjs'; +import { CLIENT_MAIN_SRC_DIR } from '../generator-constants.mjs'; +import { getGenerator } from '../../test/support/index.mjs'; const generatorPath = getGenerator('languages'); @@ -18,14 +18,13 @@ const mockBlueprintSubGen: any = class extends LanguagesGenerator { this.sbsBlueprint = true; } - get [LanguagesGenerator.WRITING]() { - const customPhaseSteps = { - addEntityTranslationKey() { - this.addEntityTranslationKey('my_entity_key', 'My Entity Value', 'en'); - this.addEntityTranslationKey('ma_cle_entite', 'Ma Valeur Entite', 'fr'); + get [LanguagesGenerator.POST_WRITING]() { + return this.asPostWritingTaskGroup({ + addEntityTranslationKey({ source }) { + source.addEntityTranslationKey?.({ translationKey: 'my_entity_key', translationValue: 'My Entity Value', language: 'en' }); + source.addEntityTranslationKey?.({ translationKey: 'ma_cle_entite', translationValue: 'Ma Valeur Entite', language: 'fr' }); }, - }; - return { ...customPhaseSteps }; + }); } }; @@ -47,10 +46,10 @@ describe('needle API i18n: JHipster language generator with blueprint', () => { }); it('Assert english entity global.json contain the new key', () => { - runResult.assertFileContent(`${CLIENT_MAIN_SRC_DIR}i18n/en/global.json`, '"my_entity_key": "My Entity Value",'); + runResult.assertFileContent(`${CLIENT_MAIN_SRC_DIR}i18n/en/global.json`, '"my_entity_key": "My Entity Value"'); }); it('Assert french entity global.json contain the new key', () => { - runResult.assertFileContent(`${CLIENT_MAIN_SRC_DIR}i18n/fr/global.json`, '"ma_cle_entite": "Ma Valeur Entite",'); + runResult.assertFileContent(`${CLIENT_MAIN_SRC_DIR}i18n/fr/global.json`, '"ma_cle_entite": "Ma Valeur Entite"'); }); }); diff --git a/generators/languages/generator.mjs b/generators/languages/generator.mjs index 6d2958d5e896..de2817c4d59d 100644 --- a/generators/languages/generator.mjs +++ b/generators/languages/generator.mjs @@ -35,6 +35,8 @@ import { updateLanguagesTask as updateLanguagesInJava } from '../server/support/ import { SERVER_MAIN_RES_DIR, SERVER_TEST_RES_DIR } from '../generator-constants.mjs'; import upgradeFilesTask from './upgrade-files-task.mjs'; +const { startCase } = _; + /** * This is the base class for a generator that generates entities. * @@ -208,17 +210,29 @@ export default class LanguagesGenerator extends BaseApplicationGenerator { // Public API method used by the getter and also by Blueprints get preparing() { - return { - prepareForTemplates({ application }) { + return this.asPreparingTaskGroup({ + prepareForTemplates({ application, source }) { if (application.enableTranslation) { if (this.options.regenerate) { this.languagesToApply = application.languages; } else { this.languagesToApply = [...new Set(this.languagesToApply || [])]; } + + source.addEntityTranslationKey = ({ translationKey, translationValue, language }) => { + this.mergeDestinationJson(`${application.clientSrcDir}i18n/${language}/global.json`, { + global: { + menu: { + entities: { + [translationKey]: translationValue, + }, + }, + }, + }); + }; } }, - }; + }); } get [BaseApplicationGenerator.PREPARING]() { @@ -360,6 +374,26 @@ export default class LanguagesGenerator extends BaseApplicationGenerator { return this.delegateTasksToBlueprint(() => this.postWriting); } + get postWritingEntities() { + return this.asPostWritingEntitiesTaskGroup({ + addEntities({ entities, source }) { + for (const entity of entities.filter(entity => !entity.skipClient && !entity.builtIn)) { + for (const language of this.languagesToApply) { + source.addEntityTranslationKey?.({ + language, + translationKey: entity.entityTranslationKeyMenu, + translationValue: entity.entityClassHumanized ?? startCase(entity.entityClass), + }); + } + } + }, + }); + } + + get [BaseApplicationGenerator.POST_WRITING_ENTITIES]() { + return this.delegateTasksToBlueprint(() => this.postWritingEntities); + } + migrateLanguages(languagesToMigrate) { const { languages, nativeLanguage } = this.jhipsterConfig; if (languagesToMigrate[nativeLanguage]) { diff --git a/generators/languages/types.d.ts b/generators/languages/types.d.ts new file mode 100644 index 000000000000..aab8aa8131fb --- /dev/null +++ b/generators/languages/types.d.ts @@ -0,0 +1,7 @@ +export type LanguageSourceType = { + /** + * Add a new entity in the "global.json" translations. + * @param args + */ + addEntityTranslationKey?(args: { translationKey: string; translationValue: string; language: string }): void; +}; diff --git a/generators/needle-api.mjs b/generators/needle-api.mjs index 2da91c55faa3..bd1b33ec1186 100644 --- a/generators/needle-api.mjs +++ b/generators/needle-api.mjs @@ -22,7 +22,6 @@ import ClientAngular from './angular/needle-api/needle-client-angular.mjs'; import ClientReact from './react/needle-api/needle-client-react.mjs'; import ClientVue from './client/needle-api/needle-client-vue.mjs'; import ClientWebpack from './client/needle-api/needle-client-webpack.mjs'; -import ClientI18n from './client/needle-api/needle-client-i18n.mjs'; export default class NeedleApi { constructor(generator) { @@ -32,6 +31,5 @@ export default class NeedleApi { this.clientReact = new ClientReact(generator); this.clientVue = new ClientVue(generator); this.clientWebpack = new ClientWebpack(generator); - this.clientI18n = new ClientI18n(generator); } } From fcf192f47ddfbd91b3e9e447926dde23680f8ea3 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 30 Aug 2023 10:31:48 -0300 Subject: [PATCH 6/8] drop loadStoredAppOptions from todo --- generators/app/generator.mjs | 4 ++-- generators/app/support/config.mts | 7 +++++-- generators/base/generator-base-todo.mts | 10 +--------- generators/base/generator.mts | 3 ++- generators/bootstrap-application-base/generator.mts | 3 ++- generators/bootstrap-application-client/generator.mts | 3 ++- generators/bootstrap-application/generator.mts | 3 ++- generators/bootstrap/generator.mts | 3 ++- generators/client/generator.mjs | 3 ++- generators/common/generator.mjs | 3 ++- generators/entities/generator.mjs | 3 ++- generators/languages/generator.mjs | 3 ++- generators/server/generator.mjs | 3 ++- 13 files changed, 28 insertions(+), 23 deletions(-) diff --git a/generators/app/generator.mjs b/generators/app/generator.mjs index 1eada056e457..07dfd23f5fe7 100644 --- a/generators/app/generator.mjs +++ b/generators/app/generator.mjs @@ -21,7 +21,7 @@ import chalk from 'chalk'; import _ from 'lodash'; import BaseApplicationGenerator from '../base-application/index.mjs'; -import { checkNode } from './support/index.mjs'; +import { checkNode, loadStoredAppOptions } from './support/index.mjs'; import cleanupOldFilesTask from './cleanup.mjs'; import prompts from './prompts.mjs'; import statistics from '../statistics.mjs'; @@ -262,7 +262,7 @@ export default class JHipsterAppGenerator extends BaseApplicationGenerator { } async beforeQueue() { - this.loadStoredAppOptions(); + loadStoredAppOptions.call(this); this.loadRuntimeOptions(); await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION_BASE); diff --git a/generators/app/support/config.mts b/generators/app/support/config.mts index e23cc15c4aa9..cc3611b928dd 100644 --- a/generators/app/support/config.mts +++ b/generators/app/support/config.mts @@ -14,7 +14,10 @@ const { CASSANDRA, NO: NO_DATABASE } = databaseTypes; * Load common options to be stored. * @deprecated */ -export const loadStoredAppOptions = ({ options, sharedData, jhipsterConfig, log }) => { +export function loadStoredAppOptions( + this: any, + { options = this.options, sharedData = this.sharedData, jhipsterConfig = this.jhipsterConfig, log = this.log } = {}, +) { // Parse options only once. if (sharedData.get('optionsParsed')) return; sharedData.set('optionsParsed', true); @@ -155,7 +158,7 @@ export const loadStoredAppOptions = ({ options, sharedData, jhipsterConfig, log options.skipInstall = true; } } -}; +} /** * Load app configs into application. diff --git a/generators/base/generator-base-todo.mts b/generators/base/generator-base-todo.mts index aaa0f8b04ee7..27d567701f47 100644 --- a/generators/base/generator-base-todo.mts +++ b/generators/base/generator-base-todo.mts @@ -26,7 +26,7 @@ import { loadServerConfig, } from '../server/support/index.mjs'; import { loadClientConfig, loadDerivedClientConfig } from '../client/support/index.mjs'; -import { loadAppConfig, loadDerivedAppConfig, loadStoredAppOptions } from '../app/support/index.mjs'; +import { loadAppConfig, loadDerivedAppConfig } from '../app/support/index.mjs'; /** * Class the contains the methods that should be refactored and converted to typescript. @@ -56,14 +56,6 @@ export default abstract class JHipsterBaseGenerator extends JHipsterBaseCoreGene } } - /** - * Load common options to be stored. - * @deprecated - */ - loadStoredAppOptions(options: any = this.options) { - loadStoredAppOptions({ jhipsterConfig: this.jhipsterConfig, sharedData: this.sharedData, options, log: this.log }); - } - /** * Load runtime options into dest. * @deprecated diff --git a/generators/base/generator.mts b/generators/base/generator.mts index b72c5f9a1a49..98d10e6e66d4 100644 --- a/generators/base/generator.mts +++ b/generators/base/generator.mts @@ -33,6 +33,7 @@ import { JHipsterGeneratorFeatures, JHipsterGeneratorOptions } from './api.mjs'; import CoreGenerator from '../base-core/index.mjs'; import { LOCAL_BLUEPRINT_PACKAGE_NAMESPACE } from './support/constants.mjs'; import { getConfigWithDefaults } from '../../jdl/index.js'; +import { loadStoredAppOptions } from '../app/support/index.mjs'; const { defaults } = _; @@ -57,7 +58,7 @@ export default class JHipsterBaseBlueprintGenerator< } this.loadRuntimeOptions(); - this.loadStoredAppOptions(); + loadStoredAppOptions.call(this); this.sbsBlueprint = this.features.sbsBlueprint ?? false; this.fromBlueprint = this.rootGeneratorName() !== 'generator-jhipster'; diff --git a/generators/bootstrap-application-base/generator.mts b/generators/bootstrap-application-base/generator.mts index 5ea7ce3e3987..1adb6b541b13 100644 --- a/generators/bootstrap-application-base/generator.mts +++ b/generators/bootstrap-application-base/generator.mts @@ -36,6 +36,7 @@ import { DOCKER_DIR } from '../generator-constants.mjs'; import { GENERATOR_BOOTSTRAP, GENERATOR_COMMON, GENERATOR_PROJECT_NAME } from '../generator-list.mjs'; import { packageJson } from '../../lib/index.mjs'; import { loadLanguagesConfig } from '../languages/support/index.mjs'; +import { loadStoredAppOptions } from '../app/support/index.mjs'; const isWin32 = os.platform() === 'win32'; @@ -47,7 +48,7 @@ export default class BootstrapApplicationBase extends BaseApplicationGenerator { if (this.options.help) return; - this.loadStoredAppOptions(); + loadStoredAppOptions.call(this); } async beforeQueue() { diff --git a/generators/bootstrap-application-client/generator.mts b/generators/bootstrap-application-client/generator.mts index 6ccdb6654cc5..1ba5c4f24c75 100644 --- a/generators/bootstrap-application-client/generator.mts +++ b/generators/bootstrap-application-client/generator.mts @@ -19,6 +19,7 @@ import { preparePostEntityClientDerivedProperties } from '../client/support/index.mjs'; import BaseApplicationGenerator from '../base-application/index.mjs'; import { GENERATOR_BOOTSTRAP_APPLICATION_BASE } from '../generator-list.mjs'; +import { loadStoredAppOptions } from '../app/support/index.mjs'; export default class BootStrapApplicationClient extends BaseApplicationGenerator { constructor(args: any, options: any, features: any) { @@ -26,7 +27,7 @@ export default class BootStrapApplicationClient extends BaseApplicationGenerator if (this.options.help) return; - this.loadStoredAppOptions(); + loadStoredAppOptions.call(this); this.loadRuntimeOptions(); } diff --git a/generators/bootstrap-application/generator.mts b/generators/bootstrap-application/generator.mts index 5359f4c74999..0065eec7f828 100644 --- a/generators/bootstrap-application/generator.mts +++ b/generators/bootstrap-application/generator.mts @@ -31,6 +31,7 @@ import { GENERATOR_BOOTSTRAP_APPLICATION_CLIENT, GENERATOR_BOOTSTRAP_APPLICATION import { preparePostEntityServerDerivedProperties } from '../server/support/index.mjs'; import { getDefaultAppName } from '../project-name/support/index.mjs'; import { packageJson } from '../../lib/index.mjs'; +import { loadStoredAppOptions } from '../app/support/index.mjs'; const { Validations: { MAX, MIN, MAXLENGTH, MINLENGTH, MAXBYTES, MINBYTES, PATTERN }, @@ -43,7 +44,7 @@ export default class BootstrapApplicationGenerator extends BaseApplicationGenera if (this.options.help) return; - this.loadStoredAppOptions(); + loadStoredAppOptions.call(this); this.loadRuntimeOptions(); } diff --git a/generators/bootstrap/generator.mts b/generators/bootstrap/generator.mts index 98a786218b02..bc1a2c35152d 100644 --- a/generators/bootstrap/generator.mts +++ b/generators/bootstrap/generator.mts @@ -35,6 +35,7 @@ import { PRIORITY_NAMES, QUEUES } from '../base-application/priorities.mjs'; import type { BaseGeneratorDefinition, GenericTaskGroup } from '../base/tasks.mjs'; import command from './command.mjs'; import { createRemoveUnusedImportsTransform } from './support/java-unused-imports-transform.mjs'; +import { loadStoredAppOptions } from '../app/support/index.mjs'; const { MULTISTEP_TRANSFORM, PRE_CONFLICTS } = PRIORITY_NAMES; const { MULTISTEP_TRANSFORM_QUEUE } = QUEUES; @@ -55,7 +56,7 @@ export default class BootstrapGenerator extends BaseGenerator { } beforeQueue() { - this.loadStoredAppOptions(); + loadStoredAppOptions.call(this); // Load common runtime options. this.parseCommonRuntimeOptions(); diff --git a/generators/client/generator.mjs b/generators/client/generator.mjs index b34e3aeb305f..88bdad1f1756 100644 --- a/generators/client/generator.mjs +++ b/generators/client/generator.mjs @@ -30,6 +30,7 @@ import { GENERATOR_BOOTSTRAP_APPLICATION, GENERATOR_CYPRESS, GENERATOR_COMMON, G import { testFrameworkTypes, clientFrameworkTypes } from '../../jdl/jhipster/index.mjs'; import { createNeedleCallback } from '../base/support/index.mjs'; +import { loadStoredAppOptions } from '../app/support/index.mjs'; const { ANGULAR, VUE, REACT } = clientFrameworkTypes; const { CYPRESS } = testFrameworkTypes; @@ -40,7 +41,7 @@ const { CYPRESS } = testFrameworkTypes; */ export default class JHipsterClientGenerator extends BaseApplicationGenerator { async beforeQueue() { - this.loadStoredAppOptions(); + loadStoredAppOptions.call(this); this.loadRuntimeOptions(); // TODO depend on GENERATOR_BOOTSTRAP_APPLICATION_CLIENT. diff --git a/generators/common/generator.mjs b/generators/common/generator.mjs index 42e12eb8fc27..bb1dac2eac97 100644 --- a/generators/common/generator.mjs +++ b/generators/common/generator.mjs @@ -32,12 +32,13 @@ import { clientFrameworkTypes } from '../../jdl/jhipster/index.mjs'; import { GENERATOR_COMMON, GENERATOR_BOOTSTRAP_APPLICATION, GENERATOR_GIT } from '../generator-list.mjs'; import command from './command.mjs'; import { createPrettierTransform } from '../bootstrap/support/prettier-support.mjs'; +import { loadStoredAppOptions } from '../app/support/index.mjs'; const { REACT, ANGULAR } = clientFrameworkTypes; export default class CommonGenerator extends BaseApplicationGenerator { async beforeQueue() { - this.loadStoredAppOptions(); + loadStoredAppOptions.call(this); this.loadRuntimeOptions(); await this.dependsOnJHipster(GENERATOR_BOOTSTRAP_APPLICATION); diff --git a/generators/entities/generator.mjs b/generators/entities/generator.mjs index bf063f4afe6b..f9ba3dc53cde 100644 --- a/generators/entities/generator.mjs +++ b/generators/entities/generator.mjs @@ -16,6 +16,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { loadStoredAppOptions } from '../app/support/index.mjs'; import BaseApplicationGenerator from '../base-application/index.mjs'; import { JHIPSTER_CONFIG_DIR } from '../generator-constants.mjs'; import { GENERATOR_ENTITIES, GENERATOR_APP } from '../generator-list.mjs'; @@ -74,7 +75,7 @@ export default class EntitiesGenerator extends BaseApplicationGenerator { } async beforeQueue() { - this.loadStoredAppOptions(); + loadStoredAppOptions.call(this); this.loadRuntimeOptions(); if (!this.fromBlueprint) { diff --git a/generators/languages/generator.mjs b/generators/languages/generator.mjs index de2817c4d59d..e5852b74bf50 100644 --- a/generators/languages/generator.mjs +++ b/generators/languages/generator.mjs @@ -34,6 +34,7 @@ import { updateLanguagesTask as updateLanguagesInVue } from '../vue/support/inde import { updateLanguagesTask as updateLanguagesInJava } from '../server/support/index.mjs'; import { SERVER_MAIN_RES_DIR, SERVER_TEST_RES_DIR } from '../generator-constants.mjs'; import upgradeFilesTask from './upgrade-files-task.mjs'; +import { loadStoredAppOptions } from '../app/support/index.mjs'; const { startCase } = _; @@ -88,7 +89,7 @@ export default class LanguagesGenerator extends BaseApplicationGenerator { return; } - this.loadStoredAppOptions(); + loadStoredAppOptions.call(this); this.loadRuntimeOptions(); // Validate languages passed as argument. diff --git a/generators/server/generator.mjs b/generators/server/generator.mjs index 81292c4f6efc..05c10291c9d5 100644 --- a/generators/server/generator.mjs +++ b/generators/server/generator.mjs @@ -102,6 +102,7 @@ import { createBase64Secret, createSecret, createNeedleCallback } from '../base/ import command from './command.mjs'; import { addJavaAnnotation } from '../java/support/index.mjs'; import { isReservedPaginationWords } from '../../jdl/jhipster/reserved-keywords.js'; +import { loadStoredAppOptions } from '../app/support/index.mjs'; const dbTypes = fieldTypes; const { @@ -155,7 +156,7 @@ export default class JHipsterServerGenerator extends BaseApplicationGenerator { fakeKeytool; async beforeQueue() { - this.loadStoredAppOptions(); + loadStoredAppOptions.call(this); this.loadRuntimeOptions(); // TODO depend on GENERATOR_BOOTSTRAP_APPLICATION_SERVER. From 082a7bb22b724861cafd8f37fcf47504a72cf8df Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 30 Aug 2023 17:44:20 -0300 Subject: [PATCH 7/8] function option type should be string --- cli/jhipster-command.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/jhipster-command.mjs b/cli/jhipster-command.mjs index 090760d92273..14eed85f0a77 100644 --- a/cli/jhipster-command.mjs +++ b/cli/jhipster-command.mjs @@ -192,7 +192,7 @@ export default class JHipsterCommand extends Command { cmdString = `-${optionDefinition.alias}, `; } cmdString = `${cmdString}${longOption}`; - if (optionDefinition.type === String) { + if (optionDefinition.type === String || typeof optionDefinition.type === 'function') { cmdString = optionDefinition.required !== false ? `${cmdString} ` : `${cmdString} [value]`; } else if (optionDefinition.type === Array) { cmdString = optionDefinition.required !== false ? `${cmdString} ` : `${cmdString} [value...]`; From f9314b6f3112045d7c2689e0170c086668877d87 Mon Sep 17 00:00:00 2001 From: Marcelo Shima Date: Wed, 30 Aug 2023 17:59:46 -0300 Subject: [PATCH 8/8] options type adjusts --- cli/jhipster-command.mjs | 6 +++--- generators/app/__snapshots__/generator.spec.mts.snap | 2 +- generators/base/__snapshots__/generator.spec.mts.snap | 2 +- generators/jdl/__snapshots__/generator.spec.mts.snap | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cli/jhipster-command.mjs b/cli/jhipster-command.mjs index 14eed85f0a77..72b8fcc861df 100644 --- a/cli/jhipster-command.mjs +++ b/cli/jhipster-command.mjs @@ -192,10 +192,10 @@ export default class JHipsterCommand extends Command { cmdString = `-${optionDefinition.alias}, `; } cmdString = `${cmdString}${longOption}`; - if (optionDefinition.type === String || typeof optionDefinition.type === 'function') { - cmdString = optionDefinition.required !== false ? `${cmdString} ` : `${cmdString} [value]`; - } else if (optionDefinition.type === Array) { + if (optionDefinition.type === Array) { cmdString = optionDefinition.required !== false ? `${cmdString} ` : `${cmdString} [value...]`; + } else if (optionDefinition.type && optionDefinition.type !== Boolean) { + cmdString = optionDefinition.required !== false ? `${cmdString} ` : `${cmdString} [value]`; } const option = new Option(cmdString, optionDefinition.description + additionalDescription) .default(optionDefinition.default) diff --git a/generators/app/__snapshots__/generator.spec.mts.snap b/generators/app/__snapshots__/generator.spec.mts.snap index ad5a6dc2b7ba..64febc8c46b4 100644 --- a/generators/app/__snapshots__/generator.spec.mts.snap +++ b/generators/app/__snapshots__/generator.spec.mts.snap @@ -55,7 +55,7 @@ Options: --project-version project version to use, this option is not persisted (env: JHI_PROJECT_VERSION) --message-broker message broker --with-generated-flag Add a GeneratedByJHipster annotation to all generated java classes and interfaces - --prettier-tab-width Default tab width for prettier + --prettier-tab-width Default tab width for prettier --with-admin-ui Generate administrative user interface --skip-git Skip git repository initialization --monorepository Use monorepository diff --git a/generators/base/__snapshots__/generator.spec.mts.snap b/generators/base/__snapshots__/generator.spec.mts.snap index db921ed105a9..063d09dc43c5 100644 --- a/generators/base/__snapshots__/generator.spec.mts.snap +++ b/generators/base/__snapshots__/generator.spec.mts.snap @@ -19,7 +19,7 @@ Options: --experimental Enable experimental features. Please note that these features may be unstable and may undergo breaking changes at any time -d, --debug Enable debugger --skip-jhipster-dependencies Don't write jhipster dependencies to package.json. - --creation-timestamp Project creation timestamp (used for reproducible builds) + --creation-timestamp Project creation timestamp (used for reproducible builds) -h, --help display help for command Commands: diff --git a/generators/jdl/__snapshots__/generator.spec.mts.snap b/generators/jdl/__snapshots__/generator.spec.mts.snap index 425417ba69c1..0cc9ec7ac4fe 100644 --- a/generators/jdl/__snapshots__/generator.spec.mts.snap +++ b/generators/jdl/__snapshots__/generator.spec.mts.snap @@ -217,7 +217,7 @@ Options: --project-version project version to use, this option is not persisted (env: JHI_PROJECT_VERSION) --message-broker message broker --with-generated-flag Add a GeneratedByJHipster annotation to all generated java classes and interfaces - --prettier-tab-width Default tab width for prettier + --prettier-tab-width Default tab width for prettier --with-admin-ui Generate administrative user interface --skip-git Skip git repository initialization --monorepository Use monorepository