-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathchangelog-maker.js
executable file
·54 lines (43 loc) · 1.35 KB
/
changelog-maker.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
#!/usr/bin/env node
import _debug from 'debug'
import process from 'process'
import minimist from 'minimist'
import pkgtoId from 'pkg-to-id'
import { existsSync, readFileSync } from 'fs'
import { join } from 'path'
import { processCommits } from './process-commits.js'
import { commitToList } from './commit-to-list.js'
const debug = _debug('changelog-maker')
const argv = minimist(process.argv.slice(2))
const help = argv.h || argv.help
const pkgFile = join(process.cwd(), 'package.json')
const pkgData = existsSync(pkgFile) ? JSON.parse(readFileSync(pkgFile)) : {}
const pkgId = pkgtoId(pkgData)
const ghId = {
user: argv._[0] || pkgId.user || 'nodejs',
repo: argv._[1] || (pkgId.name && stripScope(pkgId.name)) || 'node'
}
debug(ghId)
if (help) {
showUsage()
process.exit(0)
}
function stripScope (name) {
return name[0] === '@' && name.indexOf('/') > 0 ? name.split('/')[1] : name
}
function showUsage () {
const usage = readFileSync(new URL('README.md', import.meta.url), 'utf8')
.replace(/[\s\S]+(## Usage\n[\s\S]*)\n## [\s\S]+/m, '$1')
.replace(/## Usage\n[\s]*/m, 'Usage: ')
.replace(/\*\*/g, '')
.replace(/`/g, '')
process.stdout.write(usage)
}
async function run () {
const commitList = await commitToList(ghId, argv)
await processCommits(argv, ghId, commitList)
}
run().catch((err) => {
console.error(err)
process.exit(1)
})