监视... 在节点.js观看文件树的用具
安装
npm install watch
目的
这个模块的意图是提供工具,使文件目录树的监视管理更加容易.
watch.watchTree (root, [options,] callback) (英语)
第一个参数是您想要观看的目录根 .
选项对象被传递到fs.watchFile,但也可用于提供两个额外的WatchTree特定选项:
'ignoreDotFiles'- 当这个选项是真实的,这意味着当文件树被行走时,它会忽略那些与"'filter'- 您可以使用此选项为每个文件和目录提供返回真实或虚假的函数, 以决定是否将该文件/目录包含在监视器中 .'interval'- 指定间隔时间(以秒计), 投票之间更改文件的时间段.'ignoreUnreadableDir'- 当真实时, 此选项意味着当文件无法读取时, 此文件会被默默跳过 .'ignoreNotPermitted'- 当真实时, 这个选项意味着当一个文件由于权限问题而无法读取时, 此文件会被默默跳过 .'ignoreDirectoryPattern'- 当一个正则图案被设定时, 例如 /node modules/, 这些目录会被默默跳过 .
召回则取出三辩. 第一个是修改过的文件。 第二个是该文件的当前stat对象,第三个是上一个stat对象.
当文件为新时, 上一个 stat 对象无效 .
当WatchTree完成行走树并添加所有收听者时,它通过文件散列(键为文件/目录名而值为当前stat对象)作为第一个参数,并且作为上个和当前stat对象参数无效.
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
}
})
watch.unwatchTree(根数)
取消使用先前被监视的目录根 watch.watchTree。 。 。 .
watch.create Monitor( root, [options,] callback) (中文(简体) )
此函数创建一个 EventEmitter , 它为给定根参数下文件和目录树发生的不同变化提供通知 .
选项对象被传递给监视 。 观想特利.
回调接收显示器对象.
显示器对象包含一个属性, files,它是将文件和目录作为密钥的散列,以当前 stat 对象作为值.
监控器有以下事件.
'created'- 已经创建了新文件 。 两个参数:文件名和stat对象.'removed'- 文件已被移动或删除 。 两个参数,fd的文件名和stat对象.'changed'- 一个文件被更改了 三个参数,即文件名、当前 stat 对象和上一个 stat 对象.
监视器可以停止使用 .stop (电话) unwatchTree) (中文(简体) ).
var watch = require('watch')
watch.createMonitor('/home/mikeal', function (monitor) {
monitor.files['/home/mikeal/.zshrc'] // Stat object for my zshrc.
monitor.on("created", function (f, stat) {
// Handle new files
})
monitor.on("changed", function (f, curr, prev) {
// Handle file changes
})
monitor.on("removed", function (f, stat) {
// Handle removed files
})
monitor.stop(); // Stop watching
})
国 际
此模块包括一个简单的命令行界面,您可以用它安装 npm install watch -g。 。 。 .
Usage: watch <command> [...directory] [OPTIONS]
OPTIONS:
--wait=<seconds>
Duration, in seconds, that watching will be disabled
after running <command>. Setting this option will
throttle calls to <command> for the specified duration.
--filter=<file>
Path to a require-able .js file that exports a filter
function to be passed to watchTreeOptions.filter.
Path is resolved relative to process.cwd().
--interval=<seconds>
Specifies the interval duration in seconds, the time period between polling for file changes.
--ignoreDotFiles, -d
Ignores dot or hidden files in the watch [directory].
--ignoreUnreadable, -u
Silently ignores files that cannot be read within the
watch [directory].
--ignoreDirectoryPattern=<regexp>, -p
Silently skips directories that match the regular
expression.
它将用 : watchTree 并每次修改文件时运行给定的命令.
实例
如上文所述,模式是:
watch <command> [...directory] [OPTIONS]
要在终端运行手表命令,您必须写下以下内容:
watch 'npm run test -s' directory
由于命令必须以引号来写 Windows 用户可能需要使用双引号而不是单引号
watch "npm run test -s" directory
注:由于Windows用户可能需要使用双引号而不是单引号,所以他们需要用npm脚本来逃避它们
"scripts": {
"watch:osx": "watch 'npm run test -s' source"
"watch:windows": "watch \"npm run test -s\" source",
}
捐款
释放
在最新的干净 master数字 :
npm run release:major
npm run release:minor
npm run release:patch