made filter to work by regex (untested)

This commit is contained in:
AJ ONeal 2013-07-05 16:41:46 -07:00
parent 7d10ccfb6f
commit 60ddf2a503
2 changed files with 31 additions and 33 deletions

View File

@ -1,5 +1,4 @@
{ "es5": true
, "node": true
{ "node": true
, "browser": true
, "jquery": true

View File

@ -37,7 +37,7 @@
me._wq = [];
me._wqueue = [me._wq];
me._wcurpath = undefined;
me._wfilters = options.filters;
me._wfilters = options.filters || [];
me._wfirstrun = true;
me._wcurpath = pathname;
@ -185,30 +185,32 @@
me._wReadFiles();
});
};
Walker.prototype._wFilter = function () {
var me = this
, exclude
;
// Stop directories that contain filter keywords
// from continuing through the walk process
exclude = me._wfilters.some(function (filter) {
if (me._wcurpath.match(filter)) {
return true;
}
});
return exclude;
};
Walker.prototype._wWalkSync = function () {
console.log('walkSync');
//console.log('walkSync');
var err
, files
, me = this
;
// Stop directories that contain filter keywords
// from continuing through the walk process
if (me._wfilters != undefined) {
var shouldExclude = false;
for (var iFilter=0; iFilter<me._wfilters.length; ++iFilter) {
if (me._wcurpath.indexOf(me._wfilters[iFilter]) != -1 ) {
me._wNext();
}
}
}
if( !shouldExclude ) {
try {
files = fs.readdirSync(me._wcurpath);
} catch(e) {
err = e;
}
try {
files = fs.readdirSync(me._wcurpath);
} catch(e) {
err = e;
}
me._wReaddirHandler(err, files);
@ -218,16 +220,6 @@
var me = this
;
// Stop directories that contain filter keywords
// from continuing through the walk process
if (me._wfilters != undefined) {
for (var iFilter=0; iFilter<me._wfilters.length; ++iFilter) {
if (me._wcurpath.indexOf(me._wfilters[iFilter]) != -1 ) {
me._wNext();
}
}
}
// TODO how to remove this anony?
fs.readdir(me._wcurpath, function (err, files) {
me._wReaddirHandler(err, files);
@ -242,13 +234,20 @@
}
if (me._wq.length) {
me._wcurpath = me._wq.pop();
me._wWalk();
while (me._wq.length && me._wFilter()) {
me._wcurpath = me._wq.pop();
}
if (me._wcurpath) {
me._wWalk();
} else {
me._wNext();
}
return;
}
me._wqueue.length -= 1;
if (me._wqueue.length) {
me._wq = me._wqueue[me._wqueue.length - 1];
return this._wNext();
return me._wNext();
}
// To not break compatibility