Skip to content

Commit

Permalink
Merge pull request #27059 from mshima/info
Browse files Browse the repository at this point in the history
look for applications in `jhipster info`
  • Loading branch information
DanielFran committed Aug 24, 2024
2 parents 32dcd4c + 025ca65 commit 58c22bd
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
9 changes: 7 additions & 2 deletions generators/info/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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));
Expand Down
33 changes: 33 additions & 0 deletions generators/workspaces/support/applications-lookup.ts
Original file line number Diff line number Diff line change
@@ -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<boolean> => {
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<string[]> => {
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));
};
19 changes: 19 additions & 0 deletions generators/workspaces/support/index.ts
Original file line number Diff line number Diff line change
@@ -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';

0 comments on commit 58c22bd

Please sign in to comment.