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

allow custom entrypoint generator #25390

Merged
merged 3 commits into from
Mar 7, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 22 additions & 4 deletions cli/program.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { CLI_NAME, logger, getCommand, done } from './utils.mjs';
import { packageJson } from '../lib/index.js';
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';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
Expand Down Expand Up @@ -160,7 +161,7 @@ export const createProgram = ({ executableName = CLI_NAME, executableVersion } =
const rejectExtraArgs = ({ program, command, extraArgs }) => {
// if extraArgs exists: Unknown commands or unknown argument.
const first = extraArgs[0];
if (command.name() !== 'app') {
if (command.name() !== GENERATOR_APP) {
logger.fatal(
`${chalk.yellow(command.name())} command doesn't take ${chalk.yellow(first)} argument. See '${chalk.white(
`${program.name()} ${command.name()} --help`,
Expand All @@ -184,7 +185,8 @@ export const buildCommands = async ({
envBuilder,
env,
loadCommand,
defaultCommand = 'app',
defaultCommand = GENERATOR_APP,
entrypointGenerator,
printLogo = printJHipsterLogo,
printBlueprintLogo = () => {},
createEnvBuilder,
Expand Down Expand Up @@ -242,7 +244,10 @@ export const buildCommands = async ({
await addCommandRootGeneratorOptions(command, generatorMeta);

// Add bootstrap options, may be dropped if every generator is migrated to new structure and correctly depends on bootstrap.
const boostrapGen = ['bootstrap', generator];
const boostrapGen = [GENERATOR_BOOTSTRAP, generator];
if (cmdName === GENERATOR_JDL) {
boostrapGen.push(entrypointGenerator ?? GENERATOR_APP);
}
const allDependencies = await buildAllDependencies(boostrapGen, {
env,
blueprintNamespaces: envBuilder.getBlueprintsNamespaces(),
Expand Down Expand Up @@ -272,6 +277,7 @@ export const buildCommands = async ({
...cmdOptions,
...useOptions,
commandName: cmdName,
entrypointGenerator,
blueprints: envBuilder.getBlueprintsOption(),
positionalArguments: args,
};
Expand Down Expand Up @@ -328,6 +334,7 @@ export const buildJHipster = async ({
return command;
},
defaultCommand,
entrypointGenerator,
} = {}) => {
// eslint-disable-next-line chai-friendly/no-unused-expressions
createEnvBuilder =
Expand All @@ -336,7 +343,18 @@ export const buildJHipster = async ({
env = env ?? envBuilder.getEnvironment();
commands = commands ?? { ...SUB_GENERATORS, ...(await envBuilder.getBlueprintCommands()) };

await buildCommands({ program, commands, envBuilder, env, loadCommand, defaultCommand, printLogo, printBlueprintLogo, createEnvBuilder });
await buildCommands({
program,
commands,
envBuilder,
env,
loadCommand,
defaultCommand,
entrypointGenerator,
printLogo,
printBlueprintLogo,
createEnvBuilder,
});

return program;
};
Expand Down
8 changes: 4 additions & 4 deletions generators/jdl/__snapshots__/generator.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ Options:
--skip-install Do not automatically install dependencies (default: false)
--force-install Fail on install dependencies error (default: false)
--ask-answered Show prompts for already configured options (default: false)
--workspaces-folders <value...> Folders to use as monorepository workspace
--workspaces Generate workspaces for multiples applications
--skip-git Skip git repository initialization
--monorepository Use monorepository
--defaults Execute jhipster with default config
--skip-client Skip the client-side application generation
--skip-server Skip the server-side application generation
Expand Down Expand Up @@ -217,16 +221,12 @@ Options:
--microfrontends <value> Microfrontends to load
--with-admin-ui Generate administrative user interface
--client-root-dir <value> Client root
--skip-git Skip git repository initialization
--monorepository Use monorepository
--cypress-coverage Enable Cypress code coverage report generation
--cypress-audit Enable cypress-audit/lighthouse report generation
--enable-translation Enable translation
-l, --language <value...> Language to be added to application (existing languages are not removed)
-n, --native-language [value] Set application native language
--regenerate-languages Regenerate languages
--workspaces-folders <value...> Folders to use as monorepository workspace
--workspaces Generate workspaces for multiples applications
-h, --help display help for command
"
`;
Expand Down
10 changes: 8 additions & 2 deletions generators/jdl/command.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { JHipsterCommandDefinition } from '../base/api.js';
import { GENERATOR_APP, GENERATOR_WORKSPACES } from '../generator-list.js';
import { GENERATOR_WORKSPACES } from '../generator-list.js';

const command: JHipsterCommandDefinition = {
arguments: {
Expand All @@ -8,6 +8,12 @@ const command: JHipsterCommandDefinition = {
},
},
options: {
entrypointGenerator: {
description: 'Entrypoint generator to be used',
type: String,
scope: 'generator',
hide: true,
},
interactive: {
description:
'Generate multiple applications in series so that questions can be interacted with. This is the default when there is an existing application configuration in any of the folders',
Expand Down Expand Up @@ -45,7 +51,7 @@ const command: JHipsterCommandDefinition = {
scope: 'generator',
},
},
import: [GENERATOR_APP, GENERATOR_WORKSPACES],
import: [GENERATOR_WORKSPACES],
};

export default command;
21 changes: 21 additions & 0 deletions generators/jdl/generator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,4 +488,25 @@ entity Bar
});
});
});
describe('with entrypointGenerator', () => {
const jdl = `
application { config { baseName gatewayApp applicationType gateway } }
`;
describe('generating application', () => {
before(async () => {
await helpers
.runJHipster(GENERATOR_JDL)
.withMockedGenerators([...mockedGenerators, 'foo:bar'])
.withOptions({
inline: jdl,
entrypointGenerator: 'foo:bar',
});
});

it('should generate expected config', () => {
const mock = runResult.mockedGenerators['foo:bar'] as SinonSpy;
expect(mock.callCount).toBe(1);
});
});
});
});
13 changes: 8 additions & 5 deletions generators/jdl/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ export default class JdlGenerator extends BaseGenerator {
jdlFiles?: string[];
inline?: string;
jdlContents: string[] = [];
entrypointGenerator = `${CLI_NAME}:${GENERATOR_APP}`;
entitiesGenerator = GENERATOR_ENTITIES;
workspacesGenerator = GENERATOR_WORKSPACES;

interactive?: boolean;
jsonOnly?: boolean;
Expand Down Expand Up @@ -204,13 +207,13 @@ export default class JdlGenerator extends BaseGenerator {
if (this.ignoreApplication || this.applications.length === 0) {
if (this.applications.length === 0) {
const entities = this.exportedEntities;
await this.composeWithJHipster(GENERATOR_ENTITIES, {
await this.composeWithJHipster(this.entitiesGenerator, {
generatorArgs: entities.map(entity => entity.name),
generatorOptions,
});
} else {
for (const app of this.applications) {
await this.composeWithJHipster(GENERATOR_ENTITIES, {
await this.composeWithJHipster(this.entitiesGenerator, {
generatorArgs: app.entities.map(entity => entity.name),
generatorOptions: {
...generatorOptions,
Expand All @@ -221,10 +224,10 @@ export default class JdlGenerator extends BaseGenerator {
}
} else if (this.applications.length === 1) {
this.log.info('Generating 1 application');
await this.composeWithJHipster(GENERATOR_APP, { generatorOptions });
await this.composeWithJHipster(this.entrypointGenerator, { generatorOptions });
} else {
this.log.info(`Generating ${this.applications.length} applications`);
await this.composeWithJHipster(GENERATOR_WORKSPACES, {
await this.composeWithJHipster(this.workspacesGenerator, {
generatorOptions: {
workspacesFolders: this.applications.map(app => app.folder),
generateApplications: async () => this.runNonInteractive(this.applications, generatorOptions),
Expand Down Expand Up @@ -291,7 +294,7 @@ export default class JdlGenerator extends BaseGenerator {
}
const envBuilder = await this.createEnvBuilder(envOptions);
const env = envBuilder.getEnvironment();
await env.run([`${CLI_NAME}:${GENERATOR_APP}`], generatorOptions);
await env.run([this.entrypointGenerator], generatorOptions);
}),
);
}
Expand Down
6 changes: 6 additions & 0 deletions generators/workspaces/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ const command: JHipsterCommandDefinition = {
default: [],
scope: 'generator',
},
entrypointGenerator: {
description: 'Entrypoint generator to be used',
type: String,
scope: 'generator',
hide: true,
},
workspaces: {
type: Boolean,
description: 'Generate workspaces for multiples applications',
Expand Down
5 changes: 4 additions & 1 deletion generators/workspaces/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export default class WorkspacesGenerator extends BaseWorkspacesGenerator {
workspaces;
generateApplications;
generateWith;
entrypointGenerator;

generateWorkspaces;

Expand Down Expand Up @@ -102,7 +103,9 @@ export default class WorkspacesGenerator extends BaseWorkspacesGenerator {
await this.generateApplications.call(this);
} else {
for (const appName of this.appsFolders) {
await this.composeWithJHipster(this.generateWith, { generatorOptions: { destinationRoot: this.destinationPath(appName) } });
await this.composeWithJHipster(this.entrypointGenerator ?? this.generateWith, {
generatorOptions: { destinationRoot: this.destinationPath(appName) },
});
}
}
},
Expand Down