mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-17 23:53:25 +02:00
Add a Node.js code watcher. It's not a separate process, so it can check require.cache for files it should watch. Currently unused due to missing SIGHUP handlers.
This commit is contained in:
21
lib/util/refresh.js
Normal file
21
lib/util/refresh.js
Normal file
@@ -0,0 +1,21 @@
|
||||
var fs = require('fs')
|
||||
|
||||
var watchers = Object.create(null)
|
||||
|
||||
function refresh() {
|
||||
process.kill('SIGHUP')
|
||||
}
|
||||
|
||||
function collect() {
|
||||
Object.keys(require.cache).forEach(function(path) {
|
||||
if (!watchers[path]) {
|
||||
if (path.indexOf('node_modules') === -1) {
|
||||
watchers[path] = fs.watch(path, refresh)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = function() {
|
||||
collect()
|
||||
}
|
||||
Reference in New Issue
Block a user