Skip to content

Commit 0b04a7a

Browse files
committed
changelog generator
1 parent e331c96 commit 0b04a7a

File tree

4 files changed

+73
-0
lines changed

4 files changed

+73
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#### 2.23.1 (2018-01-01)
2+
13
<a name="2.8.2"></a>
24
## 2.8.2 (2015-07-31)
35

changelog.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const {execSync} = require('child_process');
2+
let [start, end] = process.argv.slice(2);
3+
if (!start || !end) {
4+
console.error('Must provide start and end tags');
5+
console.error(' eg: v1.0 HEAD');
6+
console.error(' eg: v1.0 v2.0');
7+
process.exit(1);
8+
}
9+
const separator = `===END===`;
10+
const res = execSync(`git log -E --format=%H%n%s%b===END=== ${start}..${end}`);
11+
const sep = res.toString().split(separator);
12+
const output = sep
13+
.map((item, i) => {
14+
const [hash, ...body] = getParts(item, i);
15+
const bodyJoined = body.join('\n');
16+
return [hash, bodyJoined];
17+
})
18+
.filter(([, body]) => /^[\w]+: [^ ]/.test(body))
19+
.map(([hash, bodyJoined]) => {
20+
const [section, body] = bodyJoined.split(/: /);
21+
return [hash, section, body];
22+
})
23+
.reduce((acc, item) => {
24+
const [, section] = item;
25+
if (!acc[section]) {
26+
acc[section] = [item];
27+
} else {
28+
acc[section].push(item);
29+
}
30+
return acc;
31+
}, {});
32+
33+
if (process.argv.indexOf('--json') > -1) {
34+
console.log(JSON.stringify(output, null, 2));
35+
} else {
36+
Object.keys(output)
37+
.map(x => [x, output[x]])
38+
.forEach(([section, items]) => {
39+
const header = `**${section}**`;
40+
console.log(header);
41+
items.forEach(([hash, section, body]) => {
42+
console.log(`- ${body} ${hash}`)
43+
});
44+
console.log('')
45+
});
46+
}
47+
48+
49+
50+
function getParts(item, index) {
51+
const segs = item.split('\n');
52+
if (index === 0) return segs;
53+
return segs.slice(1);
54+
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
"chalk": "1.1.3",
7575
"compression": "1.6.2",
7676
"crossbow": "latest",
77+
"generate-changelog": "^1.7.0",
7778
"graceful-fs": "4.1.9",
7879
"gulp": "3.9.1",
7980
"gulp-contribs": "0.0.3",

yarn.lock

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ block-stream@*:
304304
dependencies:
305305
inherits "~2.0.0"
306306

307+
bluebird@^3.0.6:
308+
version "3.5.1"
309+
resolved "https://registry.yarnpkg.com/bluebird/-/bluebird-3.5.1.tgz#d9551f9de98f1fcda1e683d17ee91a0602ee2eb9"
310+
307311
boom@2.x.x:
308312
version "2.10.1"
309313
resolved "https://registry.yarnpkg.com/boom/-/boom-2.10.1.tgz#39c8918ceff5799f83f9492a848f625add0c766f"
@@ -1447,6 +1451,14 @@ gaze@^0.5.1:
14471451
dependencies:
14481452
globule "~0.1.0"
14491453

1454+
generate-changelog@^1.7.0:
1455+
version "1.7.0"
1456+
resolved "https://registry.yarnpkg.com/generate-changelog/-/generate-changelog-1.7.0.tgz#e6321226207d5cbcfe24de39d7ffd65d51698596"
1457+
dependencies:
1458+
bluebird "^3.0.6"
1459+
commander "^2.9.0"
1460+
github-url-from-git "^1.4.0"
1461+
14501462
generate-function@^2.0.0:
14511463
version "2.0.0"
14521464
resolved "https://registry.yarnpkg.com/generate-function/-/generate-function-2.0.0.tgz#6858fe7c0969b7d4e9093337647ac79f60dfbe74"
@@ -1515,6 +1527,10 @@ gitconfiglocal@^1.0.0:
15151527
dependencies:
15161528
ini "^1.3.2"
15171529

1530+
github-url-from-git@^1.4.0:
1531+
version "1.5.0"
1532+
resolved "https://registry.yarnpkg.com/github-url-from-git/-/github-url-from-git-1.5.0.tgz#f985fedcc0a9aa579dc88d7aff068d55cc6251a0"
1533+
15181534
glob-base@^0.3.0:
15191535
version "0.3.0"
15201536
resolved "https://registry.yarnpkg.com/glob-base/-/glob-base-0.3.0.tgz#dbb164f6221b1c0b1ccf82aea328b497df0ea3c4"

0 commit comments

Comments
 (0)