This repository has been archived by the owner on May 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
index.js
115 lines (104 loc) · 2.97 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env node
'use strict'
const { promises: fs } = require('fs')
const readdirp = require('readdirp')
const { dirname, basename, resolve } = require('path')
const semver = require('semver')
const { titleCase } = require('title-case')
const main = async () => {
let contributors
try {
const rc = JSON.parse(
await fs.readFile('.all-contributorsrc', {
encoding: 'utf8'
})
)
contributors = rc.contributors
} catch (_) {}
console.log(
"<!-- This document was automatically generated through `credit-roll`. Please don't edit it directly. -->"
)
console.log()
console.log('# Credits')
console.log()
console.log(
'This project is made possible by the community surrounding it and especially the wonderful people and projects listed in this document.'
)
console.log()
if (contributors) {
console.log('## Contributors')
console.log()
for (const { login, name } of contributors) {
console.log(` - [${name}](https://github.com/${login})`)
}
console.log()
}
for (const file of process.argv.slice(2)) {
const absolutePath = resolve(process.cwd(), file)
const data = require(absolutePath)
const section = basename(file, '.json')
console.log(`## ${titleCase(section)}`)
console.log()
for (const { name } of data) {
console.log(` - ${name}`)
}
console.log()
}
console.log('## Libraries')
console.log()
const entries = await readdirp.promise('node_modules', {
fileFilter: 'package.json'
})
const pkgs = {}
for (const entry of entries) {
const entryBuffer = await fs.readFile(entry.fullPath)
let pkg
try {
pkg = JSON.parse(entryBuffer)
} catch (err) {
//malformed JSON, skip this entry
continue
}
if (!pkg.version) continue
pkg.fullPath = entry.fullPath
if (!pkgs[pkg.name] || semver.lt(pkgs[pkg.name].version, pkg.version)) {
pkgs[pkg.name] = pkg
}
}
for (const pkgName of Object.keys(pkgs).sort()) {
const pkg = pkgs[pkgName]
const licenseName =
pkg.license ||
(pkg.licenses && pkg.licenses.map(({ type }) => type).join(', '))
let licenseText
for await (const licenseEntry of readdirp(`${dirname(pkg.fullPath)}`, {
fileFilter: e => /^license/i.test(e.basename)
})) {
licenseText = await fs.readFile(licenseEntry.fullPath, {
encoding: 'utf8'
})
break
}
if (!licenseName && !licenseText) continue
console.log(`### [${pkg.name}](https://ghub.io/${pkg.name})`)
console.log()
if (licenseText) {
console.log('<details>')
console.log(` <summary>${licenseName || 'UNKNOWN LICENSE'}</summary>`)
console.log()
console.log(
(licenseText || 'UNKNOWN LICENSE TEXT').replace(/^/gm, ' ')
)
console.log()
console.log('</details>')
} else {
console.log(licenseName || 'UNKNOWN LICENSE')
}
console.log()
}
console.log()
}
main().catch(err => {
console.error(err)
process.exit(1)
})