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 types to jhipsterConfig and jhipsterConfigWithDefaults #27203

Merged
merged 1 commit into from
Sep 8, 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
4 changes: 2 additions & 2 deletions generators/app/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
GENERATOR_SERVER,
} from '../generator-list.js';

const command: JHipsterCommandDefinition = {
const command = {
options: {
defaults: {
description: 'Execute jhipster with default config',
Expand Down Expand Up @@ -97,6 +97,6 @@ const command: JHipsterCommandDefinition = {
GENERATOR_CYPRESS,
GENERATOR_LANGUAGES,
],
};
} as const satisfies JHipsterCommandDefinition;

export default command;
3 changes: 3 additions & 0 deletions generators/base-application/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import type { TaskTypes as DefaultTaskTypes } from '../../lib/types/application/
import type { ApplicationType } from '../../lib/types/application/application.js';
import type { Entity } from '../../lib/types/application/entity.js';
import type { GenericTaskGroup } from '../../lib/types/base/tasks.js';
import type { ApplicationConfiguration } from '../../lib/types/application/yo-rc.js';
import { getEntitiesFromDir } from './support/index.js';
import { CUSTOM_PRIORITIES, PRIORITY_NAMES, QUEUES } from './priorities.js';

Expand Down Expand Up @@ -93,6 +94,8 @@ export default class BaseApplicationGenerator<

static POST_WRITING_ENTITIES = asPriority(POST_WRITING_ENTITIES);

declare jhipsterConfig: ApplicationConfiguration & Record<string, any>;

constructor(args: string | string[], options: JHipsterGeneratorOptions, features: JHipsterGeneratorFeatures) {
super(args, options, features);

Expand Down
3 changes: 2 additions & 1 deletion generators/base-core/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import { getConfigWithDefaults } from '../../jdl/jhipster/index.js';
import { extractArgumentsFromConfigs } from '../../lib/command/index.js';
import type { Entity } from '../../lib/types/base/entity.js';
import type BaseApplicationGenerator from '../base-application/generator.js';
import type { ApplicationConfiguration } from '../../lib/types/application/yo-rc.js';

const {
INITIALIZING,
Expand Down Expand Up @@ -246,7 +247,7 @@ export default class CoreGenerator extends YeomanGenerator<JHipsterGeneratorOpti
/**
* JHipster config with default values fallback
*/
get jhipsterConfigWithDefaults() {
get jhipsterConfigWithDefaults(): Readonly<ApplicationConfiguration & Record<string, any>> {
const configWithDefaults = getConfigWithDefaults(removeFieldsWithNullishValues(this.config.getAll()));
defaults(configWithDefaults, {
skipFakeData: false,
Expand Down
6 changes: 2 additions & 4 deletions generators/client/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ const command = {
},
},
import: [GENERATOR_COMMON],
} as const;
} as const satisfies JHipsterCommandDefinition;

export type Command = typeof command;

export default command as JHipsterCommandDefinition;
export default command;
2 changes: 1 addition & 1 deletion generators/client/prompts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const askForClientTheme = asPromptingTask(async function askForClientThem
{
type: 'list',
name: 'clientTheme',
when: () => ['angular', 'react', 'vue'].includes(config.clientFramework),
when: () => ['angular', 'react', 'vue'].includes(config.clientFramework!),
message: 'Would you like to use a Bootswatch theme (https://bootswatch.com/)?',
choices: async () => {
const bootswatchChoices = await retrieveOnlineBootswatchThemes().catch(errorMessage => {
Expand Down
7 changes: 3 additions & 4 deletions generators/client/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import type { addIconImport, addItemToMenu, addRoute } from '../angular/support/needles.js';
import type { AngularApplication } from '../angular/types.js';
import type { ExportApplicationPropertiesFromCommand, ExportStoragePropertiesFromCommand } from '../../lib/command/index.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 { Command } from './command.ts';
import type Command from './command.ts';

export type StoredClientProperties = ExportStoragePropertiesFromCommand<Command>;
type ApplicationClientProperties = ExportApplicationPropertiesFromCommand<Command>;
type ApplicationClientProperties = ExportApplicationPropertiesFromCommand<typeof Command>;

export type ClientApplication = ApplicationClientProperties &
JavaScriptApplication &
Expand Down
10 changes: 8 additions & 2 deletions generators/spring-boot/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { applicationTypes, authenticationTypes } from '../../jdl/jhipster/index.
const { OAUTH2, SESSION, JWT } = authenticationTypes;
const { GATEWAY, MICROSERVICE } = applicationTypes;

const command: JHipsterCommandDefinition = {
const command = {
options: {
fakeKeytool: {
description: 'Add a fake certificate store file for test purposes',
Expand All @@ -46,6 +46,7 @@ const command: JHipsterCommandDefinition = {
type: 'confirm',
message: 'Do you want to make it reactive with Spring WebFlux?',
}),
scope: 'storage',
},
serverPort: {
prompt: gen => ({
Expand All @@ -61,6 +62,7 @@ const command: JHipsterCommandDefinition = {
gen.jhipsterConfig.serverPort = 8080 + gen.jhipsterConfig.applicationIndex;
}
},
scope: 'storage',
},
serviceDiscoveryType: {
cli: {
Expand All @@ -78,6 +80,7 @@ const command: JHipsterCommandDefinition = {
{ value: 'eureka', name: 'JHipster Registry (legacy, uses Eureka, provides Spring Cloud Config support)' },
{ value: 'no', name: 'No service discovery' },
],
scope: 'storage',
},
authenticationType: {
cli: {
Expand Down Expand Up @@ -112,6 +115,7 @@ const command: JHipsterCommandDefinition = {
gen.jhipsterConfig.jwtSecretKey = createBase64Secret(64, gen.options.reproducibleTests);
}
},
scope: 'storage',
},
feignClient: {
description: 'Generate a feign client',
Expand All @@ -130,6 +134,7 @@ const command: JHipsterCommandDefinition = {
tokenType: 'BOOLEAN',
},
default: false,
scope: 'storage',
},
syncUserWithIdp: {
description: 'Allow relationships with User for oauth2 applications',
Expand All @@ -150,6 +155,7 @@ const command: JHipsterCommandDefinition = {
throw new Error('syncUserWithIdp is only supported with authenticationType oauth2');
}
},
scope: 'storage',
},
defaultPackaging: {
description: 'Default packaging for the application',
Expand All @@ -168,6 +174,6 @@ const command: JHipsterCommandDefinition = {
},
},
import: [GENERATOR_JAVA, GENERATOR_LIQUIBASE, GENERATOR_SPRING_DATA_RELATIONAL],
};
} as const satisfies JHipsterCommandDefinition;

export default command;
2 changes: 1 addition & 1 deletion lib/command/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ type ExplodeCommandChoicesNoInference<U extends ParseableConfigs> = {
};

type PrepareConfigsWithType<U extends ParseableConfigs> = Simplify<{
[K in keyof U]?: U[K] extends Record<'choices', JHispterChoices>
-readonly [K in keyof U]?: U[K] extends Record<'choices', JHispterChoices>
? TupleToUnion<NormalizeChoices<U[K]['choices']>>
: WrapperToPrimitive<ConstructorReturn<GetType<U[K]>>> extends infer T
? T extends undefined
Expand Down
11 changes: 11 additions & 0 deletions lib/types/application/yo-rc.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* eslint-disable @typescript-eslint/consistent-type-imports */
import { Simplify } from 'type-fest';
import type { ExportStoragePropertiesFromCommand } from '../../command/types.js';

export type ApplicationConfiguration = Simplify<
{
jhipsterVersion: string;
baseName: string;
} & ExportStoragePropertiesFromCommand<typeof import('../../../generators/client/command.js').default> &
ExportStoragePropertiesFromCommand<typeof import('../../../generators/spring-boot/command.js').default>
>;
Loading