Update .gitignore and add new dependencies and routes
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -3,23 +3,46 @@ const chokidar = require('chokidar');
|
||||
const fs = require('fs');
|
||||
const { logger, ErrorLogger, logRequestInfo } = require('../config/logs');
|
||||
|
||||
let userData = require(path.resolve(__dirname, '../user.json'));
|
||||
let setupData = require(path.resolve(__dirname, '../setup.json'));
|
||||
const userFilePath = path.resolve(__dirname, '../data/user.json');
|
||||
const setupFilePath = path.resolve(__dirname, '../data/setup.json');
|
||||
|
||||
const watcher = chokidar.watch([path.resolve(__dirname, '../user.json'), path.resolve(__dirname, '../setup.json')], {
|
||||
let userData, setupData;
|
||||
|
||||
try {
|
||||
userData = JSON.parse(fs.readFileSync(userFilePath, 'utf-8'));
|
||||
} catch (error) {
|
||||
ErrorLogger.error(`Error parsing user.json: ${error}`);
|
||||
}
|
||||
|
||||
try {
|
||||
setupData = JSON.parse(fs.readFileSync(setupFilePath, 'utf-8'));
|
||||
} catch (error) {
|
||||
ErrorLogger.error(`Error parsing setup.json: ${error}`);
|
||||
}
|
||||
|
||||
const watcher = chokidar.watch([userFilePath, setupFilePath], {
|
||||
persistent: true
|
||||
});
|
||||
|
||||
watcher.on('change', (filePath) => {
|
||||
delete require.cache[require.resolve(filePath)];
|
||||
|
||||
if (filePath === path.resolve(__dirname, '../user.json')) {
|
||||
userData = require(filePath);
|
||||
} else if (filePath === path.resolve(__dirname, '../setup.json')) {
|
||||
setupData = require(filePath);
|
||||
let modifiedFile;
|
||||
if (filePath === userFilePath) {
|
||||
try {
|
||||
userData = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
||||
modifiedFile = 'user.json';
|
||||
} catch (error) {
|
||||
logger.error(`Error parsing user.json: ${error}`);
|
||||
}
|
||||
} else if (filePath === setupFilePath) {
|
||||
try {
|
||||
setupData = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
||||
modifiedFile = 'setup.json';
|
||||
} catch (error) {
|
||||
logger.error(`Error parsing setup.json: ${error}`);
|
||||
}
|
||||
}
|
||||
|
||||
logger.info('File', filePath, 'has been changed');
|
||||
logger.info(`File ${modifiedFile} has been modified`);
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
|
||||
Reference in New Issue
Block a user