gen-jhipster
Version:
VHipster - Spring Boot + Angular/React/Vue in one handy generator
43 lines (42 loc) • 1.58 kB
JavaScript
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { upperFirst } from 'lodash-es';
import { GENERATOR_JHIPSTER } from "../constants/jhipster.js";
import { YO_RC_FILE } from "../constants/yeoman.js";
export const YO_RC_CONFIG_KEY = GENERATOR_JHIPSTER;
export const mergeYoRcContent = (oldConfig, newConfig) => {
const merged = { [YO_RC_CONFIG_KEY]: {} };
for (const ns of new Set([...Object.keys(oldConfig), ...Object.keys(newConfig)])) {
merged[ns] = { ...oldConfig[ns], ...newConfig[ns] };
}
if (oldConfig[YO_RC_CONFIG_KEY]?.creationTimestamp) {
merged[YO_RC_CONFIG_KEY].creationTimestamp = oldConfig[YO_RC_CONFIG_KEY].creationTimestamp;
}
return merged;
};
export const readEntityFile = (applicationPath, entity) => {
const entityFile = join(applicationPath, '.jhipster', `${upperFirst(entity)}.json`);
try {
return JSON.parse(readFileSync(entityFile, 'utf-8'));
}
catch (error) {
throw new Error(`Error reading ${entityFile} file: ${error.message}`, { cause: error });
}
};
export const readYoRcFile = (yoRcPath = '.') => {
const yoRcFile = yoRcPath.endsWith(YO_RC_FILE) ? yoRcPath : join(yoRcPath, YO_RC_FILE);
try {
return JSON.parse(readFileSync(yoRcFile, 'utf-8'));
}
catch (error) {
throw new Error(`Error reading ${yoRcFile} file: ${error.message}`, { cause: error });
}
};
export const readCurrentPathYoRcFile = () => {
try {
return readYoRcFile(process.cwd());
}
catch {
return undefined;
}
};