Skip to content

Commit 70ab791

Browse files
devversionjelbourn
authored andcommitted
chore: add conventional changelog script.
* The script prepends the new conventional changelog from the latest tag to HEAD. * When using the `--force` flag, the complete changelog will be generated and overwrites, when present the previous changelog. Fixes #171. Closes #179
1 parent 1b1772c commit 70ab791

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"dartanalyzer": "cd dist/dart && pub install && cd ../.. && ts-node scripts/ci/dart_analyzer",
1313
"demo-app": "ng serve",
1414
"test": "karma start test/karma.conf.js",
15-
"tslint" : "tslint -c tslint.json 'src/**/*.ts'",
15+
"tslint": "tslint -c tslint.json 'src/**/*.ts'",
1616
"typings": "typings install --ambient",
1717
"postinstall": "npm run typings",
1818
"e2e": "protractor ./protractor.conf.js"
@@ -34,6 +34,7 @@
3434
"zone.js": "0.5.15"
3535
},
3636
"devDependencies": {
37+
"add-stream": "^1.0.0",
3738
"angular-cli": "^0.0.24",
3839
"angular-cli-github-pages": "^0.2.0",
3940
"broccoli-autoprefixer": "^4.1.0",
@@ -42,6 +43,7 @@
4243
"broccoli-sass": "^0.7.0",
4344
"broccoli-source": "^1.1.0",
4445
"browserstacktunnel-wrapper": "^1.4.2",
46+
"conventional-changelog": "^1.1.0",
4547
"ember-cli-inject-live-reload": "^1.3.0",
4648
"fs-extra": "^0.26.5",
4749
"glob": "^6.0.4",

scripts/release/update-changelog.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
'use strict';
2+
/**
3+
* Creates a conventional changelog from the current git repository / metadata.
4+
*/
5+
6+
var fs = require('fs');
7+
var addStream = require('add-stream');
8+
var cl = require('conventional-changelog');
9+
var inStream = fs.createReadStream('CHANGELOG.md');
10+
11+
/**
12+
* When the command line argument `--force` is provided, then the full changelog will created and overwritten.
13+
* By default, it will only create the changelog from the latest tag to head and prepends it to the changelog.
14+
*/
15+
var isForce = process.argv.indexOf('--force') !== -1;
16+
17+
inStream.on('error', function(err) {
18+
console.error('An error occurred, while reading the previous changelog file.\n' +
19+
'If there is no previous changelog, then you should create an empty file or use the `--force` flag.\n' + err);
20+
21+
process.exit(1);
22+
});
23+
24+
var config = {
25+
preset: 'angular',
26+
releaseCount: isForce ? 0 : 1
27+
};
28+
29+
var stream = cl(config)
30+
.on('error', function(err) {
31+
console.error('An error occurred while generating the changelog: ' + err);
32+
})
33+
.pipe(!isForce && addStream(inStream) || getOutputStream());
34+
35+
// When we are pre-pending the new changelog, then we need to wait for the input stream to be ending,
36+
// otherwise we can't write into the same destination.
37+
if (!isForce) {
38+
inStream.on('end', function() {
39+
stream.pipe(getOutputStream());
40+
});
41+
}
42+
43+
function getOutputStream() {
44+
return fs.createWriteStream('CHANGELOG.md');
45+
}

0 commit comments

Comments
 (0)