Skip to content

Commit b91b2ab

Browse files
committed
new option: --dry-run which gives detailed information about what would happen without doing anything
1 parent 3f40bd1 commit b91b2ab

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,16 @@ The command includes dotfiles by default (e.g `.htaccess` will be committed)
163163
With `--no-dotfiles` files starting with `.` are ignored.
164164

165165

166+
167+
#### <a id="dry-run">--dry-run</a>
168+
* __optional__
169+
* Default: `undefined`
170+
* Example:
171+
* `ngh` -- Normal behaviour: Changes are applied.
172+
* `ngh --dry-run` -- No changes are applied at all.
173+
174+
Run through without making any changes. This can be very usefull, because it outputs what would happend without doing anything.
175+
166176
## Extra
167177

168178
For your convenience, the command will recognize the [environment variable](https://docs.travis-ci.com/user/environment-variables/#Defining-Variables-in-Repository-Settings) `GH_TOKEN` and will replace this pattern in the `--repo` string. Please __do NOT disable the silent mode__ if you have any credentials in the repository URL! Read more about [Github tokens here](https://help.github.com/articles/creating-an-access-token-for-command-line-use/).

bin/angular-cli-ghpages

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ program
1515
.option('-e, --email <email>', 'The git user-email which is associated with this commit')
1616
.option('-S, --no-silent', 'Logging is in silent mode by default. The option enables extended console logging. Keep this untouched if the repository URL or other information passed to git commands is sensitive!')
1717
.option('-T, --no-dotfiles', 'Includes dotfiles by default. When set files starting with `.` are ignored.')
18+
.option('--dry-run', 'For testing: Run through without making any changes.')
1819
.parse(process.argv);
1920

2021
index.run(program)

index.js

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ exports.run = function (options) {
77

88
options = options || {};
99

10-
//console.log('SILENT:', options.silent);
11-
//console.log('DOTFILES:', options.dotfiles);
10+
if (options.dryRun) {
11+
console.log('*** Dry-run: No changes are applied at all. ***')
12+
}
1213

13-
if (options['name'] && options['email']) {
14+
if (options.name && options.email) {
1415
options.user = {
15-
name: options['name'],
16-
email: options['email']
16+
name: options.name,
17+
email: options.email
1718
}
1819
};
1920

@@ -35,7 +36,11 @@ exports.run = function (options) {
3536

3637
// always clean the cache directory.
3738
// avoids "Error: Remote url mismatch."
38-
ghpages.clean();
39+
if (!options.dryRun) {
40+
ghpages.clean();
41+
} else {
42+
console.info('Dry-run / SKIPPED: cleaning of the cache directory');
43+
}
3944

4045
var access = publish = denodeify(fs.access);
4146
var publish = denodeify(ghpages.publish);
@@ -53,7 +58,20 @@ exports.run = function (options) {
5358
return Promise.reject(error);
5459
})
5560
.then(function () {
56-
return publish(dir, options)
61+
if (!options.dryRun) {
62+
return publish(dir, options)
63+
} else {
64+
console.info('Dry-run / SKIPPED: publishing to "' + dir+ '" with the following options:', {
65+
dir: dir,
66+
repo: options.repo || 'undefined: current working directory (which must be a git repo in this case) will be used to commit & push',
67+
message: options.message,
68+
branch: options.branch,
69+
user: options.user || 'undefined: local or gloabl git username & email properties will be taken',
70+
noSilent: options.noSilent || 'undefined: logging is in silent mode by default',
71+
noDotfiles: options.noDotfiles || 'undefined: dotfiles are included by default',
72+
dryRun: options.dryRun
73+
});
74+
}
5775
})
5876
.then(function () {
5977
console.log('Successfully published!\n');

0 commit comments

Comments
 (0)