feat(config): add post-release event file

This commit is contained in:
2023-12-16 18:32:29 +02:00
parent 357036d029
commit 4c60f62e72
5 changed files with 35 additions and 0 deletions

View File

@@ -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`
);

7
.rczrc.postrelease.js Normal file
View File

@@ -0,0 +1,7 @@
const { execSync } = require("child_process");
execSync(`git push -u origin --tags`);
execSync(`pnpm run build`);
execSync(`pnpm publish`);

View File

@@ -4,6 +4,7 @@
"johndoe",
"onrelease",
"outro",
"postrelease",
"rczrc",
"Resultium"
]

View File

@@ -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__`

View File

@@ -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