Skip to content

Commit

Permalink
add jdl support to blueprints (#27291)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima authored Sep 17, 2024
1 parent d481e2b commit acb4cb7
Show file tree
Hide file tree
Showing 62 changed files with 659 additions and 623 deletions.
33 changes: 33 additions & 0 deletions cli/cli-jdl.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { join } from 'path';
import { execa } from 'execa';
import { basicHelpers as helpers, runResult } from '../lib/testing/index.js';
import { getPackageRoot } from '../lib/index.js';

const jhipsterCli = join(getPackageRoot(), 'bin/jhipster.cjs');

describe('allows customizing JDL definitions', () => {
it('accepts a custom JDL definition', async () => {
await helpers
.prepareTemporaryDir()
.withFiles({
'.blueprint/app/index.mjs': `export const command = {
configs: {
fooConfig: {
jdl: {
type: 'boolean',
tokenType: 'BOOLEAN',
},
scope: 'storage',
},
},
};`,
})
.commitFiles();
await execa(jhipsterCli, ['jdl', '--json-only', '--inline', 'application { config { fooConfig false } }'], { stdio: 'pipe' });
runResult.assertJsonFileContent('.yo-rc.json', {
'generator-jhipster': {
fooConfig: false,
},
});
});
});
4 changes: 4 additions & 0 deletions cli/jhipster-command.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ import { kebabCase } from 'lodash-es';
import { convertConfigToOption } from '../lib/command/index.js';

export default class JHipsterCommand extends Command {
configs = {};
blueprintConfigs = {};

createCommand(name) {
return new JHipsterCommand(name);
}
Expand Down Expand Up @@ -177,6 +180,7 @@ export default class JHipsterCommand extends Command {
}

addJHipsterConfigs(configs = {}, blueprintOptionDescription) {
Object.assign(blueprintOptionDescription ? this.blueprintConfigs : this.configs, configs);
Object.entries(configs).forEach(([name, config]) => {
const option = convertConfigToOption(name, config);
if (option) {
Expand Down
7 changes: 7 additions & 0 deletions cli/program.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { packageNameToNamespace } from '../generators/base/support/index.js';
import command from '../generators/base/command.js';
import { GENERATOR_APP, GENERATOR_BOOTSTRAP, GENERATOR_JDL } from '../generators/generator-list.js';
import { extractArgumentsFromConfigs } from '../lib/command/index.js';
import { buildJDLApplicationConfig } from '../lib/command/jdl.js';
import logo from './logo.mjs';
import EnvironmentBuilder from './environment-builder.mjs';
import SUB_GENERATORS from './commands.mjs';
Expand Down Expand Up @@ -56,6 +57,8 @@ const buildAllDependencies = async (generatorNames, { env, blueprintNamespaces }
const meta = await env.getGeneratorMeta(namespace.includes(':') ? namespace : `${JHIPSTER_NS}:${namespace}`);
if (meta) {
allDependencies[namespace] = { meta, blueprintNamespace };
} else if (!blueprintNamespace) {
logger.warn(`Generator ${namespace} not found.`);
}
return meta?.importModule();
};
Expand Down Expand Up @@ -276,6 +279,8 @@ export const buildCommands = async ({
const command = everything.pop();
const cmdOptions = everything.pop();
const args = everything;
const commandsConfigs = Object.freeze({ ...command.configs, ...command.blueprintConfigs });
const jdlDefinition = buildJDLApplicationConfig(commandsConfigs);
const options = {
...program.opts(),
...cmdOptions,
Expand All @@ -284,6 +289,8 @@ export const buildCommands = async ({
entrypointGenerator,
blueprints: envBuilder.getBlueprintsOption(),
positionalArguments: args,
jdlDefinition,
commandsConfigs,
};
if (options.installPath) {
// eslint-disable-next-line no-console
Expand Down
Loading

0 comments on commit acb4cb7

Please sign in to comment.