feat(commands): add release script customizability (#12)
This commit is contained in:
23
README.md
23
README.md
@@ -39,3 +39,26 @@ You can create an `.rczrc`, `.rczrc.json` or `rcz.config.json` file in your root
|
||||
"autoSignReleases": true
|
||||
}
|
||||
```
|
||||
|
||||
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
|
||||
const fs = require("fs"); // Require fileSystem
|
||||
|
||||
const packageFile = fs.readFileSync("./package.json").toString(); // Get package.json contents from the current working directory
|
||||
const newPackageFile = packageFile.replace(
|
||||
/"version": "[0-9]+.[0-9]+.[0-9]+"/,
|
||||
`"version": "${__NEW_VERSION__}"`
|
||||
); // Use RegExp to replace package.json version
|
||||
|
||||
fs.writeFileSync("./package.json", newPackageFile); // Write to package.json file its new content
|
||||
|
||||
const indexFile = fs.readFileSync("./src/index.ts").toString(); // Get index.ts file from source code directory
|
||||
const newIndexFile = indexFile.replace(/version\("[0-9]+\.[0-9]+\.[0-9]+"\)/); // Replace class function call content with the new version
|
||||
|
||||
fs.writeFileSync("./src/index.ts", newIndexFile); // Write to source code index file
|
||||
```
|
||||
|
||||
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.
|
||||
|
||||
Reference in New Issue
Block a user