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

typechecking on client generator #27134

Closed
wants to merge 1 commit into from
Closed
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/client/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ const command = {
message: `Do you want to enable ${chalk.yellow('*microfrontends*')}?`,
default: false,
}),
scope: 'storage',
scope: 'storage', // TODO derived property, no need to store
},
microfrontends: {
description: 'Microfrontends to load',
Expand Down
9 changes: 9 additions & 0 deletions generators/client/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ type ClientFrameworkApplication = OptionWithDerivedProperties<'clientFramework',

type ApplicationClientProperties = ExportStoragePropertiesFromCommand<Command>;

export type ClientCommandStorageResult = {
clientFramework: string;
microfrontend: boolean;
clientTestFrameworks: string[];
withAdminUi: boolean;
clientRootDir: string;
microfrontends: string[];
};

export type ClientApplication = ApplicationClientProperties &
ClientFrameworkApplication &
JavaScriptApplication &
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ describe('generators - spring-cloud:gateway - jdl', () => {

before(() => {
jdl = convertSingleContentToJDL({
// @ts-ignore
'generator-jhipster': { baseName: 'bar', [optionName]: ['blog:blog_host:123', 'store:store_host', 'notification'] },
});
});
Expand Down
2 changes: 2 additions & 0 deletions jdl/converters/json-to-jdl-application-converter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ describe('jdl - JSONToJDLApplicationConverter', () => {

before(() => {
jdlObject = convertApplicationsToJDL({
// @ts-ignore
applications: [{ 'generator-jhipster': { baseName: 'toto', applicationType: MONOLITH } }],
});
});
Expand All @@ -59,6 +60,7 @@ describe('jdl - JSONToJDLApplicationConverter', () => {
const previousJDLObject = new JDLObject();
previousJDLObject.addApplication(createJDLApplication({ baseName: 'tata', applicationType: MONOLITH }));
jdlObject = convertApplicationsToJDL({
// @ts-ignore
applications: [{ 'generator-jhipster': { baseName: 'toto', applicationType: MONOLITH } }],
jdl: previousJDLObject,
});
Expand Down
2 changes: 2 additions & 0 deletions jdl/converters/json-to-jdl-converter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ describe('jdl - JSONToJDLConverter', () => {
let jdl;
beforeEach(() => {
jdl = convertSingleContentToJDL({
//@ts-ignore
'generator-jhipster': {
baseName: 'x',
microfrontends: [
Expand All @@ -414,6 +415,7 @@ describe('jdl - JSONToJDLConverter', () => {
describe('with nullish attributes', () => {
it('should not fail', () => {
convertSingleContentToJDL({
//@ts-ignore
'generator-jhipster': {
baseName: 'x',
blueprints: null,
Expand Down
7 changes: 5 additions & 2 deletions jdl/converters/types.d.ts
Tcharl marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { RelationshipSide, RelationshipType } from '../basic-types/relationships.js';
import { GENERATOR_JHIPSTER } from '../../generators/index.js';
import { ClientCommandStorageResult } from '../../generators/client/types.js';

export type JSONField = {
fieldName: string;
Expand Down Expand Up @@ -86,12 +87,14 @@ export type JSONGeneratorJhipsterContent = {
promptValues?: Partial<JSONGeneratorJhipsterContent>;
blueprints?: JSONBlueprint[] | null;
microfrontends?: JSONMicrofrontend[] | null;
} & AbstractJSONGeneratorJhipsterContent;
} & AbstractJSONGeneratorJhipsterContent &
Omit<ClientCommandStorageResult, 'microfrontends'>;

export type PostProcessedJSONGeneratorJhipsterContent = {
blueprints?: string[];
microfrontends?: string[];
} & AbstractJSONGeneratorJhipsterContent;
} & AbstractJSONGeneratorJhipsterContent &
Omit<ClientCommandStorageResult, 'microfrontends'>;

export type PostProcessedJSONRootObject = {
[GENERATOR_JHIPSTER]: PostProcessedJSONGeneratorJhipsterContent;
Expand Down
46 changes: 32 additions & 14 deletions jdl/jhipster/default-application-options.ts
Tcharl marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import { MESSAGE_BROKER, MESSAGE_BROKER_NO } from '../../generators/server/options/index.js';
import { ClientCommandStorageResult } from '../../generators/client/types.js';
import applicationTypes from './application-types.js';
import authenticationTypes from './authentication-types.js';
import databaseTypes from './database-types.js';
Expand Down Expand Up @@ -50,7 +51,6 @@ const {
CLIENT_FRAMEWORK,
CLIENT_THEME,
CLIENT_THEME_VARIANT,
WITH_ADMIN_UI,
DATABASE_TYPE,
DEV_DATABASE_TYPE,
DTO_SUFFIX,
Expand Down Expand Up @@ -89,7 +89,7 @@ const commonDefaultOptions = {
[WEBSOCKET]: (OptionValues[WEBSOCKET] as Record<string, string>).no,
};

export function getConfigWithDefaults(customOptions: string | Record<string, any> = {}) {
export function getConfigWithDefaults(customOptions: string | Record<string, any> = {}): any & ClientCommandStorageResult {
const applicationType = typeof customOptions === 'string' ? customOptions : customOptions.applicationType;
if (applicationType === GATEWAY) {
return getConfigForGatewayApplication(customOptions);
Expand All @@ -100,13 +100,37 @@ export function getConfigWithDefaults(customOptions: string | Record<string, any
return getConfigForMonolithApplication(customOptions);
}

export function getConfigForClientApplication(options: any = {}): any {
export function getConfigForClientCommand(options: any & Partial<ClientCommandStorageResult> = {}): any & ClientCommandStorageResult {
if (options[SKIP_CLIENT]) {
options[CLIENT_FRAMEWORK] = NO_CLIENT_FRAMEWORK;
options.clientFramework = NO_CLIENT_FRAMEWORK;
} else if (options[CLIENT_FRAMEWORK] === undefined) {
if (options[APPLICATION_TYPE] === MICROSERVICE) {
options.clientFramework = NO_CLIENT_FRAMEWORK;
} else {
options.clientFramework = ANGULAR;
}
}
if (options[OptionNames.MICROFRONTEND] === undefined) {
options[OptionNames.MICROFRONTEND] = Boolean(options[OptionNames.MICROFRONTENDS]?.length);
options.microfrontend = Boolean(options.microfrontends?.length);
}
if (options[TEST_FRAMEWORKS] === undefined) {
options[TEST_FRAMEWORKS] = [];
}
if (options.clientTestFrameworks !== undefined) {
options[TEST_FRAMEWORKS] = [...new Set([...(options[TEST_FRAMEWORKS] ?? []), ...options.clientTestFrameworks])];
}
if (options.withAdminUi === undefined) {
if (options[APPLICATION_TYPE] === MICROSERVICE) {
options.withAdminUi = false;
} else {
options.withAdminUi = true;
}
}
return options;
}

export function getConfigForClientApplication(options: any = {}): any & ClientCommandStorageResult {
options = getConfigForClientCommand(options);
const clientFramework = options[CLIENT_FRAMEWORK];
if (clientFramework !== NO_CLIENT_FRAMEWORK) {
if (!options[CLIENT_THEME]) {
Expand Down Expand Up @@ -199,10 +223,8 @@ export function getServerConfigForMonolithApplication(customOptions: any = {}):
const options = {
...commonDefaultOptions,
[CACHE_PROVIDER]: EHCACHE,
[CLIENT_FRAMEWORK]: ANGULAR,
[SERVER_PORT]: OptionValues[SERVER_PORT],
[SERVICE_DISCOVERY_TYPE]: NO_SERVICE_DISCOVERY,
[WITH_ADMIN_UI]: true,
...customOptions,
};
return {
Expand All @@ -225,10 +247,8 @@ export function getConfigForMonolithApplication(customOptions: any = {}): any {
export function getServerConfigForGatewayApplication(customOptions: any = {}): any {
const options = {
...commonDefaultOptions,
[CLIENT_FRAMEWORK]: ANGULAR,
[SERVER_PORT]: OptionValues[SERVER_PORT],
[SERVICE_DISCOVERY_TYPE]: CONSUL,
[WITH_ADMIN_UI]: true,
...customOptions,
};
options[CACHE_PROVIDER] = NO_CACHE_PROVIDER;
Expand All @@ -241,7 +261,7 @@ export function getServerConfigForGatewayApplication(customOptions: any = {}): a
};
}

export function getConfigForGatewayApplication(customOptions: any = {}): any {
export function getConfigForGatewayApplication(customOptions: any = {}): any & ClientCommandStorageResult {
let options = getServerConfigForGatewayApplication(customOptions);
options = getConfigForClientApplication(options);
options = getConfigForPackageName(options);
Expand All @@ -252,26 +272,24 @@ export function getConfigForGatewayApplication(customOptions: any = {}): any {
return getConfigForAuthenticationType(options);
}

export function getServerConfigForMicroserviceApplication(customOptions: any = {}): any {
export function getServerConfigForMicroserviceApplication(customOptions: any = {}): any & ClientCommandStorageResult {
const DEFAULT_SERVER_PORT = 8081;
const options = {
...commonDefaultOptions,
[CACHE_PROVIDER]: HAZELCAST,
[SERVER_PORT]: DEFAULT_SERVER_PORT,
[SERVICE_DISCOVERY_TYPE]: CONSUL,
[SKIP_USER_MANAGEMENT]: true,
[CLIENT_FRAMEWORK]: NO_CLIENT_FRAMEWORK,
...customOptions,
};

options[WITH_ADMIN_UI] = false;
return {
...options,
[APPLICATION_TYPE]: MICROSERVICE,
};
}

export function getConfigForMicroserviceApplication(customOptions: any = {}): any {
export function getConfigForMicroserviceApplication(customOptions: any = {}): any & ClientCommandStorageResult {
let options = getServerConfigForMicroserviceApplication(customOptions);
options = getConfigForClientApplication(options);
options = getConfigForPackageName(options);
Expand Down
Loading