-
Notifications
You must be signed in to change notification settings - Fork 1
/
renderer.js
38 lines (33 loc) · 996 Bytes
/
renderer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
var electron = require('electron');
var ipcRenderer = electron.ipcRenderer;
var glob = require('glob');
var path = require('path');
var cwd = process.cwd();
var watch = require('glob-watcher');
ipcRenderer.on('run', function(sender, rendererGlob) {
glob(rendererGlob, function (err, files) {
files.forEach(function(file) {
require(path.resolve(cwd, file));
});
});
var watcher = watch(rendererGlob);
watcher.on('change', function(event) {
flush();
require(path.resolve(cwd, event.path));
});
});
function flush() {
console.clear();
Object.keys(require.cache).forEach((function (fname) {
if (fname.indexOf('node_modules') === -1) {
delete require.cache[fname];
}
var mods = ['tape', 'electron-tap'];
mods.forEach(function (mod) {
if (fname.indexOf(path.join(cwd, mod) + path.sep) > -1 ||
fname.indexOf(path.join(cwd, 'node_modules', mod) + path.sep) > -1) {
delete require.cache[fname];
}
})
}))
}