Skip to content

Commit a8aaa5e

Browse files
committed
[added] npm tags for pre-release versions
1 parent 0a986e1 commit a8aaa5e

File tree

2 files changed

+40
-10
lines changed

2 files changed

+40
-10
lines changed

README.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,24 @@ including `bower` publishing, for you - automatically.
3535
_Initial idea is got from `React-Bootstrap` release tools `./tools/release`,
3636
that have been written by [Matt Smith @mtscout6](https://github.com/mtscout6)_
3737

38+
#### Pre-release versions publishing
39+
40+
Say you need to publish pre-release `v0.25.100-pre.0` version
41+
with the `canary` npm tag name (instead of default one `latest`).
42+
43+
You can do it by this way:
44+
```
45+
> release 0.25.100 --preid pre --tag canary
46+
or
47+
> npm run release 0.25.100 -- --preid pre --tag canary
48+
```
49+
50+
If your `preid` tag and npm tag name are the same, then you can just:
51+
```
52+
> release 0.25.100 --preid beta
53+
```
54+
It will produce `v0.25.100-beta.0` and `npm publish --tag beta`.
55+
3856
#### Alternative npm package root folder
3957

4058
Say you want to publish to `npmjs` only the content of your `lib` folder.
@@ -102,9 +120,12 @@ You can set a custom message for release via `--notes` CLI option:
102120
- adds git tag with new version (and changelog message, if used)
103121
- pushes changes to github repo
104122
- if github token is present, publishes release to GitHub, named as `<repo> vx.x.x`
105-
- if `altPkgRootFolder` doesn't set it will just `npm publish` as usual
123+
- if `--preid` tag set, then `npm publish --tag` command for npm publishing is used
124+
- through `--tag` one can set `npm tag name` for the pre-release version (e.g. `alpha` or `canary`)
125+
- othewise `--preid` value will be used
126+
- if `altPkgRootFolder` doesn't set it will just `npm publish [--tag]` as usual
106127
- otherwise if `altPkgRootFolder` set then this script
107-
- will `npm publish` from the `altPkgRootFolder` folder
128+
- will `npm publish [--tag]` from the `altPkgRootFolder` folder
108129
- with the custom version of `package.json` with removed `scripts` and `devDependencies`
109130
- also it will remove the `altPkgRootFolder` part from the `main` file path
110131
- if `bowerRepo` field is present in the `package.json`, then it releases bower package:

src/release.js

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,12 @@ const altPkgRootFolder = configOptions.altPkgRootFolder;
4747
// command line options
4848
const yargsConf = yargs
4949
.usage('Usage: $0 <version> [--preid <identifier>]')
50-
.example('$0 minor --preid beta', 'Release with minor version bump with pre-release tag')
50+
.example('$0 minor --preid beta', 'Release with minor version bump with pre-release tag. (npm tag `beta`)')
5151
.example('$0 major', 'Release with major version bump')
5252
.example('$0 major --notes "This is new cool version"', 'Add a custom message to release')
5353
.example('$0 major --dry-run', 'Release dry run with patch version bump')
54-
.example('$0 --preid beta', 'Release same version with pre-release bump')
54+
.example('$0 --preid alpha', 'Release same version with pre-release bump. (npm tag `alpha`)')
55+
.example('$0 0.101.0 --preid rc --tag canary', 'Release `v0.101.0-rc.0` pre-release version with npm tag `canary`')
5556
.command('patch', 'Release patch')
5657
.command('minor', 'Release minor')
5758
.command('major', 'Release major')
@@ -61,11 +62,16 @@ const yargsConf = yargs
6162
describe: 'pre-release identifier',
6263
type: 'string'
6364
})
65+
.option('tag', {
66+
demand: false,
67+
describe: 'Npm tag name for the pre-release version.\nIf it is not provided, then `preid` value is used',
68+
type: 'string'
69+
})
6470
.option('dry-run', {
6571
alias: 'n',
6672
demand: false,
6773
default: false,
68-
describe: 'Execute command in dry run mode. Will not commit, tag, push, or publish anything. Userful for testing.'
74+
describe: 'Execute command in dry run mode.\nWill not commit, tag, push, or publish anything.\nUserful for testing.'
6975
})
7076
.option('verbose', {
7177
demand: false,
@@ -75,7 +81,7 @@ const yargsConf = yargs
7581
.option('notes', {
7682
demand: false,
7783
default: false,
78-
describe: 'A custom message for release. Overrides [rf|mt]changelog message'
84+
describe: 'A custom message for release.\nOverrides [rf|mt]changelog message'
7985
});
8086

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

8793
const versionBumpOptions = {
8894
type: argv._[0],
89-
preid: argv.preid
95+
preid: argv.preid,
96+
npmTagName: argv.tag || argv.preid
9097
};
9198

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

136-
function release({ type, preid }) {
143+
function release({ type, preid, npmTagName }) {
137144
if (type === undefined && !preid) printErrorAndExit('Must specify version type or preid');
138145

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

273+
const npmPublishCmd = preid ? `npm publish --tag ${npmTagName}` : 'npm publish';
274+
266275
// publishing just /altPkgRootFolder content
267276
if (altPkgRootFolder) {
268277
// prepare custom `package.json` without `scripts` and `devDependencies`
@@ -276,10 +285,10 @@ function release({ type, preid }) {
276285
`${JSON.stringify(npmjson, null, 2)}\n`.to(path.join(altPkgRootFolder, 'package.json'));
277286

278287
pushd(altPkgRootFolder);
279-
safeRun('npm publish');
288+
safeRun(npmPublishCmd);
280289
popd();
281290
} else {
282-
safeRun('npm publish');
291+
safeRun(npmPublishCmd);
283292
}
284293

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

0 commit comments

Comments
 (0)