@choojs/发现
这是叉子 Filirom1/ 发现待定 16号。 。 。 .
安装
npm install -g @choojs/findup
使用量
在祖先的目录中查找文件
.
├── config.json
└── f
└── e
└── d
└── c
├── b
│ └── a
└── config.json
选项
maxdepth: (数目, 默认-1) 放弃前要穿越多远 如果最大深度为-1,则没有限制.
自动同步
查找( dir, 文件Name, 选项, 回调)
查找( dir, 转发器, 选项, 回调) iterator(dir, cb) 仅接受 cb true 或者说 false
var findup = require('@choojs/findup');
findup(__dirname + '/f/e/d/c/b/a', 'config.json', function(err, dir){
// if(e) e === new Error('not found')
// dir === '/f/e/d/c'
});
或者说
findup(__dirname + '/f/e/d/c/b/a', function(dir, cb){
require('path').exists(dir + '/config.json', cb);
}, function(err, dir){
// if(e) e === new Error('not found')
// dir === '/f/e/d/c'
});
事件编辑器
查找( dir, 文件Name, 选项)
var findup = require('@choojs/findup');
var fup = findup(__dirname + '/f/e/d/c/b/a', 'config.json');
查找( dir, 转发器, 选项) iterator(dir, cb) 仅接受 cb true 或者说 false
var findup = require('@choojs/findup');
var fup = findup(__dirname + '/f/e/d/c/b/a', function(dir, cb){
require('path').exists(dir + '/config.json', cb);
});
找到返回事件Emiter。 发布3个事件: found, (中文(简体) ), error, (中文(简体) ), end
found 每次找到文件时都会发出事件.
你可以打个电话来阻止这段旅程 stop 手动.
fup.on('found', function(dir){
// dir === '/f/e/d/c'
fup.stop();
});
error 出错时会释放事件
fup.on('error', function(e){
// if(e) e === new Error('not found')
});
end 事件在翻转结束时或之后释放 stop() 实值
电话.
fup.on('end', function(){
// happy end
});
同步
查找( dir, 文件Name
查找( dir, 转发器Sync) 与 iteratorSync 返回时 true 或者说 false
var findup = require('@choojs/findup');
try{
var dir = findup.sync(__dirname + '/f/e/d/c/b/a', 'config.json'); // dir === '/f/e/d/c'
}catch(e){
// if(e) e === new Error('not found')
}
国 际
npm install -g @choojs/findup
$ cd test/fixture/f/e/d/c/b/a/
$ findup package.json
/root/findup/package.json
使用量
$ findup -h
Usage: findup [FILE]
--name, -n The name of the file to found
--dir, -d The directoy where we will start walking up $PWD
--help, -h show usage false
--verbose, -v print log false