Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add type to applicationDefaults #27383

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion generators/angular/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export default class AngularGenerator extends BaseApplicationGenerator {
__override__: true,
eslintConfigFile: app => `eslint.config.${app.packageJsonType === 'module' ? 'js' : 'mjs'}`,
webappEnumerationsDir: app => `${app.clientSrcDir}app/entities/enumerations/`,
angularLocaleId: app => app.nativeLanguageDefinition.angularLocale ?? defaultLanguage.angularLocale,
angularLocaleId: app => app.nativeLanguageDefinition.angularLocale ?? defaultLanguage.angularLocale!,
});

application.addPrettierExtensions?.(['html', 'css', 'scss']);
Expand Down
12 changes: 5 additions & 7 deletions generators/base-application/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,7 @@ const asPriority = BaseGenerator.asPriority;
* This is the base class for a generator that generates entities.
*/
export default class BaseApplicationGenerator<
E extends Entity = Entity,
A extends ApplicationType<E> = ApplicationType<E>,
TaskTypes extends DefaultTaskTypes<any, any> = DefaultTaskTypes<E, A>,
TaskTypes extends DefaultTaskTypes<any, any> = DefaultTaskTypes,
> extends BaseGenerator<TaskTypes> {
static CONFIGURING_EACH_ENTITY = asPriority(CONFIGURING_EACH_ENTITY);

Expand All @@ -96,7 +94,7 @@ export default class BaseApplicationGenerator<
static POST_WRITING_ENTITIES = asPriority(POST_WRITING_ENTITIES);

declare jhipsterConfig: ApplicationConfiguration & Record<string, any>;
declare sharedData: SharedData<A>;
declare sharedData: SharedData<ApplicationType>;

constructor(args: string | string[], options: JHipsterGeneratorOptions, features: JHipsterGeneratorFeatures) {
super(args, options, features);
Expand Down Expand Up @@ -187,16 +185,16 @@ export default class BaseApplicationGenerator<
/**
* get sorted list of entities according to changelog date (i.e. the order in which they were added)
*/
getExistingEntities(): { name: string; definition: E }[] {
getExistingEntities(): { name: string; definition: Entity }[] {
function isBefore(e1, e2) {
return (e1.definition.annotations?.changelogDate ?? 0) - (e2.definition.annotations?.changelogDate ?? 0);
}

const configDir = this.getEntitiesConfigPath();

const entities: { name: string; definition: E }[] = [];
const entities: { name: string; definition: Entity }[] = [];
for (const entityName of [...new Set(((this.jhipsterConfig.entities as string[]) || []).concat(getEntitiesFromDir(configDir)))]) {
const definition: E = this.getEntityConfig(entityName)?.getAll() as unknown as E;
const definition: Entity = this.getEntityConfig(entityName)?.getAll() as unknown as Entity;
if (definition) {
entities.push({ name: entityName, definition });
}
Expand Down
14 changes: 5 additions & 9 deletions generators/base-application/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export type BaseApplication = {

nodeVersion: string;
nodePackageManager: string;
/* @deprecated use nodePackageManager */
clientPackageManager: string;
nodeDependencies: Record<string, string>;

skipClient?: boolean;
Expand Down Expand Up @@ -104,16 +106,13 @@ type UserManagement<Entity> = {
userManagement: Entity;
authority: Entity;
};

type JwtApplication = {
jwtSecretKey: string;
};

type Oauth2Application = {
jwtSecretKey: string;
generateBuiltInUserEntity?: boolean;
user: any;
generateBuiltInAuthorityEntity: false;
generateUserManagement: false;
syncUserWithIdp?: boolean;
};

type SessionApplication = {
Expand Down Expand Up @@ -177,11 +176,8 @@ export type CommonClientServerApplication<Entity> = BaseApplication &

dockerServicesDir?: string;
dockerServices?: string[];
prettierFolders?: string;
prettierExtensions?: string;

skipUserManagement?: boolean;
syncUserWithIdp?: boolean;
generateUserManagement?: boolean;
};

type ServiceDiscoveryApplication = OptionWithDerivedProperties<'serviceDiscoveryType', ['no', 'eureka', 'consul']>;
Expand Down
9 changes: 2 additions & 7 deletions generators/base-entity-changes/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import { loadEntitiesAnnotations, loadEntitiesOtherSide } from '../base-applicat
import { relationshipEquals, relationshipNeedsForeignKeyRecreationOnly } from '../liquibase/support/index.js';
import { addEntitiesOtherRelationships } from '../server/support/index.js';
import type { TaskTypes as ApplicationTaskTypes } from '../../lib/types/application/tasks.js';
import type { ApplicationType } from '../../lib/types/application/application.js';
import type { Entity } from '../../lib/types/application/entity.js';
import type { BaseChangelog } from './types.js';

const { DEFAULT, WRITING_ENTITIES, POST_WRITING_ENTITIES } = PRIORITY_NAMES;
Expand All @@ -44,7 +42,7 @@ const baseChangelog: () => Omit<BaseChangelog, 'changelogDate' | 'entityName' |
changelogData: {},
});

type TaskTypes<E, A> = ApplicationTaskTypes<E, A> & {
type TaskTypes = ApplicationTaskTypes & {
DefaultTaskParam: { entityChanges?: BaseChangelog[] };
WritingEntitiesTaskParam: { entityChanges?: BaseChangelog[] };
PostWritingEntitiesTaskParam: { entityChanges?: BaseChangelog[] };
Expand All @@ -53,10 +51,7 @@ type TaskTypes<E, A> = ApplicationTaskTypes<E, A> & {
/**
* This is the base class for a generator for every generator.
*/
export default abstract class GeneratorBaseEntityChanges<
E extends Entity = Entity,
A extends ApplicationType<E> = ApplicationType<E>,
> extends GeneratorBaseApplication<E, A, TaskTypes<E, A>> {
export default abstract class GeneratorBaseEntityChanges extends GeneratorBaseApplication<TaskTypes> {
recreateInitialChangelog!: boolean;
private entityChanges!: any[];

Expand Down
4 changes: 2 additions & 2 deletions generators/bootstrap-application-base/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export default class BootstrapApplicationBase extends BaseApplicationGenerator {

backendTypeSpringBoot: ({ backendType }) => backendType === 'Java',
backendTypeJavaAny: ({ backendTypeSpringBoot }) => backendTypeSpringBoot,
clientFrameworkBuiltIn: ({ clientFramework }) => ['angular', 'vue', 'react'].includes(clientFramework),
clientFrameworkBuiltIn: ({ clientFramework }) => ['angular', 'vue', 'react'].includes(clientFramework!),
});
},
userRelationship({ applicationDefaults }) {
Expand Down Expand Up @@ -218,7 +218,7 @@ export default class BootstrapApplicationBase extends BaseApplicationGenerator {
applicationDefaults({
generateBuiltInUserEntity: ({ generateUserManagement, syncUserWithIdp }) => generateUserManagement || syncUserWithIdp,
generateBuiltInAuthorityEntity: ({ generateBuiltInUserEntity, databaseType }) =>
generateBuiltInUserEntity && databaseType !== 'cassandra',
generateBuiltInUserEntity! && databaseType !== 'cassandra',
});
},
});
Expand Down
2 changes: 1 addition & 1 deletion generators/bootstrap-application/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default class BootstrapApplicationGenerator extends BaseApplicationGenera
applicationDefaults({
// TODO remove prettierExtensions, moved to prettier generator
prettierExtensions,
useNpmWrapper: application => application.clientFrameworkAny && application.backendTypeJavaAny,
useNpmWrapper: application => Boolean(application.clientFrameworkAny && application.backendTypeJavaAny),
documentationArchiveUrl: ({ jhipsterVersion }) =>
`${JHIPSTER_DOCUMENTATION_URL}${JHIPSTER_DOCUMENTATION_ARCHIVE_PATH}v${jhipsterVersion}`,
});
Expand Down
1 change: 1 addition & 0 deletions generators/client/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type ClientApplication = ApplicationClientProperties &
AngularApplication &
CypressApplication & {
webappLoginRegExp: string;
clientWebappDir?: string;
webappEnumerationsDir?: string;
clientFrameworkBuiltIn?: boolean;
};
Expand Down
1 change: 1 addition & 0 deletions generators/java/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export type JavaApplication = JavaBootstrapStorageProperties &
imperativeOrReactive: string;

addOpenapiGeneratorPlugin: boolean;
useNpmWrapper: boolean;
};

export type ConditionalJavaDefinition = JavaDefinition & { condition?: boolean };
Expand Down
2 changes: 1 addition & 1 deletion generators/server/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default class JHipsterServerGenerator extends BaseApplicationGenerator {
ANGULAR,
VUE,
REACT,
});
} as any);

if (this.projectVersion) {
application.projectVersion = this.projectVersion;
Expand Down
1 change: 1 addition & 0 deletions generators/server/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export type SpringBootApplication = JavaApplication &
databaseMigrationLiquibase: boolean;

communicationSpringWebsocket: boolean;
anyEntityHasRelationshipWithUser: boolean;
requiresDeleteAllUsers: boolean;
reactorBlock: string;
reactorBlockOptional: string;
Expand Down
5 changes: 3 additions & 2 deletions lib/types/application/application.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import type { ClientSourceType } from '../../../generators/client/types.js';
import type { LanguagesSource } from '../../../generators/languages/types.js';
import type { SpringBootSourceType } from '../../../generators/server/types.js';
import type { ExportApplicationPropertiesFromCommand } from '../../command/types.js';
import { Entity } from './entity.js';

export type ApplicationType<Entity> = BaseApplication &
CommonClientServerApplication<Entity> &
export type ApplicationType<E = Entity> = BaseApplication &
CommonClientServerApplication<E> &
ExportApplicationPropertiesFromCommand<typeof import('../../../generators/spring-boot/command.ts').default>;

export type BaseApplicationSource = SpringBootSourceType & ClientSourceType & LanguagesSource;
18 changes: 14 additions & 4 deletions lib/types/application/tasks.d.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import type { Storage } from 'yeoman-generator';
import type { Merge } from 'type-fest';
import type { Merge, OmitIndexSignature, Simplify } from 'type-fest';
import type { Entity as BaseEntity } from '../base/entity.js';
import type { GetFieldType, GetRelationshipType } from '../utils/entity-utils.ts';
import type { TaskTypes as BaseTaskTypes, TaskParamWithControl, TaskParamWithSource } from '../base/tasks.js';
import type { Entity } from './entity.js';
import type { ApplicationType, BaseApplicationSource } from './application.js';

type ApplicationDefaultsTaskParam = {
type ApplicationDefaultsTaskParam<E = Entity, A = ApplicationType<E>> = {
/**
* Parameter properties accepts:
* - functions: receives the application and the return value is set at the application property.
Expand All @@ -22,7 +22,17 @@ type ApplicationDefaultsTaskParam = {
* { prop: ({ prop }) => prop + '-bar', prop2: 'won\'t override' },
* );
*/
applicationDefaults: (...defaults: Record<any, any>[]) => void;
applicationDefaults: (
...defaults: Simplify<
OmitIndexSignature<{
[Key in keyof (Partial<A> & { __override__?: boolean })]?: Key extends '__override__'
? boolean
: Key extends keyof A
? A[Key] | ((ctx: A) => A[Key])
: never;
}>
>[]
) => void;
};

type TaskParamWithApplication<E = Entity, A = ApplicationType<E>> = TaskParamWithControl & {
Expand All @@ -35,7 +45,7 @@ type TaskParamWithEntities<E = Entity, A = ApplicationType<E>> = TaskParamWithAp

type TaskParamWithApplicationDefaults<E = Entity, A = ApplicationType<E>> = TaskParamWithControl &
TaskParamWithApplication<E, A> &
ApplicationDefaultsTaskParam;
ApplicationDefaultsTaskParam<E, A>;

type PreparingTaskParam<E = Entity, A = ApplicationType<E>> = TaskParamWithApplicationDefaults<E, A> &
TaskParamWithSource<BaseApplicationSource>;
Expand Down
Loading