forked from sindresorhus/load-grunt-tasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (31 loc) · 1.07 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
'use strict';
var path = require('path');
var pkgUp = require('pkg-up');
var multimatch = require('multimatch');
var arrify = require('arrify');
var resolvePkg = require('resolve-pkg');
module.exports = function (grunt, opts) {
opts = opts || {};
var pattern = arrify(opts.pattern || ['grunt-*', '@*/grunt-*']);
var config = opts.config || pkgUp.sync();
var scope = arrify(opts.scope || ['dependencies', 'devDependencies', 'peerDependencies', 'optionalDependencies']);
if (typeof config === 'string') {
config = require(path.resolve(config));
}
pattern.push('!grunt', '!grunt-cli');
var names = scope.reduce(function (result, prop) {
var deps = config[prop] || [];
return result.concat(Array.isArray(deps) ? deps : Object.keys(deps));
}, []);
multimatch(names, pattern).forEach(function (pkgName) {
if (opts.requireResolution === true) {
try {
grunt.loadTasks(resolvePkg(path.join(pkgName, 'tasks')));
} catch (err) {
grunt.log.error('npm package "' + pkgName + '" not found. Is it installed?');
}
} else {
grunt.loadNpmTasks(pkgName);
}
});
};