made filter to work by regex (untested)
This commit is contained in:
parent
7d10ccfb6f
commit
60ddf2a503
|
@ -1,5 +1,4 @@
|
||||||
{ "es5": true
|
{ "node": true
|
||||||
, "node": true
|
|
||||||
, "browser": true
|
, "browser": true
|
||||||
, "jquery": true
|
, "jquery": true
|
||||||
|
|
||||||
|
|
61
lib/walk.js
61
lib/walk.js
|
@ -37,7 +37,7 @@
|
||||||
me._wq = [];
|
me._wq = [];
|
||||||
me._wqueue = [me._wq];
|
me._wqueue = [me._wq];
|
||||||
me._wcurpath = undefined;
|
me._wcurpath = undefined;
|
||||||
me._wfilters = options.filters;
|
me._wfilters = options.filters || [];
|
||||||
me._wfirstrun = true;
|
me._wfirstrun = true;
|
||||||
me._wcurpath = pathname;
|
me._wcurpath = pathname;
|
||||||
|
|
||||||
|
@ -185,30 +185,32 @@
|
||||||
me._wReadFiles();
|
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 () {
|
Walker.prototype._wWalkSync = function () {
|
||||||
console.log('walkSync');
|
//console.log('walkSync');
|
||||||
var err
|
var err
|
||||||
, files
|
, files
|
||||||
, me = this
|
, me = this
|
||||||
;
|
;
|
||||||
|
|
||||||
// Stop directories that contain filter keywords
|
try {
|
||||||
// from continuing through the walk process
|
files = fs.readdirSync(me._wcurpath);
|
||||||
if (me._wfilters != undefined) {
|
} catch(e) {
|
||||||
var shouldExclude = false;
|
err = e;
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
me._wReaddirHandler(err, files);
|
me._wReaddirHandler(err, files);
|
||||||
|
@ -218,16 +220,6 @@
|
||||||
var me = this
|
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?
|
// TODO how to remove this anony?
|
||||||
fs.readdir(me._wcurpath, function (err, files) {
|
fs.readdir(me._wcurpath, function (err, files) {
|
||||||
me._wReaddirHandler(err, files);
|
me._wReaddirHandler(err, files);
|
||||||
|
@ -242,13 +234,20 @@
|
||||||
}
|
}
|
||||||
if (me._wq.length) {
|
if (me._wq.length) {
|
||||||
me._wcurpath = me._wq.pop();
|
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;
|
return;
|
||||||
}
|
}
|
||||||
me._wqueue.length -= 1;
|
me._wqueue.length -= 1;
|
||||||
if (me._wqueue.length) {
|
if (me._wqueue.length) {
|
||||||
me._wq = me._wqueue[me._wqueue.length - 1];
|
me._wq = me._wqueue[me._wqueue.length - 1];
|
||||||
return this._wNext();
|
return me._wNext();
|
||||||
}
|
}
|
||||||
|
|
||||||
// To not break compatibility
|
// To not break compatibility
|
||||||
|
|
Loading…
Reference in New Issue