-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbin
executable file
·48 lines (44 loc) · 1.34 KB
/
bin
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
#!/usr/bin/env node
const npmAuthorsContributors = require('npm-authors-contributors')
const yargs = require('yargs')
const argv = yargs
.scriptName('creditstxt')
.usage('Usage: $0 [options]')
.alias('h', 'help')
.alias('v', 'version')
.describe('production', 'Do not output contributors to devDependencies')
.boolean('production')
.example('npx creditstxt > static/credits.txt')
.argv
const options = { productionOnly: argv.production }
npmAuthorsContributors(options, process.cwd(), function (error, people) {
if (error) {
console.error(error)
process.exit(1)
}
// Compile an Object map from contributor or author name to an Array
// of package names to which they contributed.
const packagesByName = {}
people.forEach(function (person) {
const name = person.name
if (!name) return
if (packagesByName.name) {
person.packages.forEach(function (packageName) {
const packages = packagesByName[name]
if (packages.indexOf(packageName) === -1) {
packages.push(packageName)
}
})
} else {
packagesByName[name] = person.packages
}
})
// Output one line per contributor, listing their packages.
Object.keys(packagesByName)
.sort()
.forEach(function (name) {
console.log(
name + ': ' + packagesByName[name].sort().join(', ')
)
})
})