Skip to content

Commit 7b907d9

Browse files
committed
feat: add generate changelog feature
1 parent f14c284 commit 7b907d9

File tree

5 files changed

+95
-13
lines changed

5 files changed

+95
-13
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
## Latest
22

3+
- chore: add CHANGELOG.md f14c2848
34
- feat: init :seedling: c681eb22

bin/perfekt.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
#!/usr/bin/env node
22

3-
const perfekt = require('../dist').default
3+
const { program } = require('commander')
4+
const { changelog } = require('../dist').default
45

5-
perfekt()
6+
program
7+
.command('changelog')
8+
.description('generate package changelog')
9+
.action(() => changelog())
10+
11+
program.parse(process.argv)

package-lock.json

Lines changed: 65 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
"semver"
3030
],
3131
"license": "MIT",
32+
"dependencies": {
33+
"commander": "^5.0.0"
34+
},
3235
"devDependencies": {
3336
"@babel/core": "^7.9.0",
3437
"@babel/preset-env": "^7.9.5",

src/index.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
1-
console.log('init')
1+
import { exec } from 'child_process'
2+
3+
const changelog = () =>
4+
exec('git log --format="%H %s"', (_, res) => {
5+
let changelog = '## Latest\n\n'
6+
const commits = res.split('\n').filter(commit => commit)
7+
commits.forEach(commit => {
8+
const {
9+
groups: { hash, title }
10+
} = commit.match(/(?<hash>.{40}) (?<title>.*)/)
11+
12+
changelog += `- ${title} ${hash.slice(0, 8)}\n`
13+
})
14+
15+
return process.stdout.write(changelog)
16+
})
17+
18+
export default { changelog }

0 commit comments

Comments
 (0)