Skip to content

Commit bb211d4

Browse files
authored
chore(*): setup generate-changelog npm script (#11)
1 parent 47f992a commit bb211d4

File tree

5 files changed

+94
-8
lines changed

5 files changed

+94
-8
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ To have uniform commit messages, I follow the [AngularJS git commit guidelines](
179179

180180
It also makes it easier to generate changelogs.
181181

182+
To generate changelog:
183+
184+
```shell
185+
npm run generate-changelog -- v1.1.0 v1.2.0
186+
```
187+
188+
Ready to be pasted to the github releases part.
189+
182190
## Advanced
183191

184192
### Mock mode

bin/generate-changelog.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/usr/bin/env node
2+
3+
/**
4+
* Simple util based on npm package generate-changelog
5+
*
6+
* Usage: ./generate-changelog.js previousTag currentTag
7+
*/
8+
9+
const program = require("commander");
10+
const packageJson = require("../package.json");
11+
const githubUrlFromGit = require("github-url-from-git");
12+
const generateChangelog = require("generate-changelog");
13+
const { exec } = require("child_process");
14+
15+
const githubRepoUrl =
16+
(packageJson.repository &&
17+
packageJson.repository.url &&
18+
githubUrlFromGit(packageJson.repository.url)) ||
19+
undefined;
20+
21+
/**
22+
* generate-changelog always takes the latest tag as title / date
23+
* this patches this little bug and retrieves the exact date of the targetted tag
24+
*/
25+
const retrieveGitTagDate = tag =>
26+
new Promise((res, rej) => {
27+
exec(`git show -s --format=%ci ${tag}^{commit}`, (error, stdout) => {
28+
if (error) {
29+
return rej(error);
30+
}
31+
return res(stdout);
32+
});
33+
});
34+
35+
program
36+
.usage("<previousTag> <currentTag>")
37+
.command("* <previousTag> <currentTag>")
38+
.action((previousTag, currentTag) => {
39+
const githubDiffLink = `Diff: ${githubRepoUrl}/compare/${previousTag}...${currentTag}`;
40+
41+
Promise.all([
42+
generateChangelog.generate({
43+
tag: `${previousTag}...${currentTag}`,
44+
repoUrl: githubRepoUrl
45+
}),
46+
retrieveGitTagDate(currentTag)
47+
]).then(([changelog, currentTagDate]) => {
48+
console.log(
49+
changelog.replace(
50+
/^(.*)$/m,
51+
`#### ${currentTag} (${currentTagDate.substr(0, 10)})`
52+
) + githubDiffLink
53+
);
54+
});
55+
});
56+
57+
program.parse(process.argv);

cypress/integration/search.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe("Search", () => {
88
cy
99
.getByTestId("search-input")
1010
.type("react")
11-
// can't test for search indicator (only shows up if search-input has focus) - it seams, we loose the focus by getting an other selector ...
11+
// can't test for search indicator (only shows up if search-input has focus) - it seems, we loose the focus by getting an other selector ...
1212
// .getByTestId("search-loading-indicator")
1313
// .should("not.contain", "error")
1414
// wait for the results (and make sure it's correct)

package-lock.json

Lines changed: 23 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@
7878
"pretty": "npx prettier --write '**/*.{js,jsx,json,css,scss}'",
7979
"precommit": "lint-staged && npm run lint && npm run test:precommit",
8080
"proxy-apis-deprecated": "echo 'DEPRECATED' && node ./bin/cors-anywhere.js",
81-
"record-http-mocks": "cross-env REACT_APP_NPM_REGISTRY_API_BASE_URL=https://registry.npmjs.org node ./bin/record-http-mocks.js"
81+
"record-http-mocks": "cross-env REACT_APP_NPM_REGISTRY_API_BASE_URL=https://registry.npmjs.org node ./bin/record-http-mocks.js",
82+
"generate-changelog": "./bin/generate-changelog.js"
8283
},
8384
"lint-staged": {
8485
"**/*.{js,jsx,json,css,scss}": [
@@ -88,6 +89,7 @@
8889
},
8990
"devDependencies": {
9091
"babel-polyfill": "^6.26.0",
92+
"commander": "^2.15.1",
9193
"cors-anywhere": "^0.4.1",
9294
"cross-env": "^5.1.4",
9395
"cypress": "^2.1.0",
@@ -103,8 +105,10 @@
103105
"esm": "^3.0.14",
104106
"express": "^4.16.3",
105107
"fs-extra": "^5.0.0",
108+
"generate-changelog": "^1.7.1",
106109
"gh-pages": "^1.1.0",
107110
"git-rev-sync": "^1.11.1",
111+
"github-url-from-git": "^1.5.0",
108112
"http-proxy-middleware": "^0.18.0",
109113
"husky": "^0.14.3",
110114
"jest-dom": "^1.0.0",

0 commit comments

Comments
 (0)