-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
54 lines (46 loc) · 1.86 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
var _ = require("lodash"),
Glob = require("glob").Glob,
path = require("path");
module.exports = function (grunt, extraTopLevelDirectories, extraExcludeSubstrings) {
extraTopLevelDirectories = extraTopLevelDirectories || [];
extraExcludeSubstrings = extraExcludeSubstrings || [];
var excludedDirectoryNameSubstrings = ["node_modules", "bower_components"].concat(extraExcludeSubstrings),
implicitTopLevelDirectories = ["app", "lib", "test", "spec"],
topLevelDirectories = _.uniq(implicitTopLevelDirectories.concat(extraTopLevelDirectories)),
lintableFiles = {};
// itemize each directory so we can exclude known external dependency caches
_.each(topLevelDirectories, function (topLevelDir) {
var hash = {},
glob = new Glob(path.join(topLevelDir, "**"), { sync: true }),
directories = _.compact(_.map(glob.cache, function (value, key) { return (typeof value === "object") ? key : null; }));
directories = _.reject(directories, function (directory) {
return _.some(excludedDirectoryNameSubstrings, function (substring) {
// use a loose match so we get things like 'old_node_modules' and 'bower_components.bak'
return directory.indexOf(substring) > -1;
});
});
hash[topLevelDir] = {
files: {
src: _.map(directories, function (directoryName) {
return path.join(directoryName, "*.js");
})
}
};
// arbitrarily include all the JS files from the root directory in the 'app' target
if (topLevelDir === "app") {
hash[topLevelDir].files.src.unshift("*.js");
}
_.assign(lintableFiles, hash);
});
return {
jshint: _.assign({
options: {
jshintrc: ".jshintrc"
}
}, lintableFiles),
jscs: _.transform(lintableFiles, function (result, hash, key) {
result[key] = hash;
result[key].options = {};
})
};
};