noWatch -> hotReload
This commit is contained in:
parent
cfaff61abf
commit
e674079f53
@ -50,17 +50,17 @@ module.exports = class ArchiveUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// singleton access
|
// singleton access
|
||||||
static getInstance(noWatch = false) {
|
static getInstance(hotReload = true) {
|
||||||
if(!archiveUtil) {
|
if(!archiveUtil) {
|
||||||
archiveUtil = new ArchiveUtil();
|
archiveUtil = new ArchiveUtil();
|
||||||
archiveUtil.init(noWatch);
|
archiveUtil.init(hotReload);
|
||||||
}
|
}
|
||||||
return archiveUtil;
|
return archiveUtil;
|
||||||
}
|
}
|
||||||
|
|
||||||
init(noWatch = false) {
|
init(hotReload = true) {
|
||||||
this.reloadConfig();
|
this.reloadConfig();
|
||||||
if(!noWatch) {
|
if(hotReload) {
|
||||||
Events.on(Events.getSystemEvents().ConfigChanged, () => {
|
Events.on(Events.getSystemEvents().ConfigChanged, () => {
|
||||||
this.reloadConfig();
|
this.reloadConfig();
|
||||||
});
|
});
|
||||||
|
@ -6,6 +6,7 @@ const paths = require('path');
|
|||||||
const fs = require('graceful-fs');
|
const fs = require('graceful-fs');
|
||||||
const hjson = require('hjson');
|
const hjson = require('hjson');
|
||||||
const sane = require('sane');
|
const sane = require('sane');
|
||||||
|
const _ = require('lodash');
|
||||||
|
|
||||||
module.exports = new class ConfigCache
|
module.exports = new class ConfigCache
|
||||||
{
|
{
|
||||||
@ -14,12 +15,13 @@ module.exports = new class ConfigCache
|
|||||||
}
|
}
|
||||||
|
|
||||||
getConfigWithOptions(options, cb) {
|
getConfigWithOptions(options, cb) {
|
||||||
|
options.hotReload = _.get(options, 'hotReload', true);
|
||||||
const cached = this.cache.has(options.filePath);
|
const cached = this.cache.has(options.filePath);
|
||||||
|
|
||||||
if(options.forceReCache || !cached) {
|
if(options.forceReCache || !cached) {
|
||||||
this.recacheConfigFromFile(options.filePath, (err, config) => {
|
this.recacheConfigFromFile(options.filePath, (err, config) => {
|
||||||
if(!err && !cached) {
|
if(!err && !cached) {
|
||||||
if(!options.noWatch) {
|
if(options.hotReload) {
|
||||||
const watcher = sane(
|
const watcher = sane(
|
||||||
paths.dirname(options.filePath),
|
paths.dirname(options.filePath),
|
||||||
{
|
{
|
||||||
|
@ -71,7 +71,7 @@ function getConfigPath() {
|
|||||||
function initConfig(cb) {
|
function initConfig(cb) {
|
||||||
const configPath = getConfigPath();
|
const configPath = getConfigPath();
|
||||||
|
|
||||||
config.init(configPath, { keepWsc : true, noWatch : true }, cb);
|
config.init(configPath, { keepWsc : true, hotReload : false }, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
function initConfigAndDatabases(cb) {
|
function initConfigAndDatabases(cb) {
|
||||||
@ -85,7 +85,7 @@ function initConfigAndDatabases(cb) {
|
|||||||
},
|
},
|
||||||
function initArchiveUtil(callback) {
|
function initArchiveUtil(callback) {
|
||||||
// ensure we init ArchiveUtil without events
|
// ensure we init ArchiveUtil without events
|
||||||
require('../../core/archive_util').getInstance(true); // true=noWatch
|
require('../../core/archive_util').getInstance(false); // false=hotReload
|
||||||
return callback(null);
|
return callback(null);
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user