Skip to content

Commit

Permalink
internal: load main config keys into application context
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Sep 27, 2024
1 parent 05bd6be commit cf75796
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 15 deletions.
12 changes: 8 additions & 4 deletions cli/program.mts
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ export const buildCommands = ({
const command = everything.pop();
const cmdOptions = everything.pop();
const args = everything;
const commandsConfigs = Object.freeze({ ...command.configs, ...command.blueprintConfigs });
const jdlDefinition = buildJDLApplicationConfig(commandsConfigs);
const mergedConfigs = Object.freeze({ ...command.configs, ...command.blueprintConfigs });
const jdlDefinition = buildJDLApplicationConfig(mergedConfigs);
const options = {
...program.opts(),
...cmdOptions,
Expand All @@ -346,8 +346,12 @@ export const buildCommands = ({
entrypointGenerator,
blueprints: envBuilder?.getBlueprintsOption(),
positionalArguments: args,
jdlDefinition,
commandsConfigs,
jhipsterDefinition: {
jdlDefinition,
mainConfigs: Object.freeze({ ...command.configs }),
blueprintConfigs: Object.freeze({ ...command.blueprintConfigs }),
mergedConfigs,
},
};
if (options.installPath) {
// eslint-disable-next-line no-console
Expand Down
9 changes: 6 additions & 3 deletions generators/base/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ export type JHipsterGeneratorOptions = BaseOptions &
positionalArguments?: unknown[];
createEnvBuilder?: any;
/** @experimental */
jdlDefinition?: JDLApplicationConfig;
/** @experimental */
commandsConfigs?: JHipsterConfigs;
jhipsterDefinition?: {
jdlDefinition: JDLApplicationConfig;
mainConfigs: JHipsterConfigs;
blueprintConfigs: JHipsterConfigs;
mergedConfigs: JHipsterConfigs;
};

/* yeoman options */
skipYoResolve?: boolean;
Expand Down
22 changes: 17 additions & 5 deletions generators/bootstrap-application-base/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export default class BootstrapApplicationBase extends BaseApplicationGenerator {

const destinationPath = this.destinationPath();
const jdlStorePath = this.destinationPath(this.jhipsterConfig.jdlStore);
const { jdlDefinition } = this.options;
const { jdlDefinition } = this.options.jhipsterDefinition ?? {};

this.features.commitTransformFactory = () => exportJDLTransform({ destinationPath, jdlStorePath, jdlDefinition });
await this.pipeline({ refresh: true, pendingFiles: false }, importJDLTransform({ destinationPath, jdlStorePath, jdlDefinition }));
Expand Down Expand Up @@ -441,10 +441,22 @@ export default class BootstrapApplicationBase extends BaseApplicationGenerator {
* Avoid having undefined keys in the application object when redering ejs templates
*/
async loadApplicationKeys({ application }) {
loadCommandConfigsKeysIntoTemplatesContext({
templatesContext: application,
commandsConfigs: this.options.commandsConfigs ?? (await lookupCommandsConfigs()),
});
if (this.options.jhipsterDefinition) {
const { mainConfigs, blueprintConfigs } = this.options.jhipsterDefinition;
loadCommandConfigsKeysIntoTemplatesContext({
templatesContext: application,
commandsConfigs: blueprintConfigs,
});
loadCommandConfigsKeysIntoTemplatesContext({
templatesContext: application,
commandsConfigs: mainConfigs,
});
} else {
loadCommandConfigsKeysIntoTemplatesContext({
templatesContext: application,
commandsConfigs: await lookupCommandsConfigs(),
});
}
},
task({ application }) {
const packageJsonFiles = [this.destinationPath('package.json')];
Expand Down
2 changes: 1 addition & 1 deletion generators/export-jdl/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class extends BaseGenerator {
return this.asDefaultTaskGroup({
convertToJDL() {
try {
const jdlObject = convertToJDL(this.destinationPath(), false, this.options.jdlDefinition);
const jdlObject = convertToJDL(this.destinationPath(), false, this.options.jhipsterDefinition?.jdlDefinition);
if (jdlObject) {
this.jdlContent = jdlObject.toString();
}
Expand Down
6 changes: 5 additions & 1 deletion generators/jdl/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,11 @@ export default class JdlGenerator extends BaseGenerator {
skipUserManagement: this.options.skipUserManagement,
};

const importer = createImporterFromContent(this.jdlContents.join('\n'), configuration, this.options.jdlDefinition);
const importer = createImporterFromContent(
this.jdlContents.join('\n'),
configuration,
this.options.jhipsterDefinition?.jdlDefinition,
);

const importState = importer.import();

Expand Down
4 changes: 3 additions & 1 deletion lib/testing/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,9 @@ class JHipsterTest extends YeomanTest {
return super
.run<GeneratorType>(GeneratorOrNamespace, settings, envOptions)
.withOptions({
jdlDefinition: getDefaultJDLApplicationConfig(),
jhipsterDefinition: {
jdlDefinition: getDefaultJDLApplicationConfig(),
},
} as any)
.withAdapterOptions({ log: createJHipsterLogger() }) as any;
}
Expand Down

0 comments on commit cf75796

Please sign in to comment.