recursive-readdir
Advanced tools
Comparing version 1.2.1 to 1.3.0
@@ -0,1 +1,7 @@ | ||
v1.3.0 - Wed, 14 Oct 2015 14:35:55 GMT | ||
-------------------------------------- | ||
- [45abf8fde380d7b1f5dc0e798d435ed50b834d9c](../../commit/45abf8fde380d7b1f5dc0e798d435ed50b834d9c) [added] added custom matcher function to determine whether to ignore a file | ||
- [eebc91c67abce413d6213e8f389ba4e0d32ffb63](../../commit/eebc91c67abce413d6213e8f389ba4e0d32ffb63) [fixed] allow ignoring directories | ||
v1.2.1 - Wed, 14 Jan 2015 16:49:55 GMT | ||
@@ -2,0 +8,0 @@ -------------------------------------- |
62
index.js
@@ -5,11 +5,27 @@ var fs = require('fs') | ||
// how to know when you are done? | ||
function patternMatcher(pattern) { | ||
return function(path, stats) { | ||
var minimatcher = new minimatch.Minimatch(pattern, {matchBase: true}) | ||
return (!minimatcher.negate || stats.isFile()) && minimatcher.match(path) | ||
} | ||
} | ||
function toMatcherFunction(ignoreEntry) { | ||
if (typeof ignoreEntry == 'function') { | ||
return ignoreEntry | ||
} else { | ||
return patternMatcher(ignoreEntry) | ||
} | ||
} | ||
function readdir(path, ignores, callback) { | ||
if (typeof ignores == 'function') { | ||
callback = ignores | ||
ignores = [] | ||
ignores = [] | ||
} | ||
ignores = ignores.map(toMatcherFunction) | ||
var list = [] | ||
fs.readdir(path, function (err, files) { | ||
fs.readdir(path, function(err, files) { | ||
if (err) { | ||
@@ -25,35 +41,37 @@ return callback(err) | ||
var ignoreOpts = {matchBase: true} | ||
files.forEach(function (file) { | ||
for (var i = 0; i < ignores.length; i++) { | ||
if (minimatch(p.join(path, file), ignores[i], ignoreOpts)) { | ||
files.forEach(function(file) { | ||
fs.lstat(p.join(path, file), function(_err, stats) { | ||
if (_err) { | ||
return callback(_err) | ||
} | ||
file = p.join(path, file) | ||
if (ignores.some(function(matcher) { return matcher(file, stats) })) { | ||
pending -= 1 | ||
if (pending <= 0) { | ||
callback(null, list) | ||
if (!pending) { | ||
return callback(null, list) | ||
} | ||
return | ||
return null | ||
} | ||
} | ||
fs.lstat(p.join(path, file), function (err, stats) { | ||
if (err) { | ||
return callback(err) | ||
} | ||
if (stats.isDirectory()) { | ||
readdir(file, ignores, function(__err, res) { | ||
if (__err) { | ||
return callback(__err) | ||
} | ||
if (stats.isDirectory()) { | ||
files = readdir(p.join(path, file), ignores, function (err, res) { | ||
list = list.concat(res) | ||
pending -= 1 | ||
if (!pending) { | ||
callback(null, list) | ||
return callback(null, list) | ||
} | ||
}) | ||
} | ||
else { | ||
list.push(p.join(path, file)) | ||
} else { | ||
list.push(file) | ||
pending -= 1 | ||
if (!pending) { | ||
callback(null, list) | ||
return callback(null, list) | ||
} | ||
} | ||
}) | ||
@@ -60,0 +78,0 @@ }) |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "1.2.1", | ||
"version": "1.3.0", | ||
"repository": { | ||
@@ -24,7 +24,7 @@ "type": "git", | ||
"dependencies": { | ||
"minimatch": "~0.3.0" | ||
"minimatch": "0.3.0" | ||
}, | ||
"devDependencies": { | ||
"mocha": "~1.14.0" | ||
"mocha": "1.14.0" | ||
} | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
#recursive-readdir | ||
# recursive-readdir | ||
@@ -13,7 +13,7 @@ [![Build Status](https://travis-ci.org/jergason/recursive-readdir.svg?branch=master)](https://travis-ci.org/jergason/recursive-readdir) | ||
##Installation | ||
## Installation | ||
npm install recursive-readdir | ||
##Usage | ||
## Usage | ||
@@ -42,3 +42,22 @@ | ||
You can also pass functions which are called to determine whether or not to | ||
ignore a file: | ||
```javascript | ||
var recursive = require('recursive-readdir'); | ||
function ignoreFunc(file, stats) { | ||
// `file` is the absolute path to the file, and `stats` is an `fs.Stats` | ||
// object returned from `fs.lstat()`. | ||
return stats.isDirectory() && path.basename(file) == "test"; | ||
} | ||
// Ignore files named 'foo.cs' and descendants of directories named test | ||
recursive('some/path', ['foo.cs', ignoreFunc], function (err, files) { | ||
// Files is an array of filename | ||
console.log(files); | ||
}); | ||
``` | ||
The ignore strings support Glob syntax via | ||
[minimatch](https://github.com/isaacs/minimatch). |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13635
291
62
1
Updatedminimatch@0.3.0