-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathcommit-logger.js
More file actions
57 lines (49 loc) · 1.65 KB
/
commit-logger.js
File metadata and controls
57 lines (49 loc) · 1.65 KB
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
const child = require('child_process');
const fs = require('fs');
const output = child.execSync('git log --format=%B%H----DELIMITER----').toString('utf-8');
const commitsArray = output
.split('----DELIMITER----\n')
.map((commit) => {
const [message, sha] = commit.split('\n');
return { sha, message };
})
.filter((commit) => Boolean(commit.sha));
const currentChangeLog = fs.readFileSync('./CHANGELOG.md', 'utf-8');
const currentVersion = Number(require('./package.json').version);
const newVersion = currentVersion + 1;
let newChangeLog = `# Version ${newVersion} (${new Date().toISOString().split('T')[0]})\n\n`;
const features = [];
const chores = [];
commitsArray.forEach((commit) => {
if (commit.message.startsWith('feature: ')) {
features.push(
`* ${commit.message.replace('feature: ', '')} ([${commit.sha.substring(
0,
6,
)}](https://github.com/Shtcut/shtcut/commit/${commit.sha}))\n`,
);
}
if (commit.message.startsWith('chore: ')) {
chores.push(
`* ${commit.message.replace('chore: ', '')} ([${commit.sha.substring(
0,
6,
)}](https://github.com/Shtcut/shtcut/commit/${commit.sha}))\n`,
);
}
});
if (features.length) {
newChangeLog += `## Features\n`;
features.forEach(feature => {
newChangeLog += feature;
});
newChangeLog += '\n';
}
if (chores.length) {
newChangeLog += `## Chores\n`;
chores.forEach(chore => {
newChangeLog += chore;
});
newChangeLog += '\n';
}
fs.writeFileSync("./CHANGELOG.md", `${newChangeLog}${currentChangeLog}`);