const path = require('path') const chokidar = require('chokidar') // Watch the srd/sys directory and reload config on changes. module.exports = async (plugin, app) => { const sys_path = path.resolve(path.join(app.config.srd, 'sys')) const dpath = path.join(sys_path, 'dictionary.js') const cpath = path.join(sys_path, 'conf.js') const mpath = path.join(sys_path, 'menu.js') const refresh = () => { delete require.cache[dpath] delete require.cache[cpath] delete require.cache[mpath] app.live = { ...app.live, dictionary: require(dpath), conf: require(cpath), menu: require(mpath), } } refresh() const watcher = chokidar.watch(sys_path, {persistent: true}) watcher.on('change', p => { refresh() }) plugin.log('watching', sys_path) }