tagy
Version:
Create a new git tag by following the 'Semantic Versioning' and push it on remote.
156 lines (123 loc) • 6.21 kB
Markdown
An easy way to create Git releases using git tags.
Create a new git tag by following the 'Semantic Versioning' and push it on remote.
> Note: This will also bump the version in `package.json` before pushing it on remote origin.
[](https://nodei.co/npm/tagy/)
```
npm i tagy -g
```
```
tagy [-p, -m, --minor, --patch, --major, --reverse, --info, --custom, -h]
```
```sh
-p, --patch
-m, --minor
--major
--reverse
--info
--custom
--soft
--auto-release
-h
```
_All parameters are optional._
```
"tagy": {
"tagPrefix": "v",
"soft": true,
"auto-release": true,
"replace": [
{
"files": "themes/custom/style.css",
"from": "Version: \\d+\\.\\d+\\.\\d+",
"to": "Version: __VERSION__",
"flags": "g"
}
]
}
```
Description of the above parameters:
* `tagPrefix` - (optional) Allows to create releases with a prefix. For example, if you want to create a release with a prefix `v` and the version is `1.0.0`, the tag will be `v1.0.0`. The tag in git will be `v1.0.0`.
* `soft` - (optional) Allows to create a new version which will update only the `package.json` and follow any rules in `tagy.js` file or `package.json`, but will not commit the changes to git or create a new git tag. So basically, it will do only a search and replace in files without affecting the git tags.
* `auto-release` - (optional) Allows to create a Github release directly from terminal after the tag is created (automatically, without confirmation).
* `replace` - (optional) Allows to define custom replacement rules in `package.json` file. For example, if you want to replace the version in a file named `style.css` with the version from `package.json`, add the following in `package.json`:
* `files` - (required) The file or files where the replacement will be done. This can be a string or an array of strings. Relative to `package.json` file!
* `from` - (required) The string or regex to search for. If you define a regex, make sure to escape the special characters and double escape the backslash.
* `to` - (required) The string to replace the matched string or regex of `from`. You can use the `__VERSION__` placeholder to use the new version from `package.json`.
* `flags` - (optional) The flags to use for the regex. Default is `g`.
#### The above `from` and `to` parameters accept 2 types of variables:
* `__VERSION__` - This will be replaced with the new version from `package.json`.
* `__CURRENT_TAG__` - This will be replaced with the current tag from git.
## Extend it:
#### Custom scripts before `git push` is executed.
Create a file in your project directory named `tagy.js` and inside export a module function with some logic. This function will be executed just before the `git push` command is called.
Doing so you have the option to manipulate the files before they are released.
For example:
```js
module.exports = (newVersion, oldVersion, args) => {
console.log('Custom "tagy" scripts can be used before git push');
}
```
A real example, replacing the version in a css file.
```
const path = require('path');
const replace = require('replace-in-file');
module.exports = (newVersion, oldVersion, args) => {
replace.sync({
files: path.resolve(__dirname, 'src/style.css'),
from: /Version: \d+\.\d+\.\d+/g,
to: `Version: ${newVersion}`,
});
}
```
A soft tag will allow to create a new version which will update only the `package.json` and follow any rules in `tagy.js` file,
but will not commit the changes to git or create a new git tag.
So basically, it will do only a search and replace in files without affecting the git tags.
To enable this, add the following in `package.json`:
```
"tagy": {
"method": "soft"
}
```
This allows to create releases with a prefix.
For example, if you want to create a release with a prefix `v` and the version is `1.0.0`, the tag will be `v1.0.0`.
To enable this, add the following in `package.json`:
```
"tagy": {
"tagPrefix": "v"
}
```
This allows to define custom replacement rules in `package.json` file.
For example, if you want to replace the version in a file named `style.css` with the version from `package.json`, add the following in `package.json`:
```
"tagy": {
"replace": [
{
"files": "themes/custom/style.css",
"from": "Version: \\d+\\.\\d+\\.\\d+",
"to": "Version: __VERSION__",
"flags": "g"
}
]
}
```
In the above example we replace the version from style.css with the new version from `package.json` file.
**This is an array of objects, so you can define multiple replacements.**
* Added `--soft` argument to create a soft tag directly from terminal.
* Deprecated `{"method": "soft"}` in `package.json` file. Use `{"soft": true}` instead.
* Added Github release prompt. This will allow to create a Github release directly from terminal after the tag is created.
* Added `--auto-release` argument to create a Github release directly from terminal after the tag is created (automatically, without confirmation).
* Added `auto-release` option in `package.json` file. This will allow to create a Github release directly from terminal after the tag is created (automatically, without confirmation).