Skip to content

Commit 98fb2c0

Browse files
authored
Merge pull request #17 from localhostdotdev/log-and-done
Logs commands executed and print Done when finished
2 parents d4b1da6 + 2870bb8 commit 98fb2c0

File tree

4 files changed

+25
-7
lines changed

4 files changed

+25
-7
lines changed

lib/docs_compressor.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
require 'fileutils'
33
require 'shellwords'
44
require 'logging'
5+
require 'running'
56

67
# Compresses HTML, JavaScript, and CSS under the given directory, recursively.
78
#
89
# We do this to leverage gzip_static in nginx.
910
class DocsCompressor
1011
include Logging
12+
include Running
1113

1214
EXTENSIONS = %w(.js .html .css)
1315

@@ -40,7 +42,7 @@ def compress_file(file)
4042
orig = Shellwords.shellescape(file)
4143
dest = Shellwords.shellescape(gzname(file))
4244

43-
system %(gzip -c -9 #{orig} > #{dest})
45+
log_and_system %(gzip -c -9 #{orig} > #{dest})
4446
end
4547

4648
def compress_file?(file)

lib/generators/base.rb

+7-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ def env_as_assigns(env)
7474
def run(command, env={})
7575
command = "rvm #{ruby_version} do #{command} >/dev/null"
7676
log "#{env_as_assigns(env)} #{command}"
77-
system(env, command)
77+
78+
if system(env, command)
79+
true
80+
else
81+
log "\"#{command}\" failed to execute"
82+
abort
83+
end
7884
end
7985

8086
# Runs `bundle exec rake` with the appropriate Bundler and Ruby versions.

lib/git_manager.rb

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
require 'logging'
2+
require 'running'
23

34
# Lightweight wrapper over Git, shells out everything.
45
class GitManager
56
include Logging
7+
include Running
68

79
attr_reader :basedir
810

@@ -18,7 +20,7 @@ def update_master
1820
Dir.chdir(basedir) do
1921
unless Dir.exist?('master')
2022
log "cloning master into #{basedir}/master"
21-
system "git clone -q #{remote_rails_url} master"
23+
log_and_system "git clone -q #{remote_rails_url} master"
2224
end
2325

2426
Dir.chdir('master') do
@@ -28,19 +30,19 @@ def update_master
2830
# git pull from succeeding. Starting with Bundler 1.10, if Gemfile.lock
2931
# does not change BUNDLED WITH is left as is, even if versions differ,
3032
# but since docs generation is automated better play safe.
31-
system 'git checkout Gemfile.lock'
32-
system 'git pull -q'
33+
log_and_system 'git checkout Gemfile.lock'
34+
log_and_system 'git pull -q'
3335
end
3436
end
3537
end
3638

3739
def checkout(tag)
3840
Dir.chdir(basedir) do
3941
log "checking out tag #{tag}"
40-
system "git clone -q #{remote_rails_url} #{tag}"
42+
log_and_system "git clone -q #{remote_rails_url} #{tag}"
4143

4244
Dir.chdir(tag) do
43-
system "git checkout -q #{tag}"
45+
log_and_system "git checkout -q #{tag}"
4446
end
4547
end
4648
end

lib/running.rb

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module Running
2+
include Logging
3+
4+
def log_and_system(*args)
5+
log(args.map(&:to_s).join(' '))
6+
system(*args).tap { log "Done" }
7+
end
8+
end

0 commit comments

Comments
 (0)