1 |
|
/* |
2 |
|
Copyright (c) 2012, Yahoo! Inc. All rights reserved. |
3 |
|
Copyrights licensed under the New BSD License. See the accompanying LICENSE file for terms. |
4 |
|
*/ |
5 |
|
|
6 |
1 |
var fileset = require('fileset'), |
7 |
|
path = require('path'), |
8 |
|
seq = 0; |
9 |
|
|
10 |
1 |
function filesFor(options, callback) { |
11 |
7 |
if (!callback && typeof options === 'function') { |
12 |
1 |
callback = options; |
13 |
1 |
options = null; |
14 |
|
} |
15 |
7 |
options = options || {}; |
16 |
|
|
17 |
7 |
var root = options.root, |
18 |
|
includes = options.includes, |
19 |
|
excludes = options.excludes, |
20 |
|
relative = options.relative, |
21 |
|
opts; |
22 |
|
|
23 |
7 |
root = root || process.cwd(); |
24 |
7 |
includes = includes && Array.isArray(includes) ? includes : [ '**/*.js' ]; |
25 |
7 |
excludes = excludes && Array.isArray(excludes) ? excludes : [ '**/node_modules/**' ]; |
26 |
|
|
27 |
7 |
opts = { cwd: root }; |
28 |
7 |
seq += 1; |
29 |
7 |
opts['x' + seq + new Date().getTime()] = true; //cache buster for minimatch cache bug |
30 |
7 |
fileset(includes.join(' '), excludes.join(' '), opts, function (err, files) { |
31 |
7 |
Iif (err) { return callback(err); } |
32 |
7 |
if (!relative) { |
33 |
355 |
files = files.map(function (file) { return path.resolve(root, file); }); |
34 |
|
} |
35 |
7 |
callback(err, files); |
36 |
|
}); |
37 |
|
} |
38 |
|
|
39 |
1 |
function matcherFor(options, callback) { |
40 |
|
|
41 |
4 |
if (!callback && typeof options === 'function') { |
42 |
1 |
callback = options; |
43 |
1 |
options = null; |
44 |
|
} |
45 |
4 |
options = options || {}; |
46 |
4 |
options.relative = false; //force absolute paths |
47 |
|
|
48 |
4 |
filesFor(options, function (err, files) { |
49 |
4 |
var fileMap = {}; |
50 |
4 |
Iif (err) { return callback(err); } |
51 |
238 |
files.forEach(function (file) { fileMap[file] = true; }); |
52 |
10 |
return callback(null, function (file) { return fileMap[file]; }); |
53 |
|
}); |
54 |
|
} |
55 |
|
|
56 |
1 |
module.exports = { |
57 |
|
filesFor: filesFor, |
58 |
|
matcherFor: matcherFor |
59 |
|
}; |
60 |
|
|
61 |
|
|