Skip to content

Commit 136c511

Browse files
committed
[added] "defaultDryRun": "false" option
for those who need the `release-script` to run commands by default without `--run`
1 parent 8c93107 commit 136c511

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ It prevents `danger` steps (`git push`, `npm publish` etc) from accidental runni
1111

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

14+
*If you don't want this behavior you can add `"defaultDryRun": "false"` into your `package.json`.*
15+
```json
16+
"release-script": {
17+
"defaultDryRun": "false"
18+
}
19+
```
20+
*Then you can use `--dry-run` option for checks.*
21+
1422
---
1523

1624
#### Description
@@ -30,7 +38,7 @@ then name the `bower` github repo as
3038
`original-project-name-bower`.
3139

3240
Add `'release-script'.bowerRepo` into your `package.json`:
33-
```js
41+
```json
3442
"release-script": {
3543
"bowerRepo": "[email protected]:<author>/original-project-name-bower.git"
3644
}
@@ -59,7 +67,7 @@ Just create additional github repo for your static documents site.
5967
E.g. [react-bootstrap.github.io.git](https://github.com/react-bootstrap/react-bootstrap.github.io)
6068

6169
Add it as `'release-script'.docsRepo` into your `package.json`:
62-
```js
70+
```json
6371
"release-script": {
6472
"docsRepo": "[email protected]:<author>/original-project-name-github.io.git"
6573
}
@@ -71,7 +79,7 @@ Default folders for documents are:
7179
It is advised to add them both into `.gitignore`.
7280

7381
You can customize them as you need:
74-
```js
82+
```json
7583
"release-script": {
7684
"docsRepo": "[email protected]:<author>/original-project-name-github.io.git"
7785
"docsRoot": "docs-built",
@@ -152,7 +160,7 @@ It is advised to add `bowerRoot` and `tmpBowerRepo` folders to your `.gitignore`
152160
All options are optional.
153161

154162
E.g.:
155-
```js
163+
```json
156164
"release-script": {
157165
"bowerRepo": "[email protected]:<org-author-name>/<name-of-project>-bower.git",
158166
"bowerRoot": "amd",
@@ -220,7 +228,7 @@ If command line `--only-docs` option is set, then `github`, `npm` and `bower` pu
220228
```
221229

222230
If you need `bower` releases too, then add `'release-script'.bowerRepo` into your `package.json` like this:
223-
```js
231+
```json
224232
"release-script": {
225233
"bowerRepo": "[email protected]:<org-author-name>/<name-of-project>-bower.git"
226234
}
@@ -247,7 +255,7 @@ Or you just can install `release-script` globally.
247255
You also can add some helpful `script` commands to your `package.json`,
248256
and because `npm` adds `node_modules/.bin` into `PATH` for running scripts automatically,
249257
you can add them just like that:
250-
```js
258+
```json
251259
"scripts": {
252260
...
253261
"patch": "release patch --run",
@@ -257,7 +265,7 @@ you can add them just like that:
257265
```
258266

259267
Also you can add it like this:
260-
```js
268+
```json
261269
"scripts": {
262270
...
263271
"release": "release",

src/release.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ const altPkgRootFolder = configOptions.altPkgRootFolder;
4949

5050
const skipBuildStep = configOptions.skipBuildStep;
5151

52+
const defaultDryRun = configOptions.defaultDryRun !== 'false';
53+
5254
//------------------------------------------------------------------------------
5355
// command line options
5456
const yargsConf = yargs
@@ -84,6 +86,12 @@ const yargsConf = yargs
8486
default: false,
8587
describe: 'Actually execute command.'
8688
})
89+
.option('dry-run', {
90+
alias: 'n',
91+
demand: false,
92+
default: false,
93+
describe: 'With "defaultDryRun" option set this toggles "dry run" mode.'
94+
})
8795
.option('verbose', {
8896
demand: false,
8997
default: false,
@@ -97,10 +105,15 @@ const yargsConf = yargs
97105

98106
const argv = yargsConf.argv;
99107

100-
if (!argv.run) {
108+
let dryRunMode = argv.dryRun || defaultDryRun;
109+
if (argv.run) {
110+
dryRunMode = false;
111+
}
112+
if (dryRunMode) {
101113
console.log('DRY RUN'.magenta);
102-
console.log('For actual running of your command please add "--run" option'.yellow);
114+
if (defaultDryRun) console.log('For actual running of your command please add "--run" option'.yellow);
103115
}
116+
104117
if (argv.onlyDocs) console.log('Publish only documents'.magenta);
105118

106119
config.silent = !argv.verbose;
@@ -134,15 +147,15 @@ function run(command) {
134147
}
135148

136149
function safeRun(command) {
137-
if (!argv.run) {
150+
if (dryRunMode) {
138151
console.log(`[${command}]`.grey, 'DRY RUN'.magenta);
139152
} else {
140153
return run(command);
141154
}
142155
}
143156

144157
function safeRm(...args) {
145-
if (!argv.run) console.log(`[rm ${args.join(' ')}]`.grey, 'DRY RUN'.magenta);
158+
if (dryRunMode) console.log(`[rm ${args.join(' ')}]`.grey, 'DRY RUN'.magenta);
146159
else rm(args);
147160
}
148161

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

307-
if (!argv.run) {
320+
if (dryRunMode) {
308321
console.log(`[publishing to GitHub]`.grey, 'DRY RUN'.magenta);
309322
} else {
310323
const [githubOwner, githubRepo] = getOwnerAndRepo(npmjson.repository.url || npmjson.repository);

0 commit comments

Comments
 (0)