diff --git a/generators/angular/generator.ts b/generators/angular/generator.ts index 7bacb5e3d658..70f047f473d7 100644 --- a/generators/angular/generator.ts +++ b/generators/angular/generator.ts @@ -16,10 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -import { camelCase } from 'lodash-es'; import chalk from 'chalk'; import { isFileStateModified } from 'mem-fs-editor/state'; - import BaseApplicationGenerator from '../base-application/index.js'; import { GENERATOR_ANGULAR, GENERATOR_CLIENT, GENERATOR_LANGUAGES } from '../generator-list.js'; import { defaultLanguage } from '../languages/support/index.js'; @@ -27,7 +25,7 @@ import { clientFrameworkTypes } from '../../lib/jhipster/index.js'; import { generateEntityClientEnumImports as getClientEnumImportsFormat } from '../client/support/index.js'; import { createNeedleCallback, mutateData } from '../base/support/index.js'; import { writeEslintClientRootConfigFile } from '../javascript/generators/eslint/support/tasks.js'; -import type { PostWritingEntitiesTaskParam } from '../../lib/types/application/tasks.js'; +import type { TaskTypes as DefaultTaskTypes } from '../../lib/types/application/tasks.js'; import { cleanupEntitiesFiles, postWriteEntitiesFiles, writeEntitiesFiles } from './entity-files-angular.js'; import { writeFiles } from './files-angular.js'; import cleanupOldFilesTask from './cleanup.js'; @@ -41,12 +39,11 @@ import { isTranslatedAngularFile, translateAngularFilesTransform, } from './support/index.js'; +import type { AngularApplication, AngularEntity } from './types.js'; const { ANGULAR } = clientFrameworkTypes; -export default class AngularGenerator extends BaseApplicationGenerator { - localEntities?: any[]; - +export default class AngularGenerator extends BaseApplicationGenerator> { async beforeQueue() { if (!this.fromBlueprint) { await this.composeWithBlueprints(); @@ -88,7 +85,6 @@ export default class AngularGenerator extends BaseApplicationGenerator { webappEnumerationsDir: app => `${app.clientSrcDir}app/entities/enumerations/`, angularLocaleId: app => app.nativeLanguageDefinition.angularLocale ?? defaultLanguage.angularLocale!, }); - application.addPrettierExtensions?.(['html', 'css', 'scss']); }, async javaNodeBuildPaths({ application }) { @@ -104,10 +100,16 @@ export default class AngularGenerator extends BaseApplicationGenerator { }, addNeedles({ source, application }) { source.addEntitiesToClient = param => { - this.addEntitiesToModule(param); - this.addEntitiesToMenu(param); + const routeTemplatePath = `${param.application.clientSrcDir}app/entities/entity.routes.ts`; + const ignoreNonExistingRoute = chalk.yellow(`Route(s) not added to ${routeTemplatePath}.`); + const addRouteCallback = addEntitiesRoute(param); + this.editFile(routeTemplatePath, { ignoreNonExisting: ignoreNonExistingRoute }, addRouteCallback); + + const filePath = `${application.clientSrcDir}app/layouts/navbar/navbar.component.html`; + const ignoreNonExisting = chalk.yellow('Reference to entities not added to menu.'); + const editCallback = addToEntitiesMenu(param); + this.editFile(filePath, { ignoreNonExisting }, editCallback); }; - source.addAdminRoute = (args: Omit[0], 'needle'>) => this.editFile( `${application.srcMainWebapp}app/admin/admin.routes.ts`, @@ -202,6 +204,9 @@ export default class AngularGenerator extends BaseApplicationGenerator { ...(entity.entityReadAuthority?.split(',') ?? []), ]), }); + entity.generateEntityClientEnumImports = fields => { + return getClientEnumImportsFormat(fields, ANGULAR); + }; }, }); } @@ -234,7 +239,6 @@ export default class AngularGenerator extends BaseApplicationGenerator { returnValue = fieldDefaultValue; } } - return returnValue; }, } as any); @@ -248,9 +252,9 @@ export default class AngularGenerator extends BaseApplicationGenerator { get default() { return this.asDefaultTaskGroup({ - loadEntities() { + loadEntities({ application }) { const entities = this.sharedData.getEntities().map(({ entity }) => entity); - this.localEntities = entities.filter(entity => !entity.builtIn && !entity.skipClient); + application.angularEntities = entities.filter(entity => !entity.builtIn && !entity.skipClient) as AngularEntity[]; }, queueTranslateTransform({ control, application }) { const { enableTranslation, jhiPrefix } = application; @@ -260,7 +264,7 @@ export default class AngularGenerator extends BaseApplicationGenerator { filter: file => isFileStateModified(file) && file.path.startsWith(this.destinationPath()) && isTranslatedAngularFile(file), refresh: false, }, - translateAngularFilesTransform(control.getWebappTranslation, { enableTranslation, jhiPrefix }), + translateAngularFilesTransform(control.getWebappTranslation!, { enableTranslation, jhiPrefix }), ); }, }); @@ -387,143 +391,4 @@ export default class AngularGenerator extends BaseApplicationGenerator { get [BaseApplicationGenerator.END]() { return this.delegateTasksToBlueprint(() => this.end); } - - /** - * @private - * Add new scss style to the angular application in "vendor.scss". - * - * @param {string} style - scss to add in the file - * @param {string} comment - comment to add before css code - * - * example: - * - * style = '.success {\n @extend .message;\n border-color: green;\n}' - * comment = 'Message' - * - * * ========================================================================== - * Message - * ========================================================================== * - * .success { - * @extend .message; - * border-color: green; - * } - * - */ - addVendorSCSSStyle(style, comment?) { - this.needleApi.clientAngular.addVendorSCSSStyle(style, comment); - } - - /** - * @private - * Add a new lazy loaded module to admin routing file. - * - * @param {string} route - The route for the module. For example 'entity-audit'. - * @param {string} modulePath - The path to the module file. For example './entity-audit/entity-audit.module'. - * @param {string} moduleName - The name of the module. For example 'EntityAuditModule'. - * @param {string} pageTitle - The translation key if i18n is enabled or the text if i18n is disabled for the page title in the browser. - * For example 'entityAudit.home.title' for i18n enabled or 'Entity audit' for i18n disabled. - * If undefined then application global page title is used in the browser title bar. - */ - addAdminRoute(route, modulePath, moduleName, pageTitle) { - this.needleApi.clientAngular.addAdminRoute(route, modulePath, moduleName, pageTitle); - } - - /** - * @private - * Add a new module in the TS modules file. - * - * @param {string} appName - Angular2 application name. - * @param {string} angularName - The name of the new admin item. - * @param {string} folderName - The name of the folder. - * @param {string} fileName - The name of the file. - * @param {boolean} enableTranslation - If translations are enabled or not. - * @param {string} clientFramework - The name of the client framework. - */ - addAngularModule(appName, angularName, folderName, fileName, enableTranslation) { - this.needleApi.clientAngular.addModule(appName, angularName, folderName, fileName, enableTranslation); - } - - /** - * @private - * Add a new icon to icon imports. - * - * @param {string} iconName - The name of the Font Awesome icon. - */ - addIcon(iconName) { - this.needleApi.clientAngular.addIcon(iconName); - } - - /** - * Add a new menu element to the admin menu. - * - * @param {string} routerName - The name of the Angular router that is added to the admin menu. - * @param {string} iconName - The name of the Font Awesome icon that will be displayed. - * @param {boolean} enableTranslation - If translations are enabled or not - * @param {string} translationKeyMenu - i18n key for entry in the admin menu - */ - addElementToAdminMenu(routerName, iconName, enableTranslation, translationKeyMenu = camelCase(routerName), jhiPrefix?) { - this.needleApi.clientAngular.addElementToAdminMenu(routerName, iconName, enableTranslation, translationKeyMenu, jhiPrefix); - } - - addEntitiesToMenu({ application, entities }: Pick) { - const filePath = `${application.clientSrcDir}app/layouts/navbar/navbar.component.html`; - const ignoreNonExisting = chalk.yellow('Reference to entities not added to menu.'); - const editCallback = addToEntitiesMenu({ application, entities }); - - this.editFile(filePath, { ignoreNonExisting }, editCallback); - } - - addEntitiesToModule(param: Pick) { - const filePath = `${param.application.clientSrcDir}app/entities/entity.routes.ts`; - const ignoreNonExisting = chalk.yellow(`Route(s) not added to ${filePath}.`); - const addRouteCallback = addEntitiesRoute(param); - this.editFile(filePath, { ignoreNonExisting }, addRouteCallback); - } - - /** - * @private - * Add new scss style to the angular application in "global.scss - * - * @param {string} style - css to add in the file - * @param {string} comment - comment to add before css code - * - * example: - * - * style = '.jhipster {\n color: #baa186;\n}' - * comment = 'New JHipster color' - * - * * ========================================================================== - * New JHipster color - * ========================================================================== * - * .jhipster { - * color: #baa186; - * } - * - */ - addMainSCSSStyle(style, comment?) { - this.needleApi.clientAngular.addGlobalSCSSStyle(style, comment); - } - - /** - * Returns the typescript import section of enums referenced by all fields of the entity. - * @param fields returns the import of enums that are referenced by the fields - * @returns {typeImports:Map} the fields that potentially contains some enum types - */ - generateEntityClientEnumImports(fields) { - return getClientEnumImportsFormat(fields, ANGULAR); - } - - /** - * @private - * Add a new menu element, at the root of the menu. - * - * @param {string} routerName - The name of the router that is added to the menu. - * @param {string} iconName - The name of the Font Awesome icon that will be displayed. - * @param {boolean} enableTranslation - If translations are enabled or not - * @param {string} clientFramework - The name of the client framework - * @param {string} translationKeyMenu - i18n key for entry in the menu - */ - addElementToMenu(routerName, iconName, enableTranslation, _clientFramework?, translationKeyMenu = camelCase(routerName)) { - this.needleApi.clientAngular.addElementToMenu(routerName, iconName, enableTranslation, translationKeyMenu); - } } diff --git a/generators/angular/support/translate-angular.ts b/generators/angular/support/translate-angular.ts index a24a67d2139c..4f8bb781db79 100644 --- a/generators/angular/support/translate-angular.ts +++ b/generators/angular/support/translate-angular.ts @@ -42,12 +42,9 @@ export type ReplacerOptions = { jhiPrefix: string; enableTranslation: boolean }; * Replace translation key with translation values * * @param {import('../generator-base.js')} generator + * @param getWebappTranslation * @param {string} content * @param {string} regexSource regular expression to find keys - * @param {object} [options] - * @param {number} [options.keyIndex] - * @param {number} [options.replacementIndex] - * @param {any} [options.escape] * @returns {string} */ function replaceTranslationKeysWithText( @@ -305,7 +302,7 @@ export const createTranslationReplacer = (getWebappTranslation: GetWebappTransla { prefixPattern: '>\\s*', suffixPattern: '\\s*<' }, ); } - return function replaceAngularTranslations(content, filePath) { + return function replaceAngularTranslations(content: string, filePath: string) { if (filePath.endsWith('.html')) { if (!enableTranslation) { content = content.replace(new RegExp(TRANSLATE_REGEX, 'g'), ''); @@ -318,7 +315,7 @@ export const createTranslationReplacer = (getWebappTranslation: GetWebappTransla content = htmlJhiTranslateStringifyReplacer(content); } if (/(:?\.html|.ts)$/.test(filePath)) { - content = translationReplacer?.(content, filePath); + content = translationReplacer ? translationReplacer?.(content, filePath) : content; } if (!enableTranslation) { if (/(:?route|module)\.ts$/.test(filePath)) { @@ -335,7 +332,7 @@ export const createTranslationReplacer = (getWebappTranslation: GetWebappTransla const minimatch = new Minimatch('**/*{.html,.ts}'); export const isTranslatedAngularFile = file => minimatch.match(file.path); -export const translateAngularFilesTransform = (getWebappTranslation, opts: ReplacerOptions | boolean) => { +export const translateAngularFilesTransform = (getWebappTranslation: GetWebappTranslationCallback, opts: ReplacerOptions | boolean) => { const translate = createTranslationReplacer(getWebappTranslation, opts); return passthrough(file => { file.contents = Buffer.from(translate(file.contents.toString(), file.path)); diff --git a/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_.model.ts.ejs b/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_.model.ts.ejs index 7e70b178d928..a7d61dba6b5d 100644 --- a/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_.model.ts.ejs +++ b/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_.model.ts.ejs @@ -17,7 +17,7 @@ limitations under the License. -%> <% -const enumImports = this.generateEntityClientEnumImports(fields); +const enumImports = generateEntityClientEnumImports(fields); %> <%_ if (anyFieldIsDateDerived) { _%> import dayjs from 'dayjs/esm'; diff --git a/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_.test-samples.ts.ejs b/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_.test-samples.ts.ejs index e01295a18213..c918e19e4e2b 100644 --- a/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_.test-samples.ts.ejs +++ b/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/_entityFile_.test-samples.ts.ejs @@ -17,7 +17,7 @@ limitations under the License. -%> <%_ - const enumImports = this.generateEntityClientEnumImports(fields); + const enumImports = generateEntityClientEnumImports(fields); _%> <%_ if (anyFieldIsDateDerived) { _%> import dayjs from 'dayjs/esm'; diff --git a/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/service/_entityFile_.service.spec.ts.ejs b/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/service/_entityFile_.service.spec.ts.ejs index 2674a2b7c35c..d90d0d3bbe49 100644 --- a/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/service/_entityFile_.service.spec.ts.ejs +++ b/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/service/_entityFile_.service.spec.ts.ejs @@ -18,7 +18,7 @@ -%> <%_ const tsKeyId = primaryKey.tsSampleValues[0]; -const enumImports = this.generateEntityClientEnumImports(fields); +const enumImports = generateEntityClientEnumImports(fields); _%> import { TestBed } from '@angular/core/testing'; import { provideHttpClientTesting, HttpTestingController } from '@angular/common/http/testing'; diff --git a/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/update/_entityFile_-update.component.ts.ejs b/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/update/_entityFile_-update.component.ts.ejs index 3c217954d618..42969d9bd4d9 100644 --- a/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/update/_entityFile_-update.component.ts.ejs +++ b/generators/angular/templates/src/main/webapp/app/entities/_entityFolder_/update/_entityFile_-update.component.ts.ejs @@ -49,7 +49,7 @@ import { <%= uniqueRel.otherEntityAngularName %>Service } from 'app/entities/<%= } } _%> -<%_ const enumImports = this.generateEntityClientEnumImports(fields); _%> +<%_ const enumImports = generateEntityClientEnumImports(fields); _%> <%_ enumImports.forEach( (importedPath, importedType) => { _%> import { <%- importedType %> } from '<%- importedPath %>'; <%_ }); _%> diff --git a/generators/angular/templates/src/main/webapp/app/entities/entity-navbar-items.ts.ejs b/generators/angular/templates/src/main/webapp/app/entities/entity-navbar-items.ts.ejs index 6ec007d1a2f8..af98e480338a 100644 --- a/generators/angular/templates/src/main/webapp/app/entities/entity-navbar-items.ts.ejs +++ b/generators/angular/templates/src/main/webapp/app/entities/entity-navbar-items.ts.ejs @@ -19,7 +19,7 @@ import NavbarItem from 'app/layouts/navbar/navbar-item.model'; export const EntityNavbarItems: NavbarItem[] = [ -<%_ for (const entity of this.localEntities) { _%> +<%_ for (const entity of angularEntities) { _%> { name: '<%= entity.entityAngularName %>', route: '/<%= entity.entityPage %>', diff --git a/generators/angular/types-partial.d.ts b/generators/angular/types-partial.d.ts new file mode 100644 index 000000000000..45913efc6e82 --- /dev/null +++ b/generators/angular/types-partial.d.ts @@ -0,0 +1,32 @@ +/** + * Copyright 2013-2024 the original author or authors from the JHipster project. + * + * This file is part of the JHipster project, see https://www.jhipster.tech/ + * for more information. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/** + * @deprecated Will be deprecated and merged into types.d/AngularApplication + */ +export type PartialAngularApplication = { + angularLocaleId: string; +}; + +/** + * @deprecated Will be deprecated and merged into types.d/AngularEntity + */ +export type PartialAngularEntity = { + entityAngularAuthorities?: string; + entityAngularReadAuthorities?: string; +}; diff --git a/generators/angular/types.d.ts b/generators/angular/types.d.ts index 311a20481eaf..5ac8bda7d279 100644 --- a/generators/angular/types.d.ts +++ b/generators/angular/types.d.ts @@ -1 +1,35 @@ -export type AngularApplication = { angularLocaleId: string }; +/** + * Copyright 2013-2024 the original author or authors from the JHipster project. + * + * This file is part of the JHipster project, see https://www.jhipster.tech/ + * for more information. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import type { ApplicationType } from '../../lib/types/application/application.js'; +import type { Entity } from '../../lib/types/application/index.js'; + +export interface AngularEntity extends Entity { + /** + * @experimental to be replaced with a calculated property + * Returns the typescript import section of enums referenced by all fields of the entity. + * @param fields returns the import of enums that are referenced by the fields + * @returns {typeImports:Map} the fields that potentially contains some enum types + */ + generateEntityClientEnumImports: (fields: any) => Map; +} + +export type AngularApplication = { + /** @experimental to be replaced with needles */ + angularEntities: AngularEntity[]; +} & ApplicationType; diff --git a/generators/app/__snapshots__/generator.spec.ts.snap b/generators/app/__snapshots__/generator.spec.ts.snap index d71d53798ee3..8b40425cc875 100644 --- a/generators/app/__snapshots__/generator.spec.ts.snap +++ b/generators/app/__snapshots__/generator.spec.ts.snap @@ -218,6 +218,7 @@ exports[`generator - app with default config should match snapshot 1`] = ` "addOpenapiGeneratorPlugin": undefined, "addPrettierExtensions": [Function], "addSpringMilestoneRepository": false, + "angularEntities": [], "angularLocaleId": "en", "anyEntityHasRelationshipWithUser": false, "applicationType": "monolith", @@ -888,6 +889,7 @@ exports[`generator - app with gateway should match snapshot 1`] = ` "addOpenapiGeneratorPlugin": undefined, "addPrettierExtensions": [Function], "addSpringMilestoneRepository": false, + "angularEntities": [], "angularLocaleId": "en", "anyEntityHasRelationshipWithUser": false, "applicationType": "gateway", diff --git a/generators/client/support/template-utils.ts b/generators/client/support/template-utils.ts index 25d3ee8c77d0..2a348d39ebb2 100644 --- a/generators/client/support/template-utils.ts +++ b/generators/client/support/template-utils.ts @@ -77,12 +77,12 @@ export const generateEntityClientImports = (relationships, dto?, clientFramework * @param {string} clientFramework the client framework, 'angular' or 'react'. * @returns typeImports: Map */ -export const generateEntityClientEnumImports = (fields, clientFramework) => { +export const generateEntityClientEnumImports = (fields: Field[], clientFramework: string) => { const typeImports = new Map(); const uniqueEnums = {}; - fields.forEach(field => { + for (const field of fields) { const { enumFileName, fieldType } = field; - if (field.fieldIsEnum && (!uniqueEnums[fieldType] || (uniqueEnums[fieldType] && field.fieldValues.length !== 0))) { + if (field.fieldIsEnum && (!uniqueEnums[fieldType] || (uniqueEnums[fieldType] && field.fieldValues?.length !== 0))) { const importType = `${fieldType}`; const basePath = clientFramework === VUE ? '@' : 'app'; const modelPath = clientFramework === ANGULAR ? 'entities' : 'shared/model'; @@ -90,7 +90,7 @@ export const generateEntityClientEnumImports = (fields, clientFramework) => { uniqueEnums[fieldType] = field.fieldType; typeImports.set(importType, importPath); } - }); + } return typeImports; }; diff --git a/generators/client/types.d.ts b/generators/client/types.d.ts index 268e5e4ff606..5858a4b4db5a 100644 --- a/generators/client/types.d.ts +++ b/generators/client/types.d.ts @@ -1,17 +1,16 @@ import type { addIconImport, addItemToMenu, addRoute } from '../angular/support/needles.js'; -import type { AngularApplication } from '../angular/types.js'; import type { ExportApplicationPropertiesFromCommand } from '../../lib/command/index.js'; import type { CypressApplication } from '../cypress/types.js'; import type { JavaScriptApplication, JavaScriptSourceType } from '../javascript/types.js'; import type { PostWritingEntitiesTaskParam } from '../../lib/types/application/tasks.js'; +import type { PartialAngularApplication } from '../angular/types-partial.js'; import type { Language } from '../languages/support/languages.ts'; import type Command from './command.ts'; type ApplicationClientProperties = ExportApplicationPropertiesFromCommand; -export type ClientApplication = ApplicationClientProperties & +export type FrontendApplication = ApplicationClientProperties & JavaScriptApplication & - AngularApplication & CypressApplication & { webappLoginRegExp: string; clientWebappDir?: string; @@ -19,6 +18,11 @@ export type ClientApplication = ApplicationClientProperties & clientFrameworkBuiltIn?: boolean; }; +/** + * @deprecated in favor of frontend application. + */ +export type ClientApplication = JavaScriptApplication & PartialAngularApplication & FrontendApplication; + export type ClientResources = { /** * resources added to root file. diff --git a/generators/spring-boot/command.ts b/generators/spring-boot/command.ts index a1ec5c371531..86816058d306 100644 --- a/generators/spring-boot/command.ts +++ b/generators/spring-boot/command.ts @@ -23,7 +23,7 @@ import { createBase64Secret, createSecret } from '../base/support/secret.js'; import { applicationTypes, authenticationTypes } from '../../lib/jhipster/index.js'; const { OAUTH2, SESSION, JWT } = authenticationTypes; -const { GATEWAY, MICROSERVICE } = applicationTypes; +const { GATEWAY, MICROSERVICE, MONOLITH } = applicationTypes; const ALPHANUMERIC_PATTERN = /^[A-Za-z][A-Za-z0-9]*$/; @@ -109,8 +109,8 @@ const command = { type: 'list', message: `Which ${chalk.yellow('*type*')} of authentication would you like to use?`, choices: () => - gen.jhipsterConfigWithDefaults.applicationType !== 'monolith' - ? (config.choices as any).filter(({ value }) => value !== 'session') + gen.jhipsterConfigWithDefaults.applicationType !== MONOLITH + ? (config.choices as any).filter(({ value }) => value !== SESSION) : config.choices, default: () => gen.jhipsterConfigWithDefaults.authenticationType, }), @@ -161,14 +161,14 @@ const command = { prompt: gen => ({ type: 'confirm', message: 'Do you want to allow relationships with User entity?', - when: ({ authenticationType }) => (authenticationType ?? gen.jhipsterConfigWithDefaults.authenticationType) === 'oauth2', + when: ({ authenticationType }) => (authenticationType ?? gen.jhipsterConfigWithDefaults.authenticationType) === OAUTH2, }), jdl: { type: 'boolean', tokenType: 'BOOLEAN', }, configure: gen => { - if (gen.jhipsterConfig.syncUserWithIdp === undefined && gen.jhipsterConfigWithDefaults.authenticationType === 'oauth2') { + if (gen.jhipsterConfig.syncUserWithIdp === undefined && gen.jhipsterConfigWithDefaults.authenticationType === OAUTH2) { if (gen.isJhipsterVersionLessThan('8.1.1')) { gen.jhipsterConfig.syncUserWithIdp = true; } diff --git a/generators/spring-boot/generator.ts b/generators/spring-boot/generator.ts index f7602a8c302b..6bb6714388f7 100644 --- a/generators/spring-boot/generator.ts +++ b/generators/spring-boot/generator.ts @@ -227,7 +227,7 @@ export default class SpringBootGenerator extends BaseApplicationGenerator { get preparing() { return this.asPreparingTaskGroup({ checksWebsocket({ application }) { - const { websocket } = application as any; + const { websocket } = application; if (websocket && websocket !== NO_WEBSOCKET) { if (application.reactive) { throw new Error('Spring Websocket is not supported with reactive applications.'); @@ -443,14 +443,13 @@ public void set${javaBeanCase(propertyName)}(${propertyType} ${propertyName}) { } }, prepareFilters({ application, entity }) { - (entity as any).entityJavaFilterableProperties = [ - ...entity.fields.filter(field => field.filterableField), - ...entity.relationships.filter(rel => !application.reactive || (rel.persistableRelationship && !rel.collection)), - ]; - (entity as any).entityJavaCustomFilters = sortedUniqBy( - entity.fields.map(field => field.propertyJavaCustomFilter).filter(Boolean), - 'type', - ); + mutateData(entity, { + entityJavaFilterableProperties: [ + ...entity.fields.filter(field => field.filterableField), + ...entity.relationships.filter(rel => !application.reactive || (rel.persistableRelationship && !rel.collection)), + ], + entityJavaCustomFilters: sortedUniqBy(entity.fields.map(field => field.propertyJavaCustomFilter).filter(Boolean), 'type'), + }); }, }); } @@ -500,9 +499,14 @@ public void set${javaBeanCase(propertyName)}(${propertyType} ${propertyName}) { get postWriting() { return this.asPostWritingTaskGroup({ addJHipsterBomDependencies({ application, source }) { - const { applicationTypeGateway, applicationTypeMicroservice, javaDependencies, jhipsterDependenciesVersion, messageBrokerAny } = - application; - const { serviceDiscoveryAny } = application as any; + const { + applicationTypeGateway, + applicationTypeMicroservice, + javaDependencies, + jhipsterDependenciesVersion, + messageBrokerAny, + serviceDiscoveryAny, + } = application; source.addJavaDefinitions?.( { diff --git a/lib/types/application/entity.d.ts b/lib/types/application/entity.d.ts index fab73dbe47bb..8af049b96112 100644 --- a/lib/types/application/entity.d.ts +++ b/lib/types/application/entity.d.ts @@ -24,14 +24,10 @@ import type { Field as BaseField } from '../base/field.js'; import type { Relationship as BaseRelationship } from '../base/relationship.js'; import type { FieldType } from '../../application/field-types.ts'; import type { FakerWithRandexp } from '../../../generators/base/support/faker.ts'; +import type { PartialAngularEntity } from '../../../generators/angular/types-partial.js'; import type { Field } from './field.js'; import type { Relationship } from './relationship.js'; -type AngularEntity = { - entityAngularAuthorities?: string; - entityAngularReadAuthorities?: string; -}; - export type PrimaryKey = { name: string; fields: F[]; @@ -51,7 +47,7 @@ type ClientSample = Record; export interface Entity extends Omit>, 'relationships'>, ServerEntity, - AngularEntity { + PartialAngularEntity { changelogDateForRecent: any; /** @experimental */ auditableEntity?: boolean; @@ -126,6 +122,8 @@ export interface Entity ); }); - it('admin menu contains the admin element added by needle api', () => { - runResult.assertFileContent( - `${CLIENT_MAIN_SRC_DIR}app/layouts/navbar/navbar.component.html`, - ` -
  • - - - Router Name 2 - -
  • -`, - ); - }); - - it('icon imports contains a new icon added by a new admin menu method of needle api ', () => { - runResult.assertFileContent(`${CLIENT_MAIN_SRC_DIR}app/config/font-awesome-icons.ts`, ' faIconName2'); - }); - it('entity module contains the microservice object added by needle api', () => { runResult.assertFileContent( `${CLIENT_MAIN_SRC_DIR}app/entities/entity.routes.ts`, diff --git a/test/needle-api/needle-client-angular.spec.ts b/test/needle-api/needle-client-angular.spec.ts deleted file mode 100644 index 1fe48a971487..000000000000 --- a/test/needle-api/needle-client-angular.spec.ts +++ /dev/null @@ -1,111 +0,0 @@ -import { before, describe, it } from 'esmocha'; -import { basicHelpers as helpers, result as runResult } from '../../lib/testing/index.js'; - -import { CLIENT_MAIN_SRC_DIR } from '../../generators/generator-constants.js'; -import BaseApplicationGenerator from '../../generators/base-application/index.js'; -import AngularGenerator from '../../generators/angular/index.js'; - -const mockBlueprintSubGen = class extends AngularGenerator { - constructor(args, opts, features) { - super(args, opts, features); - this.sbsBlueprint = true; - } - - get [BaseApplicationGenerator.POST_WRITING]() { - return this.asPostWritingTaskGroup({ - addCssStylesProperty() { - this.addMainSCSSStyle('@import style_without_comment;'); - this.addMainSCSSStyle('@import style;', 'my comment'); - this.addVendorSCSSStyle('@import style;', 'my comment'); - this.addVendorSCSSStyle('@import style_without_comment;'); - }, - addToMenuStep() { - this.addElementToMenu('routerName1', 'iconName1', true); - }, - addToModuleStep() { - this.addAngularModule('appName', 'angularName', 'folderName', 'fileName', true); - this.addAdminRoute('entity-audit', './entity-audit/entity-audit.module', 'EntityAuditModule', 'entityAudit.home.title'); - }, - }); - } -}; - -describe('needle API Angular: JHipster angular generator with blueprint', () => { - before(async () => { - await helpers - .runJHipster('angular') - .withJHipsterConfig({ - skipServer: true, - }) - .withOptions({ - blueprint: ['myblueprint'], - }) - .withGenerators([[mockBlueprintSubGen, { namespace: 'jhipster-myblueprint:angular' }]]); - }); - - it('vendor.scss contains the specific change (without comment) added by needle api', () => { - runResult.assertFileContent(`${CLIENT_MAIN_SRC_DIR}content/scss/vendor.scss`, /\n@import style_without_comment;\n/); - }); - - it('global.scss contains the specific change (without comment) added by needle api', () => { - runResult.assertFileContent(`${CLIENT_MAIN_SRC_DIR}content/scss/global.scss`, /\n@import style_without_comment;\n/); - }); - - it('vendor.scss contains the specific change added by needle api', () => { - runResult.assertFileContent(`${CLIENT_MAIN_SRC_DIR}content/scss/vendor.scss`, /\n@import style;\n/); - runResult.assertFileContent( - `${CLIENT_MAIN_SRC_DIR}content/scss/vendor.scss`, - '* ==========================================================================\n' + - 'my comment\n' + - '========================================================================== */\n', - ); - }); - - it('global.scss contains the specific change added by needle api', () => { - runResult.assertFileContent(`${CLIENT_MAIN_SRC_DIR}content/scss/global.scss`, /\n@import style;\n/); - runResult.assertFileContent( - `${CLIENT_MAIN_SRC_DIR}content/scss/global.scss`, - '* ==========================================================================\n' + - 'my comment\n' + - '========================================================================== */\n', - ); - }); - - it('menu contains the element added by needle api', () => { - runResult.assertFileContent( - `${CLIENT_MAIN_SRC_DIR}app/layouts/navbar/navbar.component.html`, - ` - -`, - ); - }); - - it('icon imports contains a new icon added by a new menu method of needle api ', () => { - runResult.assertFileContent(`${CLIENT_MAIN_SRC_DIR}app/config/font-awesome-icons.ts`, ' faIconName1'); - }); - - it('admin routes contains the routing added by needle api', () => { - runResult.assertFileContent( - `${CLIENT_MAIN_SRC_DIR}app/admin/admin.routes.ts`, - ' },\n' + - ' {\n' + - " path: 'entity-audit',\n" + - " data: { pageTitle: 'entityAudit.home.title' },\n" + - " loadChildren: () => import('./entity-audit/entity-audit.module').then(m => m.EntityAuditModule),\n" + - ' },', - ); - }); - - it('app module contains the import and the module added by needle api', () => { - runResult.assertFileContent( - `${CLIENT_MAIN_SRC_DIR}app/app.config.ts`, - "import { appNameangularNameModule } from './folderName/fileName.module';", - ); - runResult.assertFileContent(`${CLIENT_MAIN_SRC_DIR}app/app.config.ts`, 'appNameangularNameModule,'); - }); -});