Skip to content

Commit

Permalink
[changed] Now 'dry run' is default mode. To prevent accidental mistakes.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexKVal committed Sep 17, 2015
1 parent 9327ac3 commit 57b2159
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 38 deletions.
48 changes: 28 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

Release tool for npm and bower packages.


---
##### Human factor

**Because of human nature to make mistakes, by default this script runs in `dry mode`.
It prevents `danger` steps (`git push`, `npm publish` etc) from accidental running.**

**For actual running your command please add `--run` option.**

---

#### Description

With this tool there is no need to keep (transpiled) `lib`, `build`
or `distr` files in the git repo.

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

Expand All @@ -82,14 +95,14 @@ 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
> release 0.25.100 --preid pre --tag canary --run
or
> npm run release 0.25.100 -- --preid pre --tag canary
> npm run release 0.25.100 -- --preid pre --tag canary --run
```

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

Expand Down Expand Up @@ -162,7 +175,7 @@ export GITHUB_TOKEN="xxxxxxxxxxxx"
```
You can set a custom message for release via `--notes` CLI option:
```
> release patch --notes "This is small fix"
> release patch --notes "This is small fix" --run
```


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

Then you can release like that:
```sh
> release patch
> release minor --preid alpha
```

You can use `--dry-run` option to check first what will be done and if it is OK.
```sh
> release major --dry-run --verbose
> release patch --run
> release minor --preid alpha --run
```
This option prevents `danger` steps from running. (`git push`, `npm publish` etc)

If you don't have smth like that in your shell:
```sh
Expand All @@ -232,7 +239,7 @@ export PATH="./node_modules/.bin:$PATH"
```
then you have to type the commands like this:
```sh
> ./node_modules/.bin/release minor --preid alpha
> ./node_modules/.bin/release minor --preid alpha --run
```

Or you just can install `release-script` globally.
Expand All @@ -243,9 +250,10 @@ you can add them just like that:
```js
"scripts": {
...
"patch": "release patch",
"minor": "release minor",
"major": "release major"
"patch": "release patch --run",
"minor": "release minor --run",
"major": "release major --run",
"release-dry-run": "release patch"
```
Also you can add it like this:
Expand All @@ -256,9 +264,9 @@ Also you can add it like this:
```
And then you can run it like that:
```
> npm run release minor -- --preid alpha
> npm run release patch -- --notes "This is small fix"
> npm run release major -- --dry-run
> npm run release minor -- --preid alpha --run
> npm run release patch -- --notes "This is small fix --run"
> npm run release major // for dry run
etc
```
_Notice: you have to add additional `--` before any `--option`. That way additional options will get straight to `release-script`._
Expand Down
38 changes: 20 additions & 18 deletions src/release.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,17 @@ const skipBuildStep = configOptions.skipBuildStep;
//------------------------------------------------------------------------------
// command line options
const yargsConf = yargs
.usage('Usage: $0 <version> [--preid <identifier>]\nor\nUsage: $0 --only-docs')
.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 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')
.command('<version>', 'Release specific version')
.usage('Usage: $0 <version> --run [--preid <identifier>]\nor\nUsage: $0 --only-docs --run')
.example('$0 minor --preid beta --run', 'Release with minor version bump with pre-release tag. (npm tag `beta`)')
.example('$0 major --run', 'Release with major version bump')
.example('$0 major --notes "This is new cool version" --run', 'Add a custom message to release')
.example('$0 major', 'Without "--run" option it will dry run')
.example('$0 --preid alpha --run', 'Release same version with pre-release bump. (npm tag `alpha`)')
.example('$0 0.101.0 --preid rc --tag canary --run', 'Release `v0.101.0-rc.0` pre-release version with npm tag `canary`')
.command('patch --run', 'Release patch')
.command('minor --run', 'Release minor')
.command('major --run', 'Release major')
.command('<version> --run', 'Release specific version')
.option('preid', {
demand: false,
describe: 'pre-release identifier',
Expand All @@ -79,11 +79,10 @@ const yargsConf = yargs
default: false,
describe: 'Publish only documents'
})
.option('dry-run', {
alias: 'n',
.option('run', {
demand: false,
default: false,
describe: 'Execute command in dry run mode.\nWill not commit, tag, push, or publish anything.\nUserful for testing.'
describe: 'Actually execute command.'
})
.option('verbose', {
demand: false,
Expand All @@ -98,7 +97,10 @@ const yargsConf = yargs

const argv = yargsConf.argv;

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

config.silent = !argv.verbose;
Expand Down Expand Up @@ -132,15 +134,15 @@ function run(command) {
}

function safeRun(command) {
if (argv.dryRun) {
if (!argv.run) {
console.log(`[${command}]`.grey, 'DRY RUN'.magenta);
} else {
return run(command);
}
}

function safeRm(...args) {
if (argv.dryRun) console.log(`[rm ${args.join(' ')}]`.grey, 'DRY RUN'.magenta);
if (!argv.run) console.log(`[rm ${args.join(' ')}]`.grey, 'DRY RUN'.magenta);
else rm(args);
}

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

if (argv.dryRun) {
if (!argv.run) {
console.log(`[publishing to GitHub]`.grey, 'DRY RUN'.magenta);
} else {
const [githubOwner, githubRepo] = getOwnerAndRepo(npmjson.repository.url || npmjson.repository);
Expand Down

0 comments on commit 57b2159

Please sign in to comment.