Skip to content

Commit

Permalink
add type to applicationDefaults
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Nov 4, 2024
1 parent ca2e07f commit c18c105
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion generators/angular/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export default class AngularGenerator extends BaseApplicationGenerator {
eslintConfigFile: app => `eslint.config.${app.packageJsonType === 'module' ? 'js' : 'mjs'}`,
webappEnumerationsDir: app => `${app.clientSrcDir}app/entities/enumerations/`,
angularLocaleId: app => app.nativeLanguageDefinition.angularLocale ?? defaultLanguage.angularLocale,
});
} as any);

application.addPrettierExtensions?.(['html', 'css', 'scss']);
},
Expand Down
13 changes: 8 additions & 5 deletions generators/bootstrap-application-base/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,15 @@ export default class BootstrapApplicationBase extends BaseApplicationGenerator {
prepareApplication({ application, applicationDefaults }) {
loadDerivedAppConfig({ application });

applicationDefaults({
// TODO drop clientPackageManager
clientPackageManager: ({ nodePackageManager }) => nodePackageManager,
} as any);

applicationDefaults({
__override__: false,
nodePackageManager: 'npm',
dockerServicesDir: JAVA_DOCKER_DIR,
// TODO drop clientPackageManager
clientPackageManager: ({ nodePackageManager }) => nodePackageManager,
hipsterName: 'Java Hipster',
hipsterProductName: 'JHipster',
hipsterHomePageProductName: 'JHipster',
Expand All @@ -187,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 All @@ -196,7 +199,7 @@ export default class BootstrapApplicationBase extends BaseApplicationGenerator {
anyEntityHasRelationshipWithUser: this.getExistingEntities().some(entity =>
(entity.definition.relationships ?? []).some(relationship => relationship.otherEntityName.toLowerCase() === 'user'),
),
});
} as any);
},
syncUserWithIdp({ application, applicationDefaults }) {
if (!application.backendTypeSpringBoot) return;
Expand All @@ -216,7 +219,7 @@ export default class BootstrapApplicationBase extends BaseApplicationGenerator {
generateBuiltInUserEntity: ({ generateUserManagement, syncUserWithIdp }) => generateUserManagement || syncUserWithIdp,
generateBuiltInAuthorityEntity: ({ generateBuiltInUserEntity, databaseType }) =>
generateBuiltInUserEntity && databaseType !== 'cassandra',
});
} as any);
},
});
}
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 @@ -86,7 +86,7 @@ export default class BootstrapApplicationGenerator extends BaseApplicationGenera
useNpmWrapper: application => application.clientFrameworkAny && application.backendTypeJavaAny,
documentationArchiveUrl: ({ jhipsterVersion }) =>
`${JHIPSTER_DOCUMENTATION_URL}${JHIPSTER_DOCUMENTATION_ARCHIVE_PATH}v${jhipsterVersion}`,
});
} as any);
},
});
}
Expand Down
2 changes: 1 addition & 1 deletion generators/javascript/generators/prettier/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default class PrettierGenerator extends BaseApplicationGenerator {
applicationDefaults({
prettierFolders: ',**/',
prettierExtensions: 'md,json,yml,js,cjs,mjs,ts,cts,mts',
});
} as any);

application.addPrettierExtensions = (extensions: string[]) => {
const currentExtensions = application.prettierExtensions!.split(',');
Expand Down
2 changes: 1 addition & 1 deletion generators/server/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export default class JHipsterServerGenerator extends BaseApplicationGenerator {
ANGULAR,
VUE,
REACT,
});
} as any);

if (this.projectVersion) {
application.projectVersion = this.projectVersion;
Expand Down
2 changes: 1 addition & 1 deletion generators/vue/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default class VueGenerator extends BaseApplicationGenerator {
eslintConfigFile: app => `eslint.config.${app.packageJsonType === 'module' ? 'js' : 'mjs'}`,
clientWebappDir: app => `${app.clientSrcDir}app/`,
webappEnumerationsDir: app => `${app.clientWebappDir}shared/model/enumerations/`,
});
} as any);
},
prepareForTemplates({ application, source }) {
application.addPrettierExtensions?.(['html', 'vue', 'css', 'scss']);
Expand Down
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

0 comments on commit c18c105

Please sign in to comment.