From 4c60f62e72dd7c7d795c77b7eabbe7dc4007a952 Mon Sep 17 00:00:00 2001 From: Olivers Vitins Date: Sat, 16 Dec 2023 18:32:29 +0200 Subject: [PATCH] feat(config): add post-release event file --- .rczrc.onrelease.js | 5 +++++ .rczrc.postrelease.js | 7 +++++++ .vscode/settings.json | 1 + README.md | 6 ++++++ src/index.ts | 16 ++++++++++++++++ 5 files changed, 35 insertions(+) create mode 100644 .rczrc.postrelease.js diff --git a/.rczrc.onrelease.js b/.rczrc.onrelease.js index 47105e6..fab3380 100644 --- a/.rczrc.onrelease.js +++ b/.rczrc.onrelease.js @@ -1,4 +1,5 @@ const fs = require("fs"); +const { execSync } = require("child_process"); const packageFile = fs.readFileSync("./package.json").toString(); const newPackageFile = packageFile.replace( @@ -15,3 +16,7 @@ const newIndexFile = indexFile.replace( ); fs.writeFileSync("./src/index.ts", newIndexFile); + +execSync( + `rcz changelog --show-hashes --unreleased-as v${__NEW_VERSION__} > CHANGELOG.md` +); diff --git a/.rczrc.postrelease.js b/.rczrc.postrelease.js new file mode 100644 index 0000000..edb933e --- /dev/null +++ b/.rczrc.postrelease.js @@ -0,0 +1,7 @@ +const { execSync } = require("child_process"); + +execSync(`git push -u origin --tags`); + +execSync(`pnpm run build`); + +execSync(`pnpm publish`); diff --git a/.vscode/settings.json b/.vscode/settings.json index 99e8483..08c5157 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,6 +4,7 @@ "johndoe", "onrelease", "outro", + "postrelease", "rczrc", "Resultium" ] diff --git a/README.md b/README.md index 6932ce8..09a5034 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,8 @@ You can create an `.rczrc`, `.rczrc.json` or `rcz.config.json` file in your root } ``` +### On-release event + You are also able to create an onRelease event file, that is going to run before creation of a git tag and a release commit, when `rcz release` is run. The file is to be named `.rczrc.onrelease.js`. A sample can be seen below. ```js @@ -62,3 +64,7 @@ fs.writeFileSync("./src/index.ts", newIndexFile); // Write to source code index In your onRelease file you are provided with `__NEW_VERSION__` constant string which is the new version submitted in `rcz release` and `__IS_SIGNED__` constant which is a boolean telling whether the release (it's commit and tag) is going to be signed. Bear in mind, **this script is going to be executed through `eval()` with no sanitation**, be careful with whatever you write. + +### Post-release event + +Same as for onRelease you can also create a postRelease file which gets run after the tag and commit get created. Same as for onRelease file you are provided with `__NEW_VERSION__` and `__IS_SIGNED__` diff --git a/src/index.ts b/src/index.ts index dfc17a6..b7d06c5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -473,6 +473,22 @@ program ? [`-s`, `v${version}`, `-m`, `"v${version}"`] : [`-a`, `v${version}`, `-m`, `"v${version}"`] ); + + const postReleaseFile = ( + await fs.promises.readFile( + path.join(process.cwd(), ".rczrc.postrelease.js") + ) + ).toString(); + + if (postReleaseFile) { + const postReleaseScript = ` + const __NEW_VERSION__ = "${version}"; + const __IS_SIGNED__ = ${sign}; + + ${postReleaseFile}`; + + eval(postReleaseScript); + } }); program