-
Notifications
You must be signed in to change notification settings - Fork 2
/
build-changelog.js
33 lines (27 loc) · 1.06 KB
/
build-changelog.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
'use strict';
var fs = require('fs');
var path = require('path');
console.log('Building Changelog...');
var notesPath = path.join('notes');
var notes = fs.readdirSync(notesPath);
var changelogHeader = '';
var changelogData = '';
console.log('Processing ' + notes.length + ' files.');
notes.sort().reverse().forEach(function (note) {
console.log('\t' + path.parse(note).name);
if (path.parse(note).name === '_header') {
changelogHeader = fs.readFileSync(path.join(notesPath, note), 'utf8') + '\n\n';
} else {
var changelogEntry = fs.readFileSync(path.join(notesPath, note), 'utf8');
var firstLine = changelogEntry.split('\n')[0];
if (/^## R[\d\.]+\s\-\s\d\d\d\d-\d\d-\d\d$/.test(firstLine) === false) {
console.warn('First line of ' + note + ' does not match appropriate format');
process.exit(1);
}
changelogData += '<section class="log-entry">\n\n';
changelogData += changelogEntry + '\n';
changelogData += '</section>\n';
}
});
fs.writeFileSync('CHANGELOG.md', changelogHeader + changelogData, 'utf8');
console.log('Done!');