connect-compiler 满足不了我的需求, 编译过程是Makefile写的, 希望当某个文件夹被改变后, 自动执行某个命令. 是否有这样的工具?
感谢 @jiyinyiyong
var watch = require('watch')
, spawn = require('child_process').spawn
;
watch.createMonitor('.', { ignoreDotFiles: true }, function (monitor) {
monitor.on("created", function (f, stat) {
// Handle file changes
})
monitor.on("changed", function (f, curr, prev) {
if(f == 'Makefile' || /\.jade$/.test(f)) make();
})
monitor.on("removed", function (f, stat) {
// Handle removed files
})
});
function make() {
console.log('start make')
var makeprg = spawn('make')
makeprg.stdout.on('data', function(data) {
console.log(data.toString());
});
makeprg.stderr.on('data', function(data) {
console.log(data.toString());
});
makeprg.on('exit', function(code) {
console.log('make done ' + code);
})
}
回复 (10)
S
可以自己写一个的,用fs.watch来监视目录变化,然后执行你写的脚本就好了
G
引用 sumory可以自己写一个的,用fs.watch来监视目录变化,然后执行你写的脚本就好了
fs.watch无法监视文件夹
J
搜到 3 个监视树的
node-inotify-plusplus
directive = {
all_events: function (ev) {
console.log("some things happened: " + ev.masks.toString())
},
moved_from: true
}
watcher = require('watch-tree').watchTree(path, {'sample-rate': 5});
watcher.on('fileDeleted', function(path) {
console.log("Quoth the walrus: Noooo, they're deleting mah " + path + "!");
});
watch.watchTree('/home/mikeal', function (f, curr, prev) {
if (typeof f == "object" && prev === null && curr === null) {
// Finished walking the tree
} else if (prev === null) {
// f is a new file
} else if (curr.nlink === 0) {
// f was removed
} else {
// f was changed
}
})
J
mark
S
G
引用 jiyinyiyong搜到 3 个监视树的 node inotify plusplus directive = { all events: function (ev) { console.log("some thi...
node_inotify 在mac下npm install 失败, 不解
G
引用 jiyinyiyong搜到 3 个监视树的 node inotify plusplus directive = { all events: function (ev) { console.log("some thi...
试试 watch, mikeal 这位作者有很多优秀的作品.
J
引用 jiyinyiyong搜到 3 个监视树的 node inotify plusplus directive = { all events: function (ev) { console.log("some thi...
@guilin 我也只是搜到网页,, npm search 里面只有 inotify-plusplus..
页面的文档只提到编译, 怀疑只能编译
X
对于这类问题,我一般是用 ruby 的 guard 来解决的,定义规则非常方便,而且已有大量的第三方资源可供使用。它应当是目前监控类应用中最为成熟的,强烈推荐。不过使用前提是得熟悉一下 ruby 的基本语法。
G
参与回复
登录后即可参与回复。登录
