forked from highcharts/highcharts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-changelog.js
223 lines (180 loc) · 6 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/* eslint-env node, es6 */
/* eslint valid-jsdoc: 0, no-console: 0, require-jsdoc: 0 */
/**
* This node script copies commit messages since the last release and
* generates a draft for a changelog.
*
* Parameters
* --after String The start date.
* --before String Optional. The end date for the changelog, defaults to today.
*/
(function () {
'use strict';
var fs = require('fs'),
cmd = require('child_process');
var params;
/**
* Get parameters listed by -- notation
*/
function getParams() {
var p = {};
process.argv.forEach(function (arg, j) {
if (arg.substr(0, 2) === '--') {
p[arg.substr(2)] = process.argv[j + 1];
}
});
return p;
}
/**
* Get the log from Git
*/
function getLog(callback) {
var command;
function puts(err, stdout) {
if (err) {
throw err;
}
callback(stdout);
}
command = 'git log --after={' + params.after + '} --format="%s<br>" ';
if (params.before) {
command += '--before={' + params.before + '} ';
}
cmd.exec(command, 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('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();
// Pull out Fixes and append at the end
var fixes = washed.filter(message => {
return message.indexOf('Fixed') === 0;
});
if (fixes.length > 0) {
washed = washed.filter(message => {
return message.indexOf('Fixed') !== 0;
});
washed = washed.concat(fixes);
washed.startFixes = washed.length - fixes.length;
}
return washed;
}
/**
* Build the output
*/
function buildHTML(name, version, date, log, products) {
var s,
filename = 'changelog-' + name.toLowerCase() + '.htm';
log = washLog(name, log);
// Start the string
s = `<p>${name} ${version} (${date})</p>
<ul>`;
if (name === 'Highstock' || name === 'Highmaps') {
s += ' <li>Most changes listed under Highcharts ' + products.Highcharts.nr +
' above also apply to ' + name + ' ' + version + '.</li>\n';
}
var productPrefix = '',
versionDashed = version.replace(/\./g, '-');
if (name === 'Highstock') {
productPrefix = 'hs-';
} else if (name === 'Highmaps') {
productPrefix = 'hm-';
}
log.forEach((li, i) => {
// Hyperlinked issue numbers
li = li.replace(
/#([0-9]+)/g,
'<a href="https://github.com/highslide-software/highcharts.com/issues/$1">#$1</a>'
);
// Start fixes
if (i === log.startFixes) {
s += `
</ul>
<div id="accordion" class="panel-group">
<div class="panel panel-default">
<div id="${productPrefix}heading-${versionDashed}-bug-fixes" class="panel-heading">
<h4 class="panel-title">
<a href="#${productPrefix}${versionDashed}-bug-fixes" data-toggle="collapse" data-parent="#accordion">
Bug fixes
</a>
</h4>
</div>
<div id="${productPrefix}${versionDashed}-bug-fixes" class="panel-collapse collapse">
<div class="panel-body">
<ul>`;
}
// All items
if (i >= log.startFixes) {
s += `
<li>${li}</li>`;
} else {
s += `
<li>${li}</li>`;
}
// Last item
if (i === log.length - 1) {
s += `
</ul>`;
if (typeof log.startFixes === 'number') {
s += `
</div>
</div>
</div>
</div>`;
}
}
});
fs.writeFile(filename, s, function () {
console.log('Wrote draft to ' + filename);
});
}
params = getParams();
// 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);
}
}
});
});
}());