This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
forked from craig-andersen-zefr/react-responsive-carousel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate-changelog.js
69 lines (59 loc) · 1.66 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
var changelog = require('changelog');
var fs = require('fs');
var packageObj = require('./package.json')
changelog.generate('react-responsive-carousel')
.then(showChanges);
var allowedMessages = [
'Allow',
'Add',
'Fix',
'Remov',
'Replac',
'Updat',
'Refact',
'Deplo',
];
var notAllowedMessages = [
/^[0-9.]+$/,
/Merge pull request/,
/Merge branch/,
/Updating changelog/,
/Prepare for publishing/
];
function any(list, message) {
return list.filter(regexp => regexp.test(message)).length > 0;
};
var log = [];
function agreggate(message) {
if (message.indexOf('Merge pull request') !== -1) {
message = message.split('\n')
.filter(line => line.trim() !== '')
.map((line, index) => {
if (index > 0) {
return ' > ' + line;
}
return line;
}).join('\n');
}
log.push(message);
console.log(message);
}
function showChanges(data) {
try{
agreggate('# ' + packageObj.description);
data.versions.forEach(function(version) {
agreggate('\n\n## ' + version.version + ' - ' + new Date(version.date).toDateString());
if (version.changes) {
//version.changes is an array of commit messages for that version
version.changes.forEach(function(change) {
if (!any(notAllowedMessages, change.message)) {
agreggate(' * ' + change.message);
}
});
}
});
fs.writeFileSync('CHANGELOG.md', log.join('\n'), { flag: 'w' });
} catch(e) {
console.log(e);
}
}