Skip to content

Commit

Permalink
chore(*): setup generate-changelog npm task
Browse files Browse the repository at this point in the history
```
npm install --save-dev commander github-url-from-git generate-changelog
```
  • Loading branch information
topheman committed May 22, 2018
1 parent 74d81b2 commit 62fbc3a
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 0 deletions.
57 changes: 57 additions & 0 deletions bin/generate-changelog.js
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);
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,21 @@
"test:precommit": "npm test",
"eject": "react-scripts eject",
"lint": "npx eslint .",
"generate-changelog": "./bin/generate-changelog.js",
"pretty": "npx prettier --write '**/*.{js,jsx,json,css,scss}'",
"precommit": "lint-staged && npm run lint && npm run test:precommit",
"serve": "npx serve --clipless --port 5000 build"
},
"devDependencies": {
"commander": "^2.15.1",
"cross-env": "^5.1.5",
"eslint-config-airbnb": "^16.1.0",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-cypress": "^2.0.1",
"eslint-plugin-prettier": "^2.6.0",
"generate-changelog": "^1.7.1",
"git-rev-sync": "^1.12.0",
"github-url-from-git": "^1.5.0",
"husky": "^0.14.3",
"lint-staged": "^7.1.2",
"moment": "^2.22.1",
Expand Down

0 comments on commit 62fbc3a

Please sign in to comment.