forked from highcharts/highcharts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-changelog.js
132 lines (106 loc) · 3.8 KB
/
generate-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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*jslint nomen: true*/
/*global require, console, __dirname*/
/**
* This node script copies commit messages since the last release and
* generates a draft for a changelog.
*/
(function () {
'use strict';
var fs = require('fs'),
cmd = require('child_process');
/**
* Get the log from Git
*/
function getLog(callback) {
var after = '2015-02-20',
before = '2015-03-09',
puts = function (err, stdout) {
if (err) {
throw err;
}
callback(stdout);
};
cmd.exec('git log --after={' + after + '} --before={' + before + '} --format="%s<br>"', null, puts);
}
/**
* Prepare the log for each product, and sort the result to get all additions, fixes
* etc. nicely lined up.
*/
function washLog(name, log) {
var washed = [],
proceed = true;
log.forEach(function (item) {
// Keep only the commits after the last release
if (proceed && (new RegExp('^---.+' + name + '.+official release ---$')).test(item)) {
proceed = false;
}
if (proceed) {
// Commits tagged with Highstock or Highmaps
if (name === 'Highstock' && item.indexOf('Highstock:') === 0) {
washed.push(item.replace(/Highstock:\s?/, ''));
} else if (name === 'Highmaps' && item.indexOf('Highmaps:') === 0) {
washed.push(item.replace(/Highmaps:\s?/, ''));
// All others go into the Highcharts changelog for review
} else if (name === 'Highcharts' && !/^High(stock|maps):/.test(item)) {
washed.push(item);
}
}
});
// Last release not found, abort
if (proceed === true) {
throw 'Last release not located, try setting an older start date.';
}
// Sort alphabetically
washed.sort();
return washed;
}
/**
* Build the output
*/
function buildHTML(name, version, date, log, products) {
var s,
seeAlso = '',
filename = 'changelog-' + name.toLowerCase() + '.htm';
log = washLog(name, log);
log = ' <li>' + log.join('</li>\n <li>') + '</li>\n';
// Hyperlinked issue numbers
log = log.replace(
/#([0-9]+)/g,
'<a href="https://github.com/highslide-software/highcharts.com/issues/$1">#$1</a>'
);
if (name === 'Highstock' || name === 'Highmaps') {
seeAlso = ' <li>Most changes listed under Highcharts ' + products.Highcharts.nr +
' above also apply to ' + name + ' ' + version + '.</li>\n';
}
s = '<p>' + name + ' ' + version + ' (' + date + ')</p>\n' +
'<ul>\n' +
seeAlso +
log +
'</ul>\n';
fs.writeFile(filename, s, function () {
console.log('Wrote draft to ' + filename);
});
}
// Get the Git log
getLog(function (log) {
// Split the log into an array
log = log.split('<br>\n');
log.pop();
// Load the current products and versions, and create one log each
fs.readFile('build/dist/products.js', 'utf8', function (err, products) {
var name;
if (err) {
throw err;
}
if (products) {
products = products.replace('var products = ', '');
products = JSON.parse(products);
}
for (name in products) {
if (products.hasOwnProperty(name)) {
buildHTML(name, products[name].nr, products[name].date, log, products);
}
}
});
});
}());