flame/utils/init/initConfig.js

26 lines
785 B
JavaScript
Raw Normal View History

2021-10-21 18:14:25 +03:00
const { copyFile, readFile, writeFile } = require('fs/promises');
const checkFileExists = require('../checkFileExists');
const initialConfig = require('./initialConfig.json');
const initConfig = async () => {
2021-10-21 18:14:25 +03:00
const configExists = await checkFileExists('data/config.json');
if (!configExists) {
await copyFile('utils/init/initialConfig.json', 'data/config.json');
}
2021-10-21 18:14:25 +03:00
const existingConfig = await readFile('data/config.json', 'utf-8');
const parsedConfig = JSON.parse(existingConfig);
2021-10-21 18:14:25 +03:00
// Add new config pairs if necessary
for (let key in initialConfig) {
if (!Object.keys(parsedConfig).includes(key)) {
parsedConfig[key] = initialConfig[key];
}
2021-10-06 15:17:31 +03:00
}
2021-10-21 18:14:25 +03:00
await writeFile('data/config.json', JSON.stringify(parsedConfig));
2021-09-06 13:24:01 +03:00
};
2021-09-06 13:24:01 +03:00
module.exports = initConfig;