diff --git a/CHANGELOG.md b/CHANGELOG.md index ddecda7..00a2ffb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Added +- Fix [#2](https://github.com/compulim/version-from-git/issues/2). Supports customizing pre-release thru `--template`, in [PR #3](https://github.com/compulim/version-from-git/pulls/3) + ## [1.0.0] - 2018-05-18 ### Added - Initial commit diff --git a/README.md b/README.md index ba4cdca..1e418b3 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,13 @@ We want to use `npm version` to bump to a customized version that contains both Git branch and commit hash. -And use Travis CI to automatically publish the prerelease version to NPM, tagged using [`npm dist-tag`](https://docs.npmjs.com/cli/dist-tag). +And use Travis CI to automatically publish the pre-release version to NPM, tagged using [`npm dist-tag`](https://docs.npmjs.com/cli/dist-tag). -> Instead of using plus (+) to denote build information, we prefer period (.) for simpler escapes. +> Instead of using plus (+) to denote build information, we prefer period (.) for simpler escapes. If you prefer the plus sign, you can [customize the pre-release version pattern](#customizing-pre-release-version-pattern). # How to use -Run `npx version-from-git`, it will run `npm version 1.0.0-master+1a2b3c4`. +Run `npx version-from-git`, it will run `npm version 1.0.0-master.1a2b3c4`. ``` Usage: version-from-git [options] @@ -39,6 +39,18 @@ In Travis, when you push a tag (probably by `npm version 1.0.0` followed by `git Run `npx version-from-git -t`, it will detect whether `TRAVIS_TAG` environment variable is present and skip. +## Customizing pre-release version pattern + +You can customize the version pattern when tagging for pre-release versions. + +| Pattern name | Description | Sample | +|--------------|------------------------------------------------------------------|--------------------------------------------| +| `branch` | Branch name
In Travis, will use `process.env.TRAVIS_BRANCH` | `master` | +| `long` | Git commit in long form | `3807f9004867438c57a3e26f2073c33c458d4ef9` | +| `short` | Git commit in short form | `3807f90` | + +Default pattern is `branch.short`, which would produce `master.1a2b3c4`. + # Contributions Like us? [Star](https://github.com/compulim/version-from-git/stargazers) us. diff --git a/package.json b/package.json index 56ccbee..29e885e 100644 --- a/package.json +++ b/package.json @@ -24,8 +24,10 @@ "keywords": [ "branch", "bump", + "ci", "commit", "git", + "travis", "version" ], "license": "MIT", diff --git a/src/index.js b/src/index.js index 5c8fdb4..cb80c0b 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,6 @@ #!/usr/bin/env node -const { branch: gitBranch, short: gitShort } = require('git-rev-sync'); +const { branch: gitBranch, short: gitShort, long: gitLong } = require('git-rev-sync'); const { join, resolve } = require('path'); const { major, minor, patch } = require('semver'); const { green, magenta, red, yellow } = require('chalk'); @@ -11,10 +11,13 @@ const spawn = require('cross-spawn'); const { log } = console; const ourPackageJSON = require(join(__dirname, '../package.json')); +const DEFAULT_TEMPLATE = 'branch.short'; + program .version(ourPackageJSON.version) .description(ourPackageJSON.description) .option('-p, --path ', 'path to package.json, default to current directory', process.cwd()) + .option('--template