-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(*): setup generate-changelog npm task
``` npm install --save-dev commander github-url-from-git generate-changelog ```
- Loading branch information
Showing
3 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env node | ||
|
||
/** | ||
* Simple util based on npm package generate-changelog | ||
* | ||
* Usage: ./generate-changelog.js previousTag currentTag | ||
*/ | ||
|
||
const program = require("commander"); | ||
const packageJson = require("../package.json"); | ||
const githubUrlFromGit = require("github-url-from-git"); | ||
const generateChangelog = require("generate-changelog"); | ||
const { exec } = require("child_process"); | ||
|
||
const githubRepoUrl = | ||
(packageJson.repository && | ||
packageJson.repository.url && | ||
githubUrlFromGit(packageJson.repository.url)) || | ||
undefined; | ||
|
||
/** | ||
* generate-changelog always takes the latest tag as title / date | ||
* this patches this little bug and retrieves the exact date of the targetted tag | ||
*/ | ||
const retrieveGitTagDate = tag => | ||
new Promise((res, rej) => { | ||
exec(`git show -s --format=%ci ${tag}^{commit}`, (error, stdout) => { | ||
if (error) { | ||
return rej(error); | ||
} | ||
return res(stdout); | ||
}); | ||
}); | ||
|
||
program | ||
.usage("<previousTag> <currentTag>") | ||
.command("* <previousTag> <currentTag>") | ||
.action((previousTag, currentTag) => { | ||
const githubDiffLink = `Diff: ${githubRepoUrl}/compare/${previousTag}...${currentTag}`; | ||
|
||
Promise.all([ | ||
generateChangelog.generate({ | ||
tag: `${previousTag}...${currentTag}`, | ||
repoUrl: githubRepoUrl | ||
}), | ||
retrieveGitTagDate(currentTag) | ||
]).then(([changelog, currentTagDate]) => { | ||
console.log( | ||
changelog.replace( | ||
/^(.*)$/m, | ||
`#### ${currentTag} (${currentTagDate.substr(0, 10)})` | ||
) + githubDiffLink | ||
); | ||
}); | ||
}); | ||
|
||
program.parse(process.argv); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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