Skip to content

Commit

Permalink
Added quiet option
Browse files Browse the repository at this point in the history
  • Loading branch information
mrkmg committed Jul 5, 2016
1 parent 3ff6514 commit b4363cc
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 39 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ run `generate-release --help` to see this as well.
-d, --release-file Path to your .release.json file. Default: ./.release.json
-m, --set-release-message Prompt to write a release message. Default: Do no prompt, use "Release {version}"
-o, --remote Change the remote. Default: origin
-q, --quiet Less output. Default: Do show output

**Release File**

Expand Down
77 changes: 39 additions & 38 deletions src/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,20 @@ module.exports = (args) ->

#Setup the observatory
.then ->
Observatory.settings
prefix: '[Generate Release] '

@observatory_tasks =
git_pull: Observatory.add('GIT: Pull from Origin')
git_start: Observatory.add('GIT: Start Release')
write_files: Observatory.add('Files: Write New Version')
pre_commit_commands: Observatory.add('Commands: Pre Commit')
git_commit: Observatory.add('GIT: Commit Files')
post_commit_commands: Observatory.add('Commands: Post Commit')
git_finish: Observatory.add('GIT: Finish Release')
git_push: Observatory.add('GIT: Push to Origin')
post_complete_commands: Observatory.add('Commands: Post Complete')
unless @options.quiet
Observatory.settings
prefix: '[Generate Release] '

@observatory_tasks =
git_pull: Observatory.add('GIT: Pull from Origin')
git_start: Observatory.add('GIT: Start Release')
write_files: Observatory.add('Files: Write New Version')
pre_commit_commands: Observatory.add('Commands: Pre Commit')
git_commit: Observatory.add('GIT: Commit Files')
post_commit_commands: Observatory.add('Commands: Post Commit')
git_finish: Observatory.add('GIT: Finish Release')
git_push: Observatory.add('GIT: Push to Origin')
post_complete_commands: Observatory.add('Commands: Post Complete')

#Setup the Git Commands
.then ->
Expand All @@ -116,101 +117,101 @@ module.exports = (args) ->
#Git Pull
.then ->
unless @options.skip_git_pull
@observatory_tasks.git_pull.status('Pulling')
@observatory_tasks.git_pull.status('Pulling') unless @options.quiet
@git_commands.pull()
@observatory_tasks.git_pull.done('Complete')
@observatory_tasks.git_pull.done('Complete') unless @options.quiet
else
@observatory_tasks.git_pull.done('Skipped')
@observatory_tasks.git_pull.done('Skipped') unless @options.quiet

#Git Start
.then ->
@observatory_tasks.git_start.status('Starting')
@observatory_tasks.git_start.status('Starting') unless @options.quiet
@git_commands.start()
@observatory_tasks.git_start.done('Complete')
@observatory_tasks.git_start.done('Complete') unless @options.quiet

#Write Version Files
.then ->
try
files = globNormalize @options.files_to_version
for file in files
@observatory_tasks.write_files.status(file)
@observatory_tasks.write_files.status(file) unless @options.quiet
replaceVersionInFile file, @options.current_version, @options.next_version
@observatory_tasks.write_files.done('Complete')
@observatory_tasks.write_files.done('Complete') unless @options.quiet
catch err
throw new GitResetError err

#Write package
.then ->
@observatory_tasks.write_files.status('package')
@observatory_tasks.write_files.status('package') unless @options.quiet
@package_file.setVersion @options.next_version
@package_file.save()
@observatory_tasks.write_files.done('Complete')
@observatory_tasks.write_files.done('Complete') unless @options.quiet

#Run pre commit commands
.then ->
try
@observatory_tasks.pre_commit_commands.status('Running')
@observatory_tasks.pre_commit_commands.status('Running') unless @options.quiet
for command in @options.pre_commit_commands
@observatory_tasks.pre_commit_commands.status command
@observatory_tasks.pre_commit_commands.status command unless @options.quiet
runArbitraryCommand command for command in @options.pre_commit_commands
@observatory_tasks.pre_commit_commands.done('Complete')
@observatory_tasks.pre_commit_commands.done('Complete') unless @options.quiet
catch err
throw new GitResetError err

#Commit files
.then ->
try
files = globNormalize @options.package_file_location, @options.files_to_commit, @options.files_to_version
@observatory_tasks.git_commit.status('Committing')
@observatory_tasks.git_commit.status('Committing') unless @options.quiet
@git_commands.commit files
@observatory_tasks.git_commit.done('Complete')
@observatory_tasks.git_commit.done('Complete') unless @options.quiet
catch err
throw new GitResetError err

#Run post commit commands
.then ->
try
@observatory_tasks.post_commit_commands.status('Running')
@observatory_tasks.post_commit_commands.status('Running') unless @options.quiet

for command in @options.post_commit_commands
@observatory_tasks.post_commit_commands.status command
@observatory_tasks.post_commit_commands.status command unless @options.quiet
runArbitraryCommand command

@observatory_tasks.post_commit_commands.done('Complete')
@observatory_tasks.post_commit_commands.done('Complete') unless @options.quiet
catch err
throw new GitResetError err

#Git Finish
.then ->
try
@observatory_tasks.git_finish.status('Finishing')
@observatory_tasks.git_finish.status('Finishing') unless @options.quiet
@git_commands.finish()
@observatory_tasks.git_finish.done('Complete')
@observatory_tasks.git_finish.done('Complete') unless @options.quiet
catch err
throw new GitResetError err

#Git Push
.then ->
unless @options.skip_git_push
@observatory_tasks.git_push.status('Pushing')
@observatory_tasks.git_push.status('Pushing') unless @options.quiet
@git_commands.push()
@observatory_tasks.git_push.done('Complete')
@observatory_tasks.git_push.done('Complete') unless @options.quiet
else
@observatory_tasks.git_push.done('Skipped')
@observatory_tasks.git_push.done('Skipped') unless @options.quiet

#Run post commit commands
.then ->
@observatory_tasks.post_complete_commands.status('Running')
@observatory_tasks.post_complete_commands.status('Running') unless @options.quiet

for command in @options.post_complete_commands
try
@observatory_tasks.post_complete_commands.status command
@observatory_tasks.post_complete_commands.status command unless @options.quiet
runArbitraryCommand command
catch error
#TODO make this better. Currently, the error message may not be seen...
console.error error.message

@observatory_tasks.post_complete_commands.done('Complete')
@observatory_tasks.post_complete_commands.done('Complete') unless @options.quiet

.then ->
process.exit 0
Expand Down
5 changes: 5 additions & 0 deletions src/lib/Options.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ options =
switches: ['h', 'help']
file_key: false
validate: (input) -> typeof input is 'boolean'
quiet:
default: false
switches: ['q', 'quiet']
file_key: false
validate: (input) -> typeof input is 'boolean'
package_file_location:
default: './package.json'
switches: ['p', 'package']
Expand Down
1 change: 1 addition & 0 deletions src/lib/error/HelpError.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class HelpError extends Error
-d, --release-file Path to your .release.json file. Default: ./.release.json
-m, --set-release-message Prompt to write a release message. Default: Release {version}
-o, --remote Change the remote. Default: origin
-q, --quiet Less output. Default: Do show output
#{post or ''}"""

Expand Down
2 changes: 1 addition & 1 deletion test/specs/run.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe 'run', ->
.try =>
main @help_arguments
.then =>
assert stdout_spy.calledWith('generate-release\n\n-p, --package Path to package.json file. Default: ./package.json\n-c, --current-version Current Version. Default: read from package.json\n-t, --release-type Release Type: patch, minor, major. Default: prompt\n-n, --no-confirm Do not ask for confirmation. Default: prompt for confirmation\n-l, --skip-git-pull Do not pull from origin and rebase master and dev. Default: Do pull\n-s, --skip-git-push Do not push to origin when complete. Default: Do push\n-d, --release-file Path to your .release.json file. Default: ./.release.json\n-m, --set-release-message Prompt to write a release message. Default: Release {version}\n-o, --remote Change the remote. Default: origin\n\n\n')
assert stdout_spy.calledWith('generate-release\n\n-p, --package Path to package.json file. Default: ./package.json\n-c, --current-version Current Version. Default: read from package.json\n-t, --release-type Release Type: patch, minor, major. Default: prompt\n-n, --no-confirm Do not ask for confirmation. Default: prompt for confirmation\n-l, --skip-git-pull Do not pull from origin and rebase master and dev. Default: Do pull\n-s, --skip-git-push Do not push to origin when complete. Default: Do push\n-d, --release-file Path to your .release.json file. Default: ./.release.json\n-m, --set-release-message Prompt to write a release message. Default: Release {version}\n-o, --remote Change the remote. Default: origin\n-q, --quiet Less output. Default: Do show output\n\n\n')
assert @exit_stub.calledWith(0)
.finally ->
stdout_spy.restore()

0 comments on commit b4363cc

Please sign in to comment.