有没有当文件时改变自动make的middleware
发布于 13 年前 作者 guilin 5676 次预览 最后一次回复是 13 年前 来自
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 回复
可以自己写一个的,用fs.watch来监视目录变化,然后执行你写的脚本就好了
fs.watch无法监视文件夹
搜到 3 个监视树的
node-inotify-plusplus
node-watch-tree
watch
Monitoring directory for changes - potential high memory
mark
@guilin
node_inotify 在mac下npm install 失败, 不解
试试 watch, mikeal 这位作者有很多优秀的作品.
@guilin 我也只是搜到网页,
npm search里面只有inotify-plusplus…页面的文档只提到编译, 怀疑只能编译
对于这类问题,我一般是用 ruby 的 guard 来解决的,定义规则非常方便,而且已有大量的第三方资源可供使用。它应当是目前监控类应用中最为成熟的,强烈推荐。不过使用前提是得熟悉一下 ruby 的基本语法。
ruby在CI等方面的确是非常领先. 收藏.