Skip to content

Commit

Permalink
add initial command integration to jdl
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Sep 2, 2024
1 parent e2f01e7 commit d4d1e14
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 32 deletions.
2 changes: 2 additions & 0 deletions generators/base/api.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { ArgumentSpec, BaseFeatures, BaseOptions, CliOptionSpec } from 'yeoman-generator';
import type { RequireAtLeastOne, SetOptional, Simplify, TaggedUnion, TupleToUnion, ValueOf } from 'type-fest';
import type CoreGenerator from '../base-core/index.js';
import { JHipsterOptionDefinition } from '../../jdl/types/types.js';
import { MergeUnion } from './internal/merge-union.js';

type ConfigScope = 'storage' | 'blueprint' | 'control' | 'generator';
Expand Down Expand Up @@ -233,6 +234,7 @@ export type ConfigSpec = {
readonly prompt?:
| PromptSpec
| ((gen: CoreGenerator & { jhipsterConfigWithDefaults: Record<string, any> }, config: ConfigSpec) => PromptSpec);
readonly jdl?: Omit<JHipsterOptionDefinition, 'name', 'knownChoices'>;

Check failure on line 237 in generators/base/api.d.ts

View workflow job for this annotation

GitHub Actions / check-npm-test

Generic type 'Omit' requires 2 type argument(s).
readonly scope?: 'storage' | 'blueprint' | 'generator';
/**
* The callback receives the generator as input for 'generator' scope.
Expand Down
6 changes: 6 additions & 0 deletions generators/base/internal/command.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { JHipsterOptionDefinition } from '../../../jdl/types/types.js';
import { JHipsterArguments, JHipsterConfigs } from '../api.js';

export const extractArgumentsFromConfigs = (configs: JHipsterConfigs | undefined): JHipsterArguments => {
Expand All @@ -14,3 +15,8 @@ export const extractArgumentsFromConfigs = (configs: JHipsterConfigs | undefined
]),
) as JHipsterArguments;
};

export const extractJdlDefinitionFromCommand = (configs: JHipsterConfigs = {}): JHipsterOptionDefinition[] =>
Object.entries(configs)
.filter(([_name, def]) => def.jdl)
.map(([name, def]) => ({ name, ...def.jdl }));
6 changes: 4 additions & 2 deletions generators/server/jdl/application-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ import { snakeCase, upperCase } from 'lodash-es';
import { JDLApplicationConfig, JHipsterOptionDefinition } from '../../../jdl/types/types.js';
import databaseMigrationOption from '../options/database-migration.js';
import messageBrokerOption from '../options/message-broker.js';
import { feignClientDefinition, syncUserWithIdpDefinition } from '../options/index.js';
import { syncUserWithIdpDefinition } from '../options/index.js';
import { jdlRoutesOptions } from '../../spring-cloud/generators/gateway/jdl/jdl-routes-option.js';
import command from '../../spring-boot/command.js';
import { extractJdlDefinitionFromCommand } from '../../base/internal/command.js';

const jdlOptions: JHipsterOptionDefinition[] = [
databaseMigrationOption,
messageBrokerOption,
feignClientDefinition,
syncUserWithIdpDefinition,
jdlRoutesOptions,
...extractJdlDefinitionFromCommand(command.configs),
];

const applicationConfig: JDLApplicationConfig = {
Expand Down
28 changes: 0 additions & 28 deletions generators/server/options/feign-client.ts

This file was deleted.

1 change: 0 additions & 1 deletion generators/server/options/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,4 @@

export * from './database-migration.js';
export * from './message-broker.js';
export * from './feign-client.js';
export * from './sync-user-with-idp.js';
4 changes: 4 additions & 0 deletions generators/spring-boot/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ const command: JHipsterCommandDefinition = {
[MICROSERVICE].includes(gen.jhipsterConfigWithDefaults.applicationType) &&
(reactive ?? gen.jhipsterConfigWithDefaults.reactive) === false,
}),
jdl: {
type: 'boolean',
tokenType: 'BOOLEAN',
},
default: false,
},
syncUserWithIdp: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { before, describe, expect, it } from 'esmocha';
import { ImportState, createImporterFromContent } from '../../../jdl/jdl-importer.js';
import { FEIGN_CLIENT as optionName } from './index.js';

const optionName = 'feignClient';

describe(`generators - server - jdl - ${optionName}`, () => {
[true, false].forEach(optionValue => {
Expand Down

0 comments on commit d4d1e14

Please sign in to comment.