generator-begcode
Version:
Spring Boot + Angular/React/Vue in one handy generator
24 lines (23 loc) • 919 B
JavaScript
import fs from 'fs';
export const GENERATOR_NAME = 'generator-begcode';
export function writeConfigFile(config, yoRcPath = '.yo-rc.json') {
let newYoRc = { ...config };
const stats = fs.statSync(yoRcPath, { throwIfNoEntry: false });
if (stats && stats.isFile) {
const yoRc = JSON.parse(fs.readFileSync(yoRcPath, { encoding: 'utf-8' }));
let creationTimestamp = config[GENERATOR_NAME].creationTimestamp;
if (yoRc[GENERATOR_NAME] && yoRc[GENERATOR_NAME].creationTimestamp) {
creationTimestamp = yoRc[GENERATOR_NAME].creationTimestamp;
}
newYoRc = {
...yoRc,
...config,
[GENERATOR_NAME]: {
...yoRc[GENERATOR_NAME],
...config[GENERATOR_NAME],
creationTimestamp,
},
};
}
fs.writeFileSync(yoRcPath, JSON.stringify(newYoRc, null, 2).concat('\n'));
}