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

cleanup jdl and reduce dependency on jhipster #27151

Merged
merged 8 commits into from
Sep 2, 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
18 changes: 0 additions & 18 deletions jdl/__snapshots__/jdl-importer.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -670,24 +670,6 @@ exports[`jdl - JDLImporter import when parsing deployment config should export t
"serviceDiscoveryType": "consul",
},
},
{
"generator-jhipster": {
"appsFolders": [
"tata",
"titi",
],
"clusteredDbApps": [],
"deploymentType": "openshift",
"directoryPath": "../",
"dockerPushCommand": "docker push",
"dockerRepositoryName": "test",
"monitoring": "no",
"openshiftNamespace": "default",
"registryReplicas": 2,
"serviceDiscoveryType": "consul",
"storageType": "ephemeral",
},
},
]
`;

Expand Down
5 changes: 0 additions & 5 deletions jdl/__test-files__/deployments.jdl
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,3 @@ deployment {
dockerRepositoryName "test"
kubernetesStorageClassName "KubernetesStorageClassName"
}
deployment {
deploymentType openshift,
appsFolders [tata, titi],
dockerRepositoryName "test"
}
12 changes: 0 additions & 12 deletions jdl/built-in-options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,5 @@ export {
/** @deprecated */
deploymentOptions,
/** @deprecated */
searchEngineTypes,
/** @deprecated */
entityOptions,
/** @deprecated */
jhipsterOptionTypes,
/** @deprecated */
jhipsterOptionValues,
/** @deprecated */
jhipsterQuotedOptionNames,
/** @deprecated */
clientFrameworkTypes,
/** @deprecated */
serviceDiscoveryTypes,
} from '../jhipster/index.js';
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { describe, it } from 'esmocha';
import { expect } from 'chai';
import { applicationOptions } from '../built-in-options/index.js';
import { applicationOptions } from '../jhipster/index.js';
import JDLApplicationDefinition from './jdl-application-definition.js';

const { OptionNames } = applicationOptions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { jhipsterOptionTypes, jhipsterOptionValues, jhipsterQuotedOptionNames } from '../built-in-options/index.js';
import { jhipsterOptionTypes, jhipsterOptionValues, jhipsterQuotedOptionNames } from '../jhipster/index.js';

export type JDLApplicationOptionValue = string | number | boolean | undefined | never[] | Record<string, string>;
export type JDLApplicationOptionTypeValue = 'string' | 'integer' | 'boolean' | 'list' | 'quotedList';
Expand Down
10 changes: 3 additions & 7 deletions jdl/converters/jdl-to-json/jdl-to-json-option-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,14 @@
*/

import logger from '../../utils/objects/logger.js';
import { binaryOptions, entityOptions, searchEngineTypes, unaryOptions } from '../../built-in-options/index.js';
import { binaryOptions, unaryOptions } from '../../built-in-options/index.js';
import JDLObject from '../../models/jdl-object.js';
import JDLApplication from '../../models/jdl-application.js';
import AbstractJDLOption from '../../models/abstract-jdl-option.js';
import JDLBinaryOption from '../../models/jdl-binary-option.js';

const { FILTER, NO_FLUENT_METHOD, READ_ONLY, EMBEDDED, SKIP_CLIENT, SKIP_SERVER } = unaryOptions;

const { ServiceTypes } = entityOptions;
const { NO: NO_SEARCH_ENGINE } = searchEngineTypes;

const NO_SERVICE = ServiceTypes.NO;
const {
Options: { ANGULAR_SUFFIX, MICROSERVICE, SEARCH, DTO },
} = binaryOptions;
Expand Down Expand Up @@ -82,7 +78,7 @@ function setOptionsToEachEntityName(jdlOption: AbstractJDLOption): void {
});
jdlOption.entityNames.forEach(entityName => {
const serviceOptionValue = convertedOptionContent.get(entityName).service;
if ((!serviceOptionValue || serviceOptionValue === NO_SERVICE) && [DTO, FILTER].includes(jdlOption.name)) {
if ((!serviceOptionValue || serviceOptionValue === 'no') && [DTO, FILTER].includes(jdlOption.name)) {
logger.info(
`The ${jdlOption.name} option is set for ${entityName}, the '${serviceClassOptionValue}' value for the ` +
"'service' is gonna be set for this entity if no other value has been set.",
Expand Down Expand Up @@ -120,7 +116,7 @@ function getJSONOptionKeyAndValue(jdlOption: AbstractJDLOption): { key: string;

function preventEntitiesFromBeingSearched(entityNames: Set<string>) {
entityNames.forEach(entityName => {
setOptionToEntityName({ optionName: 'searchEngine', optionValue: NO_SEARCH_ENGINE }, entityName);
setOptionToEntityName({ optionName: 'searchEngine', optionValue: 'no' }, entityName);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('jdl - DeploymentConverter', () => {
before(() => {
convertedDeployments = convertDeployments([
{
deploymentType: 'openshift',
deploymentType: 'docker-compose',
appsFolders: ['tata', 'titi'],
dockerRepositoryName: 'test',
},
Expand All @@ -50,20 +50,17 @@ describe('jdl - DeploymentConverter', () => {
"titi",
},
"clusteredDbApps": Set {},
"deploymentType": "openshift",
"deploymentType": "docker-compose",
"directoryPath": "../",
"dockerPushCommand": "docker push",
"dockerRepositoryName": "test",
"gatewayType": undefined,
"gatewayType": "SpringCloudGateway",
"ingressDomain": undefined,
"ingressType": undefined,
"istio": undefined,
"kubernetesServiceType": undefined,
"monitoring": "no",
"openshiftNamespace": "default",
"registryReplicas": 2,
"serviceDiscoveryType": "consul",
"storageType": "ephemeral",
"storageType": undefined,
},
]
`);
Expand Down
16 changes: 5 additions & 11 deletions jdl/converters/parsed-jdl-to-jdl-object/option-converter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,9 @@
*/

import { before, describe, expect, it } from 'esmocha';
import { binaryOptions, entityOptions, searchEngineTypes, unaryOptions } from '../../built-in-options/index.js';
import { binaryOptions, unaryOptions } from '../../built-in-options/index.js';
import { convertOptions } from './option-converter.js';

const { MapperTypes, PaginationTypes } = entityOptions;
const { COUCHBASE } = searchEngineTypes;

const { MAPSTRUCT } = MapperTypes;
const { PAGINATION } = PaginationTypes;

describe('jdl - OptionConverter', () => {
describe('convertOptions', () => {
describe('when not passing options', () => {
Expand Down Expand Up @@ -91,12 +85,12 @@ describe('jdl - OptionConverter', () => {
before(() => {
convertedOptions = convertOptions({}, [
{
optionValues: [MAPSTRUCT, COUCHBASE],
optionValues: ['mapstruct', 'elasticsearch'],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More consistency is more valuable than decoupling. Jdl should be split into generator so each part create the dsl. Jdl should not be decoupled from generator but instead integrated into each of them

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Imho, this pr comes with regressions : using constants helps folding to provide complete feature enhancement. This pr breaks that useful feature.
I do not see any added value decoupling jdl and generator as the main end user usage is the jdl triggering generator : jdl should be modularized and fragmented into generators instead of being decoupled and only covering partial coverage

list: ['*'],
excluded: ['B'],
},
{
optionValues: [PAGINATION],
optionValues: ['pagination'],
list: ['A', 'C'],
excluded: [],
},
Expand All @@ -123,7 +117,7 @@ describe('jdl - OptionConverter', () => {
"B",
},
"name": "search",
"value": "couchbase",
"value": "elasticsearch",
},
JDLBinaryOption {
"entityNames": Set {
Expand All @@ -144,7 +138,7 @@ describe('jdl - OptionConverter', () => {
before(() => {
convertedOptions = convertOptions({}, [
{
optionValues: [MAPSTRUCT],
optionValues: ['mapstruct'],
list: ['*'],
excluded: ['B'],
},
Expand Down
5 changes: 2 additions & 3 deletions jdl/exporters/jdl-exporter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,9 @@ import { JDLEntity } from '../models/index.js';
import exportToJDL from '../exporters/jdl-exporter.js';
import JDLApplication from '../models/jdl-application.js';
import { JDLJSONApplicationConfiguration } from '../parsing/jdl-parsing-types.js';
import { applicationOptions, clientFrameworkTypes } from '../built-in-options/index.js';
import { applicationOptions } from '../built-in-options/index.js';
import { basicHelpers as helpers } from '../../testing/index.js';

const NO_CLIENT_FRAMEWORK = clientFrameworkTypes.NO;
const {
OptionNames: { CLIENT_FRAMEWORK },
} = applicationOptions;
Expand Down Expand Up @@ -104,7 +103,7 @@ describe('jdl - JDLExporter', () => {
beforeEach(() => {
jdlObject = new JDLObject();
const jdlApplication: JDLJSONApplicationConfiguration = {
config: { [CLIENT_FRAMEWORK]: NO_CLIENT_FRAMEWORK },
config: { [CLIENT_FRAMEWORK]: 'no' },
};
jdlObject.addApplication(new JDLApplication(jdlApplication));
});
Expand Down
2 changes: 1 addition & 1 deletion jdl/jdl-importer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ relationship OneToOne {
});
describe('when parsing deployment config', () => {
const contents: any[] = [];
const DEPLOYMENT_NAMES = ['docker-compose', 'kubernetes', 'openshift'];
const DEPLOYMENT_NAMES = ['docker-compose', 'kubernetes'];

before(() => {
const importer = createImporterFromFiles([path.join(__dirname, '__test-files__', 'deployments.jdl')]);
Expand Down
2 changes: 1 addition & 1 deletion jdl/jhipster/application-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import {
JDLApplicationOptionType,
JDLApplicationOptionTypeValue,
JDLApplicationOptionValue,
} from '../models/jdl-application-definition.js';
} from '../built-in-options/jdl-application-definition.js';
import applicationTypes from './application-types.js';
import authenticationTypes from './authentication-types.js';
import databaseTypes from './database-types.js';
Expand Down
16 changes: 0 additions & 16 deletions jdl/jhipster/deployment-options.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,6 @@ describe('jdl - DeploymentOptions', () => {
});
});
});
describe('when passing openshift as arg', () => {
it('should return openshift deployment config', () => {
expect(Options.defaults('openshift')).to.eql({
appsFolders: [],
clusteredDbApps: [],
directoryPath: '../',
dockerPushCommand: 'docker push',
dockerRepositoryName: '',
monitoring: 'no',
serviceDiscoveryType: 'consul',
openshiftNamespace: 'default',
storageType: 'ephemeral',
registryReplicas: 2,
});
});
});
});
});
});
19 changes: 0 additions & 19 deletions jdl/jhipster/deployment-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@
* limitations under the License.
*/
import kubernetesPlatformTypes from './kubernetes-platform-types.js';
import openshiftPlatformTypes from './openshift-platform-types.js';
import monitoringTypes from './monitoring-types.js';
import serviceDiscoveryTypes from './service-discovery-types.js';

const { LOAD_BALANCER, NODE_PORT, INGRESS } = kubernetesPlatformTypes.ServiceTypes;
const { NGINX, GKE } = kubernetesPlatformTypes.IngressTypes;

const { EPHEMERAL, PERSISTENT } = openshiftPlatformTypes.StorageTypes;

const { EUREKA, CONSUL } = serviceDiscoveryTypes;
const NO_SERVICE_DISCOVERY = serviceDiscoveryTypes.NO;

Expand All @@ -35,13 +32,11 @@ const { PROMETHEUS } = monitoringTypes;
export const DeploymentTypes = {
DOCKERCOMPOSE: 'docker-compose',
KUBERNETES: 'kubernetes',
OPENSHIFT: 'openshift',
exists: (deploymentType?: any) => !!deploymentType && !!DeploymentTypes[deploymentType.toUpperCase().replace('-', '')],
};

export const DOCKERCOMPOSE = DeploymentTypes.DOCKERCOMPOSE;
export const KUBERNETES = DeploymentTypes.KUBERNETES;
export const OPENSHIFT = DeploymentTypes.OPENSHIFT;

const kubernetesRelatedOptions = {
kubernetesNamespace: 'default',
Expand All @@ -66,17 +61,6 @@ const kubernetesRelatedOptions = {
},
};

const openshiftRelatedOptions = {
openshiftNamespace: 'default',
registryReplicas: {
two: 2,
},
storageType: {
ephemeral: EPHEMERAL,
persistent: PERSISTENT,
},
};

const dockerComposeRelatedOptions = {
gatewayType: {
springCloudGateway: 'SpringCloudGateway',
Expand All @@ -103,13 +87,11 @@ const Options: any = {
deploymentType: {
dockerCompose: DeploymentTypes.DOCKERCOMPOSE,
kubernetes: DeploymentTypes.KUBERNETES,
openshift: DeploymentTypes.OPENSHIFT,
},
dockerPushCommand: 'docker push',
dockerRepositoryName: '',
...dockerComposeRelatedOptions,
...kubernetesRelatedOptions,
...openshiftRelatedOptions,
};

Options.defaults = (deploymentType = Options.deploymentType.dockerCompose) => {
Expand Down Expand Up @@ -150,7 +132,6 @@ Options.defaults = (deploymentType = Options.deploymentType.dockerCompose) => {
monitoring: Options.monitoring.no,
dockerRepositoryName: Options.dockerRepositoryName,
dockerPushCommand: Options.dockerPushCommand,
openshiftNamespace: Options.openshiftNamespace,
storageType: Options.storageType.ephemeral,
registryReplicas: Options.registryReplicas.two,
};
Expand Down
1 change: 0 additions & 1 deletion jdl/jhipster/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export { default as kubernetesPlatformTypes } from './kubernetes-platform-types.
export { default as messageBrokerTypes } from './message-broker-types.js';
export { default as monitoringTypes } from './monitoring-types.js';
export { default as openapiOptions } from './openapi-options.js';
export { default as openshiftPlatformTypes } from './openshift-platform-types.js';
export { default as reservedKeywords } from './reserved-keywords.js';
export { default as searchEngineTypes } from './search-engine-types.js';
export { default as serviceDiscoveryTypes } from './service-discovery-types.js';
Expand Down
2 changes: 1 addition & 1 deletion jdl/models/jdl-application-configuration-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*/

import logger from '../utils/objects/logger.js';
import JDLApplicationDefinition, { JDLApplicationOptionTypeValue } from '../built-in-options/jdl-application-definition.js';
import JDLApplicationConfiguration from './jdl-application-configuration.js';
import StringJDLApplicationConfigurationOption from './string-jdl-application-configuration-option.js';
import IntegerJDLApplicationConfigurationOption from './integer-jdl-application-configuration-option.js';
import BooleanJDLApplicationConfigurationOption from './boolean-jdl-application-configuration-option.js';
import ListJDLApplicationConfigurationOption from './list-jdl-application-configuration-option.js';
import JDLApplicationDefinition, { JDLApplicationOptionTypeValue } from './jdl-application-definition.js';
import JDLApplicationConfigurationOption from './jdl-application-configuration-option.js';

const applicationDefinition = new JDLApplicationDefinition();
Expand Down
5 changes: 2 additions & 3 deletions jdl/models/jdl-deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
* limitations under the License.
*/
import { isEqual } from 'lodash-es';
import { applicationOptions, deploymentOptions, serviceDiscoveryTypes } from '../built-in-options/index.js';
import { applicationOptions, deploymentOptions } from '../built-in-options/index.js';
import { merge } from '../utils/object-utils.js';
import { join } from '../utils/set-utils.js';
import { ParsedJDLDeployment } from '../converters/parsed-jdl-to-jdl-object/types.js';

const { Options } = deploymentOptions;
const arrayTypes = ['appsFolders', 'clusteredDbApps'];
const NO_SERVICE_DISCOVERY = serviceDiscoveryTypes.NO;

export default class JDLDeployment {
deploymentType!: string;
Expand All @@ -48,7 +47,7 @@ export default class JDLDeployment {
if (Array.isArray(option) && arrayTypes.includes(key)) {
this[key] = new Set(option);
} else if (key === applicationOptions.OptionNames.SERVICE_DISCOVERY_TYPE && option === Options.serviceDiscoveryType.no) {
this[key] = NO_SERVICE_DISCOVERY;
this[key] = 'no';
} else {
this[key] = option;
}
Expand Down
Loading
Loading