|
1 | 1 | # git-prefix-tag |
| 2 | + |
2 | 3 | get git tags with prefix |
| 4 | + |
| 5 | +## Install |
| 6 | + |
| 7 | +```sh |
| 8 | +$ npm install git-prefix-tag --save-dev |
| 9 | +``` |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +Assume you have tags like below |
| 14 | + |
| 15 | +>4de0361ae9c51f51fb6d3a50addfff6ca2d64a99 refs/tags/dev-v0.0.1 |
| 16 | +>9ec697394a8def124f5b7c85e27a991adbff2c86 refs/tags/dev-v0.1.1 |
| 17 | +>3dbfd9dbce2f48c68051d025e037b54bc17b015a refs/tags/dev-v0.1.2 |
| 18 | +>5409b3f8b96087d73973efdacc0a290b873612e3 refs/tags/dev-v0.1.3 |
| 19 | +>364a61ea754e8150e3bf460bc37709732260a851 refs/tags/prod-v0.1.0 |
| 20 | +>a0ebc1571e2c69725877191d688c815701a49e78 refs/tags/prod-v0.1.1 |
| 21 | +>a0ebc1571e2c69725877191d688c815701a49e78 refs/tags/sth-werid |
| 22 | +>d5b47d82ecd19b5c19fe2bd28294ad887968a5aa refs/tags/prod-v0.1.2 |
| 23 | +>10817d87a8182d2a72b174ffb70b879555a2b73c refs/tags/prod-v0.1.3-alpha |
| 24 | +>45a75e99ea1a6c333eadf81bdbfac164f6613955 refs/tags/prod-v0.1.4-beta |
| 25 | +>702139d72160a729854e3adbc62a2955f87e212b refs/tags/prod-v0.1.5 |
| 26 | +>984e86d46ef724d4d06026740624cce5ecdb59fd refs/tags/prod-v0.1.6-beta |
| 27 | +
|
| 28 | +You can use `git-prefix-tag` to fetch the tag you want. |
| 29 | + |
| 30 | +### getLatest |
| 31 | + |
| 32 | +This function definition is below. |
| 33 | + |
| 34 | +```typescript |
| 35 | +function getLatest(prefix: string | regExp | Function, options: { |
| 36 | + semver: boolean = false, |
| 37 | + wholeVersion: boolean = false, |
| 38 | + withPrefix: boolean = false, |
| 39 | + all: boolean = false, |
| 40 | +}): string | semver {} |
| 41 | +``` |
| 42 | + |
| 43 | +You can use getLatest to get the latest version. |
| 44 | + |
| 45 | +```javascript |
| 46 | +const helper = require('git-prefix-tag'); |
| 47 | +console.log(helper.getLatest('dev-v')); // 0.1.3 |
| 48 | +``` |
| 49 | + |
| 50 | +#### Options |
| 51 | + |
| 52 | +There are several options here. |
| 53 | + |
| 54 | +**withPrefix** |
| 55 | + |
| 56 | +You can add withPrefix option to get the whole tag |
| 57 | + |
| 58 | +```javascript |
| 59 | +const helper = require('git-prefix-tag'); |
| 60 | +console.log(helper.getLatest('dev-v', { withPrefix: true })); // dev-v0.1.3 |
| 61 | +``` |
| 62 | + |
| 63 | +**semver** |
| 64 | + |
| 65 | +You can get a semver object. |
| 66 | + |
| 67 | +```javascript |
| 68 | +const helper = require('git-prefix-tag'); |
| 69 | +console.log(helper.getLatest('dev-v', { semver: true })); |
| 70 | +/* |
| 71 | +{ |
| 72 | + "semver": { |
| 73 | + "raw": "0.1.3", |
| 74 | + "major": 0, |
| 75 | + "minor": 1, |
| 76 | + "patch": 3, |
| 77 | + "prerelease": [], |
| 78 | + "build": [], |
| 79 | + "version": "0.1.3" |
| 80 | + }, |
| 81 | + "wholeVersion": "0.1.3", |
| 82 | + "prefix": "dev-v", |
| 83 | + "tag": "dev-v0.1.3", |
| 84 | + "version": "0.1.3" |
| 85 | +} |
| 86 | +*/ |
| 87 | +``` |
| 88 | + |
| 89 | +#### Input |
| 90 | + |
| 91 | +you can custom your input |
| 92 | + |
| 93 | +**RegExp** |
| 94 | + |
| 95 | +```javascript |
| 96 | +const helper = require('git-prefix-tag'); |
| 97 | +console.log(helper.getLatest(/dev-v/)); // 0.1.3 |
| 98 | +``` |
| 99 | + |
| 100 | +**Function** |
| 101 | + |
| 102 | +```javascript |
| 103 | +const helper = require('git-prefix-tag'); |
| 104 | +console.log(helper.getLatest(() => 'dev-v'))); // 0.1.3 |
| 105 | +``` |
| 106 | + |
| 107 | +### increase |
| 108 | + |
| 109 | +You can get the increace tag based on the latest tag through this function. Its definition is like this. |
| 110 | + |
| 111 | +```javascript |
| 112 | +function increase(prefix: string | regExp | Function, type: 'major' | 'premajor' | 'minor' | 'preminor' | 'patch' | 'prepatch' | 'prerelease' = 'patch'): string {} |
| 113 | +``` |
| 114 | + |
| 115 | +You can use like this. |
| 116 | + |
| 117 | +```javascript |
| 118 | +const helper = require('git-prefix-tag'); |
| 119 | +console.log(helper.increase('dev-v')); // '0.1.4' |
| 120 | +console.log(helper.increase('dev-v', 'minor')); // '0.2.0' |
| 121 | +``` |
0 commit comments