-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
51 lines (43 loc) · 1.32 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
'use strict';
const union = require('arr-union');
const reflinks = require('reflinks');
const arrayify = val => [].concat(val || []).sort();
/**
* Generate a reflink or list of reflinks for npm modules.
*
* - If no repo names are passed, reflinks are generated for all locally-installed
* dependencies listed in package.json
* - If names are passed, reflinks are generated both from matching locally-
* installed dependencies and, if necessary, by pulling them down from npm.
*
* @param {String|Array} `repos` Repo name or array of names.
* @param {Object} `options`
* @param {Function} `cb`
* @return {Array}
*/
module.exports = function(config) {
return function(names, options, cb) {
if (typeof names === 'function') {
cb = names;
options = {};
names = null;
}
if (typeof options === 'function') {
cb = options;
options = {};
}
const app = this || {};
const opts = Object.assign({}, config, options, app.options);
const ctx = Object.assign({}, app.context);
names = arrayify(names);
names = union([], names, opts.names, ctx.names);
if (names.length === 0) {
cb(null, '');
return;
}
reflinks(names, opts, function(err, res) {
if (err) return cb(err);
cb(null, '\n\n' + res.links.join('\n'));
});
};
};