diff --git a/lib/docs_compressor.rb b/lib/docs_compressor.rb index 0fad71f..38a398a 100644 --- a/lib/docs_compressor.rb +++ b/lib/docs_compressor.rb @@ -2,12 +2,14 @@ require 'fileutils' require 'shellwords' require 'logging' +require 'running' # Compresses HTML, JavaScript, and CSS under the given directory, recursively. # # We do this to leverage gzip_static in nginx. class DocsCompressor include Logging + include Running EXTENSIONS = %w(.js .html .css) @@ -40,7 +42,7 @@ def compress_file(file) orig = Shellwords.shellescape(file) dest = Shellwords.shellescape(gzname(file)) - system %(gzip -c -9 #{orig} > #{dest}) + log_and_system %(gzip -c -9 #{orig} > #{dest}) end def compress_file?(file) diff --git a/lib/generators/base.rb b/lib/generators/base.rb index c59da8c..5b0cf20 100644 --- a/lib/generators/base.rb +++ b/lib/generators/base.rb @@ -74,7 +74,13 @@ def env_as_assigns(env) def run(command, env={}) command = "rvm #{ruby_version} do #{command} >/dev/null" log "#{env_as_assigns(env)} #{command}" - system(env, command) + + if system(env, command) + true + else + log "\"#{command}\" failed to execute" + abort + end end # Runs `bundle exec rake` with the appropriate Bundler and Ruby versions. diff --git a/lib/git_manager.rb b/lib/git_manager.rb index 0184bc1..9ef3f95 100644 --- a/lib/git_manager.rb +++ b/lib/git_manager.rb @@ -1,8 +1,10 @@ require 'logging' +require 'running' # Lightweight wrapper over Git, shells out everything. class GitManager include Logging + include Running attr_reader :basedir @@ -18,7 +20,7 @@ def update_master Dir.chdir(basedir) do unless Dir.exist?('master') log "cloning master into #{basedir}/master" - system "git clone -q #{remote_rails_url} master" + log_and_system "git clone -q #{remote_rails_url} master" end Dir.chdir('master') do @@ -28,8 +30,8 @@ def update_master # git pull from succeeding. Starting with Bundler 1.10, if Gemfile.lock # does not change BUNDLED WITH is left as is, even if versions differ, # but since docs generation is automated better play safe. - system 'git checkout Gemfile.lock' - system 'git pull -q' + log_and_system 'git checkout Gemfile.lock' + log_and_system 'git pull -q' end end end @@ -37,10 +39,10 @@ def update_master def checkout(tag) Dir.chdir(basedir) do log "checking out tag #{tag}" - system "git clone -q #{remote_rails_url} #{tag}" + log_and_system "git clone -q #{remote_rails_url} #{tag}" Dir.chdir(tag) do - system "git checkout -q #{tag}" + log_and_system "git checkout -q #{tag}" end end end diff --git a/lib/running.rb b/lib/running.rb new file mode 100644 index 0000000..b8ddb3f --- /dev/null +++ b/lib/running.rb @@ -0,0 +1,8 @@ +module Running + include Logging + + def log_and_system(*args) + log(args.map(&:to_s).join(' ')) + system(*args).tap { log "Done" } + end +end