diff --git a/generators/angular/cleanup.ts b/generators/angular/cleanup.ts index 30e1a7a99c80..0fb879c1f302 100644 --- a/generators/angular/cleanup.ts +++ b/generators/angular/cleanup.ts @@ -120,7 +120,7 @@ export default asWritingTask(function cleanupOldFilesTask(this, { application }) this.removeFile(`${application.clientSrcDir}app/shared/login/login.component.ts`); this.removeFile(`${application.clientSrcDir}app/shared/login/login.component.html`); this.removeFile(`${application.clientSrcDir}app/core/auth/user-route-access-service.ts`); - if (!application.authenticationTypeSession || !(application as any).communicationSpringWebsocket) { + if (!application.authenticationTypeSession || !application.communicationSpringWebsocket) { this.removeFile(`${application.clientSrcDir}app/core/auth/csrf.service.ts`); } this.removeFolder(`${application.clientSrcDir}app/core/login`); diff --git a/generators/angular/generator.ts b/generators/angular/generator.ts index 5e8cd9047611..cf13b51d9b05 100644 --- a/generators/angular/generator.ts +++ b/generators/angular/generator.ts @@ -16,10 +16,9 @@ * 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 type { Entity } from '../../lib/types/application/entity.js'; 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'; @@ -33,7 +32,7 @@ import { } 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'; @@ -48,10 +47,15 @@ import { isTranslatedAngularFile, translateAngularFilesTransform, } from './support/index.js'; +import type { AngularApplication } from './types.js'; const { ANGULAR } = clientFrameworkTypes; -export default class AngularGenerator extends BaseApplicationGenerator { +export default class AngularGenerator extends BaseApplicationGenerator< + Entity, + AngularApplication, + DefaultTaskTypes +> { localEntities?: any[]; async beforeQueue() { @@ -100,8 +104,15 @@ 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'>) => @@ -196,7 +207,6 @@ export default class AngularGenerator extends BaseApplicationGenerator { returnValue = fieldDefaultValue; } } - return returnValue; }, }); @@ -222,7 +232,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 }), ); }, }); @@ -314,123 +324,6 @@ 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 @@ -459,7 +352,6 @@ export default class AngularGenerator extends BaseApplicationGenerator { generateTestEntityId(primaryKey, index = 0, wrapped = true) { return getTestEntityId(primaryKey, index, wrapped); } - /** * @private * Generate a test entity, for the PK references (when the PK is a composite, derived key) @@ -493,18 +385,4 @@ export default class AngularGenerator extends BaseApplicationGenerator { buildAngularFormPath(reference, prefix = []) { return angularFormPath(reference, prefix); } - - /** - * @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.spec.ts b/generators/angular/support/translate-angular.spec.ts index c4b6f0cd0710..73987f53bcc3 100644 --- a/generators/angular/support/translate-angular.spec.ts +++ b/generators/angular/support/translate-angular.spec.ts @@ -28,10 +28,12 @@ describe('generator - angular - transform', () => { beforeEach(() => { let value = 0; const testImpl = (key, data) => (key === 'blank' ? '' : `translated-value-${key}-${data ? `${inspect(data)}-` : ''}${value++}`); + // @ts-ignore replaceAngularTranslations = createTranslationReplacer(esmocha.fn().mockImplementation(testImpl), { jhiPrefix: 'jhi', enableTranslation: false, }); + // @ts-ignore enabledAngularTranslations = createTranslationReplacer(esmocha.fn().mockImplementation(testImpl), { jhiPrefix: 'jhi', enableTranslation: true, diff --git a/generators/angular/support/translate-angular.ts b/generators/angular/support/translate-angular.ts index 54dfb1eb75d9..7985bf4879d1 100644 --- a/generators/angular/support/translate-angular.ts +++ b/generators/angular/support/translate-angular.ts @@ -41,18 +41,15 @@ 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( - getWebappTranslation, - content, - regexSource, + getWebappTranslation: (s: string, val?: Record | undefined) => string, + content: string, + regexSource: string, { keyIndex = 1, replacementIndex = 1, @@ -81,7 +78,11 @@ function replaceTranslationKeysWithText( * @param {string} jsKey * @returns string with jsKey value replaced */ -function replaceJSTranslation(getWebappTranslation, content, jsKey) { +function replaceJSTranslation( + getWebappTranslation: (s: string, val?: Record | undefined) => string, + content: string, + jsKey: string, +) { return replaceTranslationKeysWithText( getWebappTranslation, content, @@ -98,14 +99,14 @@ function replaceJSTranslation(getWebappTranslation, content, jsKey) { * @param {string} content html content * @returns string with pageTitle replaced */ -function replacePageTitles(getWebappTranslation, content) { +function replacePageTitles(getWebappTranslation: (s: string, val?: Record | undefined) => string, content: string) { return replaceJSTranslation(getWebappTranslation, content, 'title'); } /** * @type {function(import('../generator-base.js'), string): string} */ -function replacePlaceholders(getWebappTranslation, content) { +function replacePlaceholders(getWebappTranslation: (s: string, val?: Record | undefined) => string, content: string) { return replaceTranslationKeysWithText(getWebappTranslation, content, PLACEHOLDER_REGEX, { keyIndex: 2 }); } @@ -114,7 +115,7 @@ function replacePlaceholders(getWebappTranslation, content) { * * @type {function(import('../generator-base.js'), string): string} */ -function replaceErrorMessage(getWebappTranslation, content) { +function replaceErrorMessage(getWebappTranslation: (s: string, val?: Record | undefined) => string, content: string) { return replaceJSTranslation(getWebappTranslation, content, 'errorMessage'); } @@ -123,7 +124,7 @@ function replaceErrorMessage(getWebappTranslation, content) { * Or the translation value if translation is disabled. */ const tagTranslation = ( - getWebappTranslation: any, + getWebappTranslation: (s: string, val?: Record | undefined) => string, { enableTranslation, jhiPrefix }: ReplacerOptions, { key, parsedInterpolate, prefix, suffix }: JHITranslateConverterOptions, ) => { @@ -149,7 +150,7 @@ const tagTranslation = ( * Or the translation value if translation is disabled. */ const validationTagTranslation = ( - getWebappTranslation: any, + getWebappTranslation: (key: string, val?: Record | undefined) => string, { enableTranslation, jhiPrefix }: ReplacerOptions, { key, parsedInterpolate, prefix, suffix }: JHITranslateConverterOptions, ) => { @@ -175,7 +176,7 @@ const validationTagTranslation = ( * Or the translation value if translation is disabled. */ const tagPipeTranslation = ( - getWebappTranslation: any, + getWebappTranslation: (key: string, val?: Record | undefined) => string, { enableTranslation, jhiPrefix }: ReplacerOptions, { key, parsedInterpolate, prefix, suffix }: JHITranslateConverterOptions, ) => { @@ -201,7 +202,7 @@ const tagPipeTranslation = ( * Or the translation value if translation is disabled. */ const tagEnumTranslation = ( - getWebappTranslation: any, + getWebappTranslation: (key: string, val?: Record | undefined) => string, { enableTranslation, jhiPrefix }: ReplacerOptions, { key, parsedInterpolate, prefix, suffix }: JHITranslateConverterOptions, ) => { @@ -222,7 +223,7 @@ const tagEnumTranslation = ( * Or the translation value if translation is disabled. */ const pipeTranslation = ( - getWebappTranslation: any, + getWebappTranslation: (key: string, val?: Record | undefined) => string, { enableTranslation }: ReplacerOptions, { key, prefix, suffix }: JHITranslateConverterOptions, ) => { @@ -237,7 +238,7 @@ const pipeTranslation = ( * Get translation value. */ const valueTranslation = ( - getWebappTranslation: any, + getWebappTranslation: (key: string, val?: Record | undefined) => string, _replacerOptions: ReplacerOptions, { filePath, key, prefix, suffix }: JHITranslateConverterOptions, ) => { @@ -256,7 +257,7 @@ const valueTranslation = ( * Or the translation value if translation is disabled. */ const pipeEnumTranslation = ( - getWebappTranslation: any, + getWebappTranslation: (key: string, val?: Record | undefined) => string, { enableTranslation }: ReplacerOptions, { key, parsedInterpolate, prefix, suffix }: JHITranslateConverterOptions, ) => { @@ -274,7 +275,11 @@ const pipeEnumTranslation = ( const replaceImplementations: Record< string, - (getWebappTranslation: any, replacerOpts: ReplacerOptions, translateOpts: JHITranslateConverterOptions) => string + ( + getWebappTranslation: (key: string, val?: Record | undefined) => string, + replacerOpts: ReplacerOptions, + translateOpts: JHITranslateConverterOptions, + ) => string > = { Tag: tagTranslation, TagPipe: tagPipeTranslation, @@ -291,7 +296,10 @@ const replaceImplementations: Record< * @type {import('../generator-base.js').EditFileCallback} * @this {import('../generator-base.js')} */ -export const createTranslationReplacer = (getWebappTranslation, opts: ReplacerOptions | boolean) => { +export const createTranslationReplacer = ( + getWebappTranslation: (s: string, val?: Record) => string, + opts: ReplacerOptions | boolean, +) => { const htmlJhiTranslateReplacer = createJhiTransformTranslateReplacer(getWebappTranslation, { escapeHtml: true }); const htmlJhiTranslateStringifyReplacer = createJhiTransformTranslateStringifyReplacer(getWebappTranslation); let translationReplacer: ((content: string, filePath: string) => string) | undefined; @@ -309,7 +317,7 @@ export const createTranslationReplacer = (getWebappTranslation, opts: ReplacerOp { 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'), ''); @@ -322,7 +330,7 @@ export const createTranslationReplacer = (getWebappTranslation, opts: ReplacerOp 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)) { @@ -339,7 +347,10 @@ export const createTranslationReplacer = (getWebappTranslation, opts: ReplacerOp 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: (s: string, val?: Record) => string, + 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/types.d.ts b/generators/angular/types.d.ts index 311a20481eaf..b88b53057932 100644 --- a/generators/angular/types.d.ts +++ b/generators/angular/types.d.ts @@ -1 +1,6 @@ -export type AngularApplication = { angularLocaleId: string }; +import type { Entity } from '../../lib/types/application/entity.js'; +import type { ApplicationType } from '../../lib/types/application/application.js'; + +export type AngularApplication = { + angularLocaleId: string; +} & ApplicationType; diff --git a/generators/client/support/template-utils.ts b/generators/client/support/template-utils.ts index ad30cd519080..52948a518edb 100644 --- a/generators/client/support/template-utils.ts +++ b/generators/client/support/template-utils.ts @@ -21,6 +21,7 @@ import path from 'path'; import { clientFrameworkTypes, fieldTypes } from '../../../lib/jhipster/index.js'; import type { PrimaryKey } from '../../../lib/types/application/entity.js'; import type { FieldType } from '../../../lib/application/field-types.js'; +import type { Field } from '../../../lib/types/application/index.js'; import { getEntryIfTypeOrTypeAttribute } from './types-utils.js'; const { STRING: TYPE_STRING, UUID: TYPE_UUID } = fieldTypes.CommonDBTypes; @@ -75,20 +76,22 @@ 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[] | undefined, clientFramework: string) => { const typeImports = new Map(); const uniqueEnums = {}; - fields.forEach(field => { - const { enumFileName, fieldType } = field; - 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'; - const importPath = `${basePath}/${modelPath}/enumerations/${enumFileName}.model`; - uniqueEnums[fieldType] = field.fieldType; - typeImports.set(importType, importPath); - } - }); + if (fields && fields.forEach) { + fields.forEach(field => { + const { enumFileName, fieldType } = field; + 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'; + const importPath = `${basePath}/${modelPath}/enumerations/${enumFileName}.model`; + 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 35cf78e2b8f8..4aab32bf6ab7 100644 --- a/generators/client/types.d.ts +++ b/generators/client/types.d.ts @@ -1,5 +1,4 @@ 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'; @@ -10,7 +9,6 @@ type ApplicationClientProperties = ExportApplicationPropertiesFromCommand ({ - when: () => ['gateway', 'microservice'].includes(gen.jhipsterConfigWithDefaults.applicationType), + when: () => [GATEWAY, MICROSERVICE].includes(gen.jhipsterConfigWithDefaults.applicationType), type: 'list', message: 'Which service discovery server do you want to use?', default: 'consul', @@ -94,8 +94,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, }), @@ -146,14 +146,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 f0029a5731f8..a02c979df828 100644 --- a/generators/spring-boot/generator.ts +++ b/generators/spring-boot/generator.ts @@ -52,6 +52,7 @@ import { APPLICATION_TYPE_MICROSERVICE, applicationTypes, cacheTypes, + clientFrameworkTypes, databaseTypes, fieldTypes, messageBrokerTypes, @@ -72,6 +73,7 @@ const { CASSANDRA, COUCHBASE, MONGODB, NEO4J, SQL } = databaseTypes; const { MICROSERVICE, GATEWAY } = applicationTypes; const { KAFKA, PULSAR } = messageBrokerTypes; const { ELASTICSEARCH } = searchEngineTypes; +const { NO: NO_CLIENT } = clientFrameworkTypes; const { BYTES: TYPE_BYTES, BYTE_BUFFER: TYPE_BYTE_BUFFER } = fieldTypes.RelationalOnlyDBTypes; const { CUCUMBER, GATLING } = testFrameworkTypes; @@ -209,7 +211,7 @@ export default class SpringBootGenerator extends BaseApplicationGenerator { return this.asComposingComponentTaskGroup({ async composing() { const { clientFramework, skipClient } = this.jhipsterConfigWithDefaults; - if (!skipClient && clientFramework !== 'no') { + if (!skipClient && clientFramework !== NO_CLIENT) { // When using prompts, clientFramework will only be known after composing priority. await this.composeWithJHipster('jhipster:java:node'); } @@ -229,7 +231,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.'); @@ -431,14 +433,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'), + }); }, }); } @@ -488,9 +489,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/generators/spring-boot/prompts.ts b/generators/spring-boot/prompts.ts index 8b023b3d559f..5891827f96b1 100644 --- a/generators/spring-boot/prompts.ts +++ b/generators/spring-boot/prompts.ts @@ -103,7 +103,7 @@ export async function askForServerSideOpts(this: CoreGenerator, { control }) { }); } opts.push({ - value: 'couchbase', + value: COUCHBASE, name: '[BETA] Couchbase', }); opts.push({ diff --git a/test/needle-api/needle-client-angular-generator.spec.ts b/test/needle-api/needle-client-angular-generator.spec.ts index 2a1769bc5d79..3df770391fab 100644 --- a/test/needle-api/needle-client-angular-generator.spec.ts +++ b/test/needle-api/needle-client-angular-generator.spec.ts @@ -13,9 +13,6 @@ const mockAngularBlueprintSubGen = class extends AngularGenerator { get [BaseApplicationGenerator.POST_WRITING_ENTITIES]() { return this.asPostWritingEntitiesTaskGroup({ - addToMenuStep() { - this.addElementToAdminMenu('routerName2', 'iconName2', true); - }, addToModuleStep({ source, application }) { source.addEntitiesToClient({ application, @@ -66,24 +63,6 @@ describe('needle API Angular angular generator : JHipster with blueprint', () => ); }); - 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,'); - }); -});