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

internal: always load main generators configs #27466

Merged
merged 1 commit into from
Oct 1, 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
10 changes: 9 additions & 1 deletion generators/bootstrap-application-base/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,17 @@ export default class BootstrapApplicationBase extends BaseApplicationGenerator {
* Avoid having undefined keys in the application object when redering ejs templates
*/
async loadApplicationKeys({ application }) {
if (this.options.commandsConfigs) {
// Load keys passed from cli
loadCommandConfigsKeysIntoTemplatesContext({
templatesContext: application,
commandsConfigs: this.options.commandsConfigs,
});
}
// Load keys from main generators
loadCommandConfigsKeysIntoTemplatesContext({
templatesContext: application,
commandsConfigs: this.options.commandsConfigs ?? (await lookupCommandsConfigs()),
commandsConfigs: await lookupCommandsConfigs(),
});
},
task({ application }) {
Expand Down
21 changes: 9 additions & 12 deletions lib/command/lookup-commands-configs.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
import { dirname, join } from 'path';
import { fileURLToPath } from 'url';
import { fileURLToPath, pathToFileURL } from 'url';
import { glob } from 'glob';
import type { JHipsterConfig, JHipsterConfigs } from './types.js';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const cwd = join(__dirname, '../..');
let jdlConfigs: JHipsterConfigs;
let jhipsterConfigs: JHipsterConfigs;

export const lookupCommandsConfigs = async (options?: { filter: (config: JHipsterConfig) => boolean }): Promise<JHipsterConfigs> => {
if (jdlConfigs) {
return jdlConfigs;
if (jhipsterConfigs) {
return jhipsterConfigs;
}
const { filter = () => true } = options ?? {};
jdlConfigs = {};
jhipsterConfigs = {};
const files = [...(await glob('generators/*/index.{j,t}s', { cwd })), ...(await glob('generators/*/generators/*/index.{j,t}s', { cwd }))];
for (const file of files) {
const index = await import(`${cwd}/${file}`);
const configs: JHipsterConfigs = index.command?.configs ?? {};
for (const [key, value] of Object.entries(configs)) {
if (filter(value)) {
jdlConfigs[key] = value;
}
const index = await import(pathToFileURL(`${cwd}/${file}`).toString());
if (index.command?.configs) {
Object.assign(jhipsterConfigs, index.command?.configs);
}
}
return jdlConfigs;
return Object.fromEntries(Object.entries(jhipsterConfigs).filter(([_key, value]) => filter(value)));
};
Loading