Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/bebraw/node-filewalker into…
Browse files Browse the repository at this point in the history
… bebraw-master
  • Loading branch information
oleics committed Jun 25, 2013
2 parents edef0c6 + 95f51f2 commit c1712f8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ Useful to let network-drives remount, etc.
A RegExp-instance the path to a file must match in order to
emit a "file" event. Set to ```null``` to emit all paths.

```recursive``` (default: true)
Traverse in a recursive manner.
In case you wish to target only the current directory,
disable this.

### Properties

maxPending
Expand Down Expand Up @@ -157,4 +162,4 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4 changes: 3 additions & 1 deletion lib/filewalker.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ function Filewalker(root, options) {

this.matchRegExp = null;

this.recursive = true;

options = options || {};
Object.keys(options).forEach(function(k) {
if(self.hasOwnProperty(k)) {
Expand Down Expand Up @@ -48,7 +50,7 @@ Filewalker.prototype._emitDir = function(p, s, fullPath) {
fs.readdir(fullPath, function(err, files) {
if(err) {
self.error(err, self._emitDir, args);
} else {
} else if(self.recursive || !self.dirs) {
files.forEach(function(file) {
self.enqueue(self._stat, [path.join(fullPath, file)]);
});
Expand Down
23 changes: 23 additions & 0 deletions test/basic-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ describe('Filewalker', function() {
it('should have a .matchRegExp property <number>', function() {
assert.strictEqual(fw.matchRegExp, null);
});
it('should have a .recursive property <boolean>', function() {
assert.strictEqual(fw.recursive, true);
});
it('should have a .walk() method', function() {
assert.ok(fw.walk instanceof Function);
});
Expand Down Expand Up @@ -346,4 +349,24 @@ describe('Filewalker', function() {
fw.walk();
});
});

describe('feature: non-recursive walking', function() {
var fw;
before(function() {
fw = filewalker(examplesDir, {recursive: false});
});
after(function() {
fw = null;
});

it('"done" event without recursive', function(done) {
fw.on('done', function() {
// it could be nicer to check the amount using fs on examplesDir
// this works, though, given the structure of /examples doesn't change
assert.strictEqual(this.files + this.dirs, 2);
done();
});
fw.walk();
});
});
});

0 comments on commit c1712f8

Please sign in to comment.