diff --git a/generators/info/generator.ts b/generators/info/generator.ts index b5edb862cca2..c65685b78ee5 100644 --- a/generators/info/generator.ts +++ b/generators/info/generator.ts @@ -27,6 +27,7 @@ import JSONToJDLOptionConverter from '../../jdl/converters/json-to-jdl-option-co import type { JHipsterGeneratorFeatures, JHipsterGeneratorOptions } from '../base/api.js'; import { YO_RC_FILE } from '../generator-constants.js'; import { JSONEntity } from '../../jdl/converters/types.js'; +import { applicationsLookup } from '../workspaces/support/applications-lookup.js'; import { replaceSensitiveConfig } from './support/utils.js'; const isInfoCommand = commandName => commandName === 'info' || undefined; @@ -53,7 +54,7 @@ export default class InfoGenerator extends BaseApplicationGenerator { console.log(`\n\`\`\`\n${stdout}\`\`\`\n`); }, - displayConfiguration() { + async displayConfiguration() { // Omit sensitive information. const yoRc = this.readDestinationJSON(YO_RC_FILE); if (yoRc) { @@ -64,7 +65,11 @@ export default class InfoGenerator extends BaseApplicationGenerator { console.log('\n##### **JHipster configuration not found**\n'); } - const packages = this.jhipsterConfig.appsFolders ?? this.jhipsterConfig.packages ?? []; + let packages = this.jhipsterConfig.appsFolders ?? this.jhipsterConfig.packages ?? []; + if (!yoRc && packages.length === 0) { + packages = await applicationsLookup(this.destinationRoot()); + } + if (packages.length > 0) { for (const pkg of packages) { const yoRc = this.readDestinationJSON(this.destinationPath(pkg, YO_RC_FILE)); diff --git a/generators/workspaces/support/applications-lookup.ts b/generators/workspaces/support/applications-lookup.ts new file mode 100644 index 000000000000..08b8fbcb1e56 --- /dev/null +++ b/generators/workspaces/support/applications-lookup.ts @@ -0,0 +1,33 @@ +/** + * Copyright 2013-2024 the original author or authors from the JHipster project. + * + * This file is part of the JHipster project, see https://www.jhipster.tech/ + * for more information. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { readFile } from 'node:fs/promises'; +import { dirname } from 'node:path'; +import { globby } from 'globby'; + +const isApplication = async (cwd: string): Promise => { + const content = await readFile(cwd, { encoding: 'utf-8' }); + const jsonContent = JSON.parse(content); + return Boolean(jsonContent?.['generator-jhipster']?.baseName); +}; + +export const applicationsLookup = async (cwd: string): Promise => { + const yoRcFiles = await globby('**/.yo-rc.json', { cwd }); + const result = await Promise.all(yoRcFiles.map(async file => ({ file, isApp: await isApplication(file) }))); + return result.filter(({ isApp }) => isApp).map(({ file }) => dirname(file)); +}; diff --git a/generators/workspaces/support/index.ts b/generators/workspaces/support/index.ts new file mode 100644 index 000000000000..a545be161e76 --- /dev/null +++ b/generators/workspaces/support/index.ts @@ -0,0 +1,19 @@ +/** + * Copyright 2013-2024 the original author or authors from the JHipster project. + * + * This file is part of the JHipster project, see https://www.jhipster.tech/ + * for more information. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +export * from './applications-lookup.js';