Skip to content

Commit

Permalink
adjust docker-prompts lookups (#23866)
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima authored Oct 17, 2023
1 parent 9119e8e commit e031780
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions generators/base-workspaces/internal/docker-prompts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*/
import chalk from 'chalk';

import { readdirSync, statSync } from 'node:fs';
import { readFileSync, readdirSync, statSync } from 'node:fs';
import { join } from 'node:path';
import { loadConfigs } from './docker-base.mjs';
import { applicationTypes, monitoringTypes, serviceDiscoveryTypes } from '../../../jdl/jhipster/index.mjs';
import { convertSecretToBase64 } from '../../base/support/index.mjs';
Expand Down Expand Up @@ -122,7 +123,7 @@ async function askForPath() {
const path = this.destinationPath(input);
try {
if (statSync(path).isDirectory) {
const appsFolders = getAppFolders.call(this, input, deploymentApplicationType);
const appsFolders = getAppFolders.call(this, path, deploymentApplicationType);

if (appsFolders.length === 0) {
return deploymentApplicationType === MONOLITH
Expand All @@ -147,7 +148,7 @@ async function askForPath() {
this.directoryPath += '/';
}

this.appsFolders = getAppFolders.call(this, this.directoryPath, deploymentApplicationType);
this.appsFolders = getAppFolders.call(this, this.destinationPath(this.directoryPath), deploymentApplicationType);

// Removing registry from appsFolders, using reverse for loop
for (let i = this.appsFolders.length - 1; i >= 0; i--) {
Expand Down Expand Up @@ -370,27 +371,27 @@ async function askForDockerPushCommand() {
* @param deploymentApplicationType type of application being composed
* @returns {Array} array of string representing app folders
*/
export function getAppFolders(input, deploymentApplicationType) {
const destinationPath = this.destinationPath(input);
const files = readdirSync(destinationPath);
export function getAppFolders(directory, deploymentApplicationType) {
const files = readdirSync(directory);
const appsFolders = [];

files.forEach(file => {
try {
if (statSync(this.destinationPath(file)).isDirectory()) {
if (statSync(this.destinationPath(file, '.yo-rc.json')).isFile()) {
if (statSync(join(directory, file)).isDirectory()) {
const yoRcFile = join(directory, file, '.yo-rc.json');
if (statSync(yoRcFile).isFile()) {
try {
const fileData = this.readDestinationJSON(`${file.name}/.yo-rc.json`);
const fileData = JSON.parse(readFileSync(yoRcFile).toString());
if (
fileData['generator-jhipster'].baseName !== undefined &&
(deploymentApplicationType === undefined ||
deploymentApplicationType === fileData['generator-jhipster'].applicationType ||
deploymentApplicationType === (fileData['generator-jhipster'].applicationType ?? MONOLITH) ||
(deploymentApplicationType === MICROSERVICE && fileData['generator-jhipster'].applicationType === GATEWAY))
) {
appsFolders.push(file.name.match(/([^/]*)\/*$/)[1]);
appsFolders.push(file.match(/([^/]*)\/*$/)[1]);
}
} catch (err) {
this.log.error(chalk.red(`${file}: this .yo-rc.json can't be read`));
this.log.error(chalk.red(`${yoRcFile}: this .yo-rc.json can't be read`));
this.log.debug('Error:', err);
}
}
Expand Down

0 comments on commit e031780

Please sign in to comment.