Skip to content

Commit

Permalink
[added] npm tags for pre-release versions
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKVal committed Sep 15, 2015
1 parent 0a986e1 commit a8aaa5e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
25 changes: 23 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,24 @@ including `bower` publishing, for you - automatically.
_Initial idea is got from `React-Bootstrap` release tools `./tools/release`,
that have been written by [Matt Smith @mtscout6](https://github.com/mtscout6)_

#### Pre-release versions publishing

Say you need to publish pre-release `v0.25.100-pre.0` version
with the `canary` npm tag name (instead of default one `latest`).

You can do it by this way:
```
> release 0.25.100 --preid pre --tag canary
or
> npm run release 0.25.100 -- --preid pre --tag canary
```

If your `preid` tag and npm tag name are the same, then you can just:
```
> release 0.25.100 --preid beta
```
It will produce `v0.25.100-beta.0` and `npm publish --tag beta`.

#### Alternative npm package root folder

Say you want to publish to `npmjs` only the content of your `lib` folder.
Expand Down Expand Up @@ -102,9 +120,12 @@ You can set a custom message for release via `--notes` CLI option:
- adds git tag with new version (and changelog message, if used)
- pushes changes to github repo
- if github token is present, publishes release to GitHub, named as `<repo> vx.x.x`
- if `altPkgRootFolder` doesn't set it will just `npm publish` as usual
- if `--preid` tag set, then `npm publish --tag` command for npm publishing is used
- through `--tag` one can set `npm tag name` for the pre-release version (e.g. `alpha` or `canary`)
- othewise `--preid` value will be used
- if `altPkgRootFolder` doesn't set it will just `npm publish [--tag]` as usual
- otherwise if `altPkgRootFolder` set then this script
- will `npm publish` from the `altPkgRootFolder` folder
- will `npm publish [--tag]` from the `altPkgRootFolder` folder
- with the custom version of `package.json` with removed `scripts` and `devDependencies`
- also it will remove the `altPkgRootFolder` part from the `main` file path
- if `bowerRepo` field is present in the `package.json`, then it releases bower package:
Expand Down
25 changes: 17 additions & 8 deletions src/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ const altPkgRootFolder = configOptions.altPkgRootFolder;
// command line options
const yargsConf = yargs
.usage('Usage: $0 <version> [--preid <identifier>]')
.example('$0 minor --preid beta', 'Release with minor version bump with pre-release tag')
.example('$0 minor --preid beta', 'Release with minor version bump with pre-release tag. (npm tag `beta`)')
.example('$0 major', 'Release with major version bump')
.example('$0 major --notes "This is new cool version"', 'Add a custom message to release')
.example('$0 major --dry-run', 'Release dry run with patch version bump')
.example('$0 --preid beta', 'Release same version with pre-release bump')
.example('$0 --preid alpha', 'Release same version with pre-release bump. (npm tag `alpha`)')
.example('$0 0.101.0 --preid rc --tag canary', 'Release `v0.101.0-rc.0` pre-release version with npm tag `canary`')
.command('patch', 'Release patch')
.command('minor', 'Release minor')
.command('major', 'Release major')
Expand All @@ -61,11 +62,16 @@ const yargsConf = yargs
describe: 'pre-release identifier',
type: 'string'
})
.option('tag', {
demand: false,
describe: 'Npm tag name for the pre-release version.\nIf it is not provided, then `preid` value is used',
type: 'string'
})
.option('dry-run', {
alias: 'n',
demand: false,
default: false,
describe: 'Execute command in dry run mode. Will not commit, tag, push, or publish anything. Userful for testing.'
describe: 'Execute command in dry run mode.\nWill not commit, tag, push, or publish anything.\nUserful for testing.'
})
.option('verbose', {
demand: false,
Expand All @@ -75,7 +81,7 @@ const yargsConf = yargs
.option('notes', {
demand: false,
default: false,
describe: 'A custom message for release. Overrides [rf|mt]changelog message'
describe: 'A custom message for release.\nOverrides [rf|mt]changelog message'
});

const argv = yargsConf.argv;
Expand All @@ -86,7 +92,8 @@ config.silent = !argv.verbose;

const versionBumpOptions = {
type: argv._[0],
preid: argv.preid
preid: argv.preid,
npmTagName: argv.tag || argv.preid
};

if (versionBumpOptions.type === undefined && versionBumpOptions.preid === undefined) {
Expand Down Expand Up @@ -133,7 +140,7 @@ function getOwnerAndRepo(url) {
return (gitUrlBase || url).split('/');
}

function release({ type, preid }) {
function release({ type, preid, npmTagName }) {
if (type === undefined && !preid) printErrorAndExit('Must specify version type or preid');

// ensure git repo has no pending changes
Expand Down Expand Up @@ -263,6 +270,8 @@ function release({ type, preid }) {
} else {
console.log('Releasing: '.cyan + 'npm package'.green);

const npmPublishCmd = preid ? `npm publish --tag ${npmTagName}` : 'npm publish';

// publishing just /altPkgRootFolder content
if (altPkgRootFolder) {
// prepare custom `package.json` without `scripts` and `devDependencies`
Expand All @@ -276,10 +285,10 @@ function release({ type, preid }) {
`${JSON.stringify(npmjson, null, 2)}\n`.to(path.join(altPkgRootFolder, 'package.json'));

pushd(altPkgRootFolder);
safeRun('npm publish');
safeRun(npmPublishCmd);
popd();
} else {
safeRun('npm publish');
safeRun(npmPublishCmd);
}

console.log('Released: '.cyan + 'npm package'.green);
Expand Down

0 comments on commit a8aaa5e

Please sign in to comment.