mirror of
https://github.com/quine-global/hyper.git
synced 2026-01-12 20:18:41 -09:00
Made file watching work on Windows (#2220)
This commit is contained in:
parent
966aad150d
commit
51b08930ee
1 changed files with 19 additions and 13 deletions
|
|
@ -14,23 +14,29 @@ const _watch = function () {
|
||||||
return _watcher;
|
return _watcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.platform === 'win32') {
|
const onChange = () => {
|
||||||
// watch for changes on config every 2s on windows
|
|
||||||
// https://github.com/zeit/hyper/pull/1772
|
|
||||||
_watcher = fs.watchFile(cfgPath, {interval: 2000});
|
|
||||||
} else {
|
|
||||||
_watcher = fs.watch(cfgPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
_watcher.on('change', () => {
|
|
||||||
cfg = _import();
|
cfg = _import();
|
||||||
notify('Configuration updated', 'Hyper configuration reloaded!');
|
notify('Configuration updated', 'Hyper configuration reloaded!');
|
||||||
watchers.forEach(fn => fn());
|
watchers.forEach(fn => fn());
|
||||||
});
|
};
|
||||||
|
|
||||||
_watcher.on('error', error => {
|
if (process.platform === 'win32') {
|
||||||
console.error('error watching config', error);
|
// watch for changes on config every 2s on windows
|
||||||
});
|
// https://github.com/zeit/hyper/pull/1772
|
||||||
|
_watcher = fs.watchFile(cfgPath, {interval: 2000}, (curr, prev) => {
|
||||||
|
if (curr.mtime === 0) {
|
||||||
|
console.error('error watching config');
|
||||||
|
} else if (curr.mtime !== prev.mtime) {
|
||||||
|
onChange();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
_watcher = fs.watch(cfgPath);
|
||||||
|
_watcher.on('change', onChange);
|
||||||
|
_watcher.on('error', error => {
|
||||||
|
console.error('error watching config', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.subscribe = function (fn) {
|
exports.subscribe = function (fn) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue