Skip to content

Commit

Permalink
Added support for release pre
Browse files Browse the repository at this point in the history
  • Loading branch information
leo committed Nov 27, 2017
1 parent a903792 commit 1225ccb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
10 changes: 6 additions & 4 deletions bin/release.js
Expand Up @@ -351,24 +351,26 @@ const checkReleaseStatus = async () => {
}

const bumpType = args.sub
const argAmount = bumpType.length

if (bumpType.length === 1) {
const allowedTypes = []
if (argAmount === 1 || (bumpType[0] === 'pre' && argAmount === 2)) {
const allowedTypes = ['pre']

for (const type of changeTypes) {
allowedTypes.push(type.handle)
}

const allowed = allowedTypes.includes(bumpType[0])
const type = bumpType[0]

if (!allowed) {
handleSpinner.fail(
'Version type not SemVer-compatible (major, minor or patch)!'
'Version type not SemVer-compatible ("major", "minor", "patch" or "pre")'
)
process.exit(1)
}

bumpVersion(bumpType[0])
bumpVersion(type, bumpType[1])
} else {
checkReleaseStatus()
}
11 changes: 9 additions & 2 deletions lib/bump.js
Expand Up @@ -32,7 +32,7 @@ const fail = message => {
handleSpinner.fail(message)
}

module.exports = async type => {
module.exports = async (type, preSuffix) => {
if (isTTY) {
handleSpinner.create('Bumping version tag')
}
Expand All @@ -55,7 +55,14 @@ module.exports = async type => {
fail(`No "version" field inside "package.json".`)
}

const newVersion = semver.inc(pkgContent.version, type)
let newVersion

if (type === 'pre' && preSuffix) {
newVersion = semver.inc(pkgContent.version, type, preSuffix)
} else {
newVersion = semver.inc(pkgContent.version, type)
}

pkgContent.version = newVersion

try {
Expand Down
17 changes: 17 additions & 0 deletions readme.md
Expand Up @@ -30,6 +30,23 @@ To bump the version inside `package.json` or `package-lock.json`, run this comma
release <major|minor|patch>
```

### Pre-Releases

Assuming that you want to increment a pre-release tag like `3.0.0-canary.1`, you can do it like this:

```bash
release pre
```

For the example tag mentioned above, the command will result in `3.0.0-canary.2`. However, you can also increment a normal tag like `3.0.0` to a pre-release one like this:

```bash
release pre <suffix>
```

If `<suffix>` is "canary", the example tag `3.0.0` would be incremented to `3.0.0-canary.0`. You can use any
word of your choice in place of `<suffix>`.

### Options

The following command will show you a list of all available options:
Expand Down

0 comments on commit 1225ccb

Please sign in to comment.