Skip to content

Commit

Permalink
feat(rn-changelog-generator): Prepend changelogs to the supplied file (
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrieldonadel authored Feb 21, 2022
1 parent 64ce5a1 commit 37b980b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/tasty-birds-give.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rnx-kit/rn-changelog-generator": minor
---

prepend the newly generated changelog to the supplied --changelog file
2 changes: 1 addition & 1 deletion packages/rn-changelog-generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ Generate a changelog for `react-native` commits between versions 0.65.0 and
0.66.0:

```sh
npx rn-changelog-generator --base v0.65.0 --compare v0.66.0 --repo ../../../react-native --changelog ../../../react-native/CHANGELOG.md > NEW_CHANGES.md
npx @rnx-kit/rn-changelog-generator --base v0.65.0 --compare v0.66.0 --repo ../../../react-native --changelog ../../../react-native/CHANGELOG.md
```

As explained above, you will need to have a local clone of `react-native`, which
Expand Down
22 changes: 20 additions & 2 deletions packages/rn-changelog-generator/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,8 +514,26 @@ function handler(argv: GenerateArgs) {
.then(async () => {
const existingChangelogData = fs.readFileSync(argv.changelog, "utf-8");
const base = await getOffsetBaseCommit(gitDir, argv.base, argv.compare);
const data = await run({ ...argv, base, gitDir, existingChangelogData });
return console.log(data);
const newChangeLogData = await run({
...argv,
base,
gitDir,
existingChangelogData,
});

const changelogHeader = "# Changelog";
fs.writeFileSync(argv.changelog, changelogHeader, {
encoding: "utf8",
flag: "w",
});
fs.appendFileSync(argv.changelog, newChangeLogData);
fs.appendFileSync(
argv.changelog,
existingChangelogData.substring(
existingChangelogData.indexOf(changelogHeader) +
changelogHeader.length
)
);
})
.catch((e) => {
console.error(e);
Expand Down

0 comments on commit 37b980b

Please sign in to comment.