
Security News
GitHub Actions Checkout Now Blocks Risky pull_request_target Checkouts
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.
##目的(Purpose) Utilities for auto watching file trees.
自动监视目录树中文件和目录的创建、删除、改变等等事件。当添加新目录时自动给新目录及其子目录和文件添加监视任务。
##安装(Install)
npm install auto-watching
###创建方式:
require('./watch' ).create(function(watch){
//...处理代码
});
//或者
var watch = require('./watch' ).create();
//...处理代码
###事件(Events):
create - 创建文件或目录时触发事件。两个参数:path,stat。path:创建文件或目录的路径;stat:fs.Stats。createfile - 创建文件时触发的事件。两个参数:path,stat。path:创建文件的路径;stat:fs.Stats。createdirectory - 创建目录时触发的事件。两个参数:path,stat。path:创建目录的路径;stat:fs.Stats。delete - 删除文件或目录时触发事件。两个参数:path,stat。path:删除文件或目录的路径;stat:fs.Stats。deletefile - 删除文件时触发的事件。两个参数:path,stat。path:删除文件的路径;stat:fs.Stats。deletedirectory - 删除目录时触发的事件。两个参数:path,stat。path:删除目录的路径;stat:fs.Stats。change - 修改文件或目录时触发事件。两个参数:path,stat。path:修改文件或目录的路径;stat:fs.Stats。changefile - 修改文件时触发的事件。两个参数:path,stat。path:修改文件的路径;stat:fs.Stats。changedirectory - 修改目录时触发的事件。两个参数:path,stat。path:修改目录的路径;stat:fs.Stats。###添加不需要监视目录的规则:
//字符串
watch.exclude(['*index.js']);
//正则表达式
watch.exclude(/.*index.js$/);
watch.exclude(new RegExp(/.*index.js$/));
//函数
watch.exclude(function(path){
return path !== __filename;
});
###添加事件方法:
watch.listeners(object) - object必须,返回scanFS对象。 watch.listeners({
'create': function(path, stat){
//...
},
'delete': function(path, stat){
//...
}
//...
});
onCreate(fn)、onCreateFile(fn)、onCreateDirectory(fn)、
onDelete(fn)、onDeleteFile(fn)、onDeleteDirectory(fn)、
onChange(fn)、onChangeFile(fn)、onChangeDirectory(fn)。var watch = require('./watch' ).create(function(watch){
/*watch.exclude(['*index.js']);
watch.exclude(/.*index.js$/);
watch.exclude(new RegExp(/.*index.js$/));*/
watch.listeners({
'create': function(path, stat){
console.log('create:' + path, stat);
},
'delete': function(path, stat){
console.log('delete:' + path, stat);
},
'change': function(path, stat){
console.log('change:' + path, stat);
}
}).watchTree(__dirname + '/test', function(err, fileCount, dirCount){
console.log('test: ', arguments);
});
});
//或者
var watch = require('./watch' ).create(function(watch){
/*watch.exclude(['*index.js']);
watch.exclude(/.*index.js$/);
watch.exclude(new RegExp(/.*index.js$/));*/
watch.listeners({
'createfile': function(path, stat){
console.log('createfile:' + path, stat);
console.log(watch.files);
},
'deletefile': function(path, stat){
console.log('deletefile:' + path, stat);
console.log(watch.files);
},
'changefile': function(path, stat){
console.log('changefile:' + path, stat);
console.log(watch.files);
},
'createdirectory': function(path, stat){
console.log('createdirectory:' + path, stat);
console.log(watch.files);
},
'deletedirectory': function(path, stat){
console.log('deletedirectory:' + path, stat);
console.log(watch.files);
},
'changedirectory': function(path, stat){
console.log('changedirectory:' + path, stat);
console.log(watch.files);
}
} ).watchTree(__dirname + '/test', function(err, fileCount, dirCount){
console.log('test: ', arguments);
});
});
FAQs
Utilities for auto watching file trees in node.js.
The npm package auto-watch receives a total of 0 weekly downloads. As such, auto-watch popularity was classified as not popular.
We found that auto-watch demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.