-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·67 lines (58 loc) · 1.64 KB
/
index.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
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/jackyef/changelog-generator/commit/${
commit.sha
}))\n`
);
}
if (commit.message.startsWith("chore: ")) {
chores.push(
`* ${commit.message.replace("chore: ", "")} ([${commit.sha.substring(
0,
6
)}](https://github.com/jackyef/changelog-generator/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';
}
// prepend the newChangelog to the current one
fs.writeFileSync("./CHANGELOG.md", `${newChangelog}${currentChangelog}`);