Created
October 27, 2022 09:57
-
-
Save Ankit1598/bc150f065809eb7e2e0cf5cea4ea1d62 to your computer and use it in GitHub Desktop.
Basic script to generate changelog for commits before conventional commits
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 firstCommit = child | |
.execSync(`git rev-list --max-parents=0 HEAD`) | |
.toString("utf-8").slice(0, -1); | |
const currentVersion = require("./package.json").version; | |
let newChangelog = `# [v${currentVersion}](https://github.com/AnkitC1598/admin/commit/${firstCommit}...${currentVersion}) (${new Date().toISOString().split("T")[0]})\n\n`; | |
const commits = []; | |
commitsArray.forEach(commit => { | |
if (commit.sha === firstCommit) commit.message = '1.0.0' + ` [${commit.message}]` | |
commits.push( | |
`* ${commit.message} ([${commit.sha.substring( | |
0, | |
6 | |
)}](https://github.com/AnkitC1598/admin/commit/${commit.sha | |
}))\n` | |
); | |
} | |
); | |
if (commits.length) { | |
newChangelog += `## Commits\n`; | |
commits.forEach(commit => { | |
newChangelog += commit; | |
}); | |
newChangelog += '\n'; | |
} | |
fs.writeFileSync("./CHANGELOG.md", `${newChangelog}`); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment