-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
43 lines (37 loc) · 1 KB
/
example.js
File metadata and controls
43 lines (37 loc) · 1 KB
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
'use strict';
const through = require('through2');
const pad = require('right-pad-keys');
const dependents = require('./');
let results = {};
const tasks = [];
const transform = through.obj(function(dependent, enc, next) {
// queue up tasks to retrieve package.json files later
const task = () => {
return dependent.package()
.then((pkg) => {
process.stdout.write('.');
results[pkg.name] = pkg.repository ? pkg.repository.url : '<undefined>';
});
};
tasks.push(task);
next(null, dependent);
}, function(cb) {
// get all of the package.json files at once
Promise.all(tasks.map((task) => task()))
.then(() => {
process.stdout.write('\n');
results = pad(results);
Object.keys(results).forEach(function(key) {
console.log(key, results[key]);
});
})
.then(cb)
.catch(cb);
});
dependents('micromatch')
.pipe(transform)
.on('data', () => {})
.on('error', console.error)
.on('end', function() {
console.log('done');
});