generator-begcode
Version:
Spring Boot + Angular/React/Vue in one handy generator
32 lines (31 loc) • 1.3 kB
JavaScript
import { lstat, readFile } from 'node:fs/promises';
import { join } from 'node:path';
import { GENERATOR_JHIPSTER } from '../../generators/generator-constants.js';
import { mutateData } from '../utils/object.js';
const isFile = async (filename) => {
try {
return (await lstat(filename)).isFile();
}
catch {
return false;
}
};
export const prepareSample = async (projectFolder, files, { removeBlueprints } = {}) => {
return Promise.all(files.map(async ({ filename, content, type }) => {
filename = join(projectFolder, filename);
if (filename.endsWith('.yo-rc.json')) {
if (await isFile(filename)) {
const { jwtSecretKey, rememberMeKey } = JSON.parse(await readFile(filename, 'utf-8'))[GENERATOR_JHIPSTER];
if (jwtSecretKey || rememberMeKey) {
const newContent = JSON.parse(content);
mutateData(newContent[GENERATOR_JHIPSTER], { jwtSecretKey, rememberMeKey });
if (removeBlueprints) {
delete newContent[GENERATOR_JHIPSTER].blueprints;
}
content = JSON.stringify(newContent, null, 2);
}
}
}
return { filename, content, type };
}));
};