Skip to content

Commit 57b2159

Browse files
committed
[changed] Now 'dry run' is default mode. To prevent accidental mistakes.
1 parent 9327ac3 commit 57b2159

File tree

2 files changed

+48
-38
lines changed

2 files changed

+48
-38
lines changed

README.md

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,19 @@
22

33
Release tool for npm and bower packages.
44

5+
6+
---
7+
##### Human factor
8+
9+
**Because of human nature to make mistakes, by default this script runs in `dry mode`.
10+
It prevents `danger` steps (`git push`, `npm publish` etc) from accidental running.**
11+
12+
**For actual running your command please add `--run` option.**
13+
14+
---
15+
16+
#### Description
17+
518
With this tool there is no need to keep (transpiled) `lib`, `build`
619
or `distr` files in the git repo.
720

@@ -69,7 +82,7 @@ You can customize them as you need:
6982
If you need to publish only documents (say with some minor fixes),
7083
this is as simple as:
7184
```
72-
> release --only-docs
85+
> release --only-docs --run
7386
```
7487
In this case the `package.json` version will be bumped with `--preid docs` as `0.10.0` => `0.10.0-docs.0`.
7588

@@ -82,14 +95,14 @@ with the `canary` npm tag name (instead of default one `latest`).
8295

8396
You can do it by this way:
8497
```
85-
> release 0.25.100 --preid pre --tag canary
98+
> release 0.25.100 --preid pre --tag canary --run
8699
or
87-
> npm run release 0.25.100 -- --preid pre --tag canary
100+
> npm run release 0.25.100 -- --preid pre --tag canary --run
88101
```
89102

90103
If your `preid` tag and npm tag name are the same, then you can just:
91104
```
92-
> release 0.25.100 --preid beta
105+
> release 0.25.100 --preid beta --run
93106
```
94107
It will produce `v0.25.100-beta.0` and `npm publish --tag beta`.
95108

@@ -162,7 +175,7 @@ export GITHUB_TOKEN="xxxxxxxxxxxx"
162175
```
163176
You can set a custom message for release via `--notes` CLI option:
164177
```
165-
> release patch --notes "This is small fix"
178+
> release patch --notes "This is small fix" --run
166179
```
167180

168181

@@ -215,15 +228,9 @@ If you need `bower` releases too, then add `'release-script'.bowerRepo` into you
215228

216229
Then you can release like that:
217230
```sh
218-
> release patch
219-
> release minor --preid alpha
220-
```
221-
222-
You can use `--dry-run` option to check first what will be done and if it is OK.
223-
```sh
224-
> release major --dry-run --verbose
231+
> release patch --run
232+
> release minor --preid alpha --run
225233
```
226-
This option prevents `danger` steps from running. (`git push`, `npm publish` etc)
227234

228235
If you don't have smth like that in your shell:
229236
```sh
@@ -232,7 +239,7 @@ export PATH="./node_modules/.bin:$PATH"
232239
```
233240
then you have to type the commands like this:
234241
```sh
235-
> ./node_modules/.bin/release minor --preid alpha
242+
> ./node_modules/.bin/release minor --preid alpha --run
236243
```
237244

238245
Or you just can install `release-script` globally.
@@ -243,9 +250,10 @@ you can add them just like that:
243250
```js
244251
"scripts": {
245252
...
246-
"patch": "release patch",
247-
"minor": "release minor",
248-
"major": "release major"
253+
"patch": "release patch --run",
254+
"minor": "release minor --run",
255+
"major": "release major --run",
256+
"release-dry-run": "release patch"
249257
```
250258
251259
Also you can add it like this:
@@ -256,9 +264,9 @@ Also you can add it like this:
256264
```
257265
And then you can run it like that:
258266
```
259-
> npm run release minor -- --preid alpha
260-
> npm run release patch -- --notes "This is small fix"
261-
> npm run release major -- --dry-run
267+
> npm run release minor -- --preid alpha --run
268+
> npm run release patch -- --notes "This is small fix --run"
269+
> npm run release major // for dry run
262270
etc
263271
```
264272
_Notice: you have to add additional `--` before any `--option`. That way additional options will get straight to `release-script`._

src/release.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -52,17 +52,17 @@ const skipBuildStep = configOptions.skipBuildStep;
5252
//------------------------------------------------------------------------------
5353
// command line options
5454
const yargsConf = yargs
55-
.usage('Usage: $0 <version> [--preid <identifier>]\nor\nUsage: $0 --only-docs')
56-
.example('$0 minor --preid beta', 'Release with minor version bump with pre-release tag. (npm tag `beta`)')
57-
.example('$0 major', 'Release with major version bump')
58-
.example('$0 major --notes "This is new cool version"', 'Add a custom message to release')
59-
.example('$0 major --dry-run', 'Release dry run with patch version bump')
60-
.example('$0 --preid alpha', 'Release same version with pre-release bump. (npm tag `alpha`)')
61-
.example('$0 0.101.0 --preid rc --tag canary', 'Release `v0.101.0-rc.0` pre-release version with npm tag `canary`')
62-
.command('patch', 'Release patch')
63-
.command('minor', 'Release minor')
64-
.command('major', 'Release major')
65-
.command('<version>', 'Release specific version')
55+
.usage('Usage: $0 <version> --run [--preid <identifier>]\nor\nUsage: $0 --only-docs --run')
56+
.example('$0 minor --preid beta --run', 'Release with minor version bump with pre-release tag. (npm tag `beta`)')
57+
.example('$0 major --run', 'Release with major version bump')
58+
.example('$0 major --notes "This is new cool version" --run', 'Add a custom message to release')
59+
.example('$0 major', 'Without "--run" option it will dry run')
60+
.example('$0 --preid alpha --run', 'Release same version with pre-release bump. (npm tag `alpha`)')
61+
.example('$0 0.101.0 --preid rc --tag canary --run', 'Release `v0.101.0-rc.0` pre-release version with npm tag `canary`')
62+
.command('patch --run', 'Release patch')
63+
.command('minor --run', 'Release minor')
64+
.command('major --run', 'Release major')
65+
.command('<version> --run', 'Release specific version')
6666
.option('preid', {
6767
demand: false,
6868
describe: 'pre-release identifier',
@@ -79,11 +79,10 @@ const yargsConf = yargs
7979
default: false,
8080
describe: 'Publish only documents'
8181
})
82-
.option('dry-run', {
83-
alias: 'n',
82+
.option('run', {
8483
demand: false,
8584
default: false,
86-
describe: 'Execute command in dry run mode.\nWill not commit, tag, push, or publish anything.\nUserful for testing.'
85+
describe: 'Actually execute command.'
8786
})
8887
.option('verbose', {
8988
demand: false,
@@ -98,7 +97,10 @@ const yargsConf = yargs
9897

9998
const argv = yargsConf.argv;
10099

101-
if (argv.dryRun) console.log('DRY RUN'.magenta);
100+
if (!argv.run) {
101+
console.log('DRY RUN'.magenta);
102+
console.log('For actuall running of your command please add "--run" option'.yellow);
103+
}
102104
if (argv.onlyDocs) console.log('Publish only documents'.magenta);
103105

104106
config.silent = !argv.verbose;
@@ -132,15 +134,15 @@ function run(command) {
132134
}
133135

134136
function safeRun(command) {
135-
if (argv.dryRun) {
137+
if (!argv.run) {
136138
console.log(`[${command}]`.grey, 'DRY RUN'.magenta);
137139
} else {
138140
return run(command);
139141
}
140142
}
141143

142144
function safeRm(...args) {
143-
if (argv.dryRun) console.log(`[rm ${args.join(' ')}]`.grey, 'DRY RUN'.magenta);
145+
if (!argv.run) console.log(`[rm ${args.join(' ')}]`.grey, 'DRY RUN'.magenta);
144146
else rm(args);
145147
}
146148

@@ -302,7 +304,7 @@ function release({ type, preid, npmTagName }) {
302304
console.log(`GitHub token found ${githubToken}`.green);
303305
console.log('Publishing to GitHub: '.cyan + vVersion.green);
304306

305-
if (argv.dryRun) {
307+
if (!argv.run) {
306308
console.log(`[publishing to GitHub]`.grey, 'DRY RUN'.magenta);
307309
} else {
308310
const [githubOwner, githubRepo] = getOwnerAndRepo(npmjson.repository.url || npmjson.repository);

0 commit comments

Comments
 (0)