rackstatic 0.1.1 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc1751213160fd605d7884ac94edf263ba7c2050
4
- data.tar.gz: e783ebc5fe72cd0a64b5ba01641690fd9d6fb8f2
3
+ metadata.gz: 988438ddf50817e39303c24d76b78b34917fdf2b
4
+ data.tar.gz: ea0c783934b0116db4b4c6381ba286156ffd55ca
5
5
  SHA512:
6
- metadata.gz: 19284839fe275f71d4e42f23d511a197af1a0ff5d7f5a866ea5ea30f98a90d63093e31dda37a3e442103e82d8dffc2e097a4716552b498d28e956a942a6c89ac
7
- data.tar.gz: 72dc00451eee38e4afb170e3ba76e7e09c7163d9b7391d5c3f5dcd2b16fc14aef9ebc5f59d8580047a28eb5ecbd795c4c566251b525db5c35e911061847e931b
6
+ metadata.gz: fd01b6ddb7882f58c879b73b354819fdea97bedf011f372133e758db147801205596bf1c2c32504a7d817df220ce8f080b06022f251bb4a98cb16116ecbc20f3
7
+ data.tar.gz: 82a3a8e7112867e4e84ced5a50e4c3941f0ed13aafc837bec63baaafd9ff2cd58ce87bf6d88262a25ce6e9ee3d7c0404b7c507456766f156cae19be73cc64498
data/bin/rackstatic CHANGED
@@ -9,17 +9,20 @@ opts = {}
9
9
  opts[:app_dir] = 'app'
10
10
  opts[:app_static_dir] = 'public'
11
11
  opts[:dest_dir] = 'dist'
12
- opts[:noisy] = true
12
+ opts[:noise_level] = 1
13
13
 
14
14
  OptionParser.new do |op|
15
- op.banner = "Usage: rackstatic [opts] [destination]"
15
+ op.banner = "Usage: #{File.basename($0)} [opts] [destination]"
16
16
 
17
17
  op.on("-a", "--app DIRECTORY", "Application directory (where config.ru is)"){ |v| opts[:app_dir] = v }
18
18
  op.on("-s", "--static SUBDIRECTORY", "Directory within the app dir where static files are kept"){ |v| opts[:app_static_dir] = v }
19
19
 
20
20
  op.on("-d", "--dest DIRECTORY", "Build output directory"){ |v| opts[:dest_dir] = v }
21
21
 
22
- op.on("-q", "--quiet", "Build quietly"){ opts[:noisy] = false }
22
+ op.on("-p", "--preserve-on-error", "Keep the build output even if the build fails"){ opts[:preserve_on_error] = true }
23
+
24
+ op.on("-q", "--quiet", "Build quietly"){ opts[:noise_level] = 0 }
25
+ op.on("-v", "--verbose", "Build with lots of output"){ opts[:noise_level] = 2 }
23
26
 
24
27
  op.on_tail("-h", "--help", "Show this message") { puts opts; exit }
25
28
  op.on_tail("--version", "Show version") { puts Rack::StaticBuilder::VERSION }
@@ -30,9 +33,14 @@ if ARGV.length == 1
30
33
  end
31
34
 
32
35
  begin
33
- status = Rack::StaticBuilder.new(opts).build!
34
- Kernel.exit( status ? 0 : 1 )
36
+ Rack::StaticBuilder.new(opts).build!
37
+ rescue Rack::StaticBuilder::BuildError => e
38
+ if opts[:noise_level] > 0
39
+ $stderr.puts "#{File.basename($0)}: build failed - " + e.message
40
+ end
41
+
42
+ Kernel.exit 1
35
43
  rescue ArgumentError
36
- $stderr.puts "rackstatic: must be run within or above a rack-compatible application directory"
44
+ $stderr.puts "#{File.basename($0)}: must be run within or above a rack-compatible application directory"
37
45
  Kernel.exit 1
38
46
  end
@@ -6,8 +6,9 @@ require 'rack/test'
6
6
  require 'nokogiri'
7
7
 
8
8
  class Rack::StaticBuilder
9
- VERSION = '0.1.1'
9
+ VERSION = '0.1.4'
10
10
 
11
+ class BuildError < Exception; end
11
12
 
12
13
  class RequestPathQueue
13
14
  def initialize
@@ -39,6 +40,8 @@ class Rack::StaticBuilder
39
40
 
40
41
 
41
42
  def initialize(opts)
43
+ opts = opts.dup
44
+
42
45
  @app_dir = [opts.delete(:app_dir), 'app', '.'].compact.find{ |d| File.file?(d + '/config.ru') }
43
46
  raise ArgumentError unless @app_dir
44
47
 
@@ -46,30 +49,45 @@ class Rack::StaticBuilder
46
49
  @dest_dir = Pathname.new(opts.delete(:dest_dir) || 'dist').expand_path.cleanpath
47
50
  @app_static_dir = (@app_dir + (opts.delete(:static_dir) || 'public')).expand_path.cleanpath
48
51
 
49
- @noisy = opts.delete(:noisy)
52
+ @noise_level = (opts.delete(:noise_level) || '0').to_i
53
+ @preserve_on_error = opts.delete(:preserve_on_error)
50
54
  end
51
55
 
52
- def build!
56
+ def build
53
57
  @dest_dir.rmtree if @dest_dir.directory?
54
58
 
55
59
  queue = RequestPathQueue.new
56
60
 
57
61
  enqueue_static_assets(queue)
58
62
 
59
- counts = {true => 0, false => 0}
63
+ req_stats = {
64
+ :status => Hash.new(0),
65
+ :category => Hash.new(0),
66
+ :succeeded => 0,
67
+ :failed => 0,
68
+ :total => 0
69
+ }
60
70
 
61
71
  with_rack_client do |client|
62
72
 
63
73
  queue.drain do |req_path|
64
74
  resp = client.get req_path
65
75
 
66
- if @noisy
67
- channel = (resp.status == 200) ? $stdout : $stderr
68
- channel.puts("#{resp.status} #{req_path}")
69
- counts[(resp.status == 200)] += 1
76
+ req_status = resp.status
77
+ req_category = (req_status / 100)
78
+ req_succeeded = (req_category == 2)
79
+
80
+ req_stats[:status][req_status] += 1
81
+ req_stats[:category][req_category] += 1
82
+ req_stats[(req_succeeded ? :succeeded : :failed)] += 1
83
+ req_stats[:total] += 1
84
+
85
+ if @noise_level > 1 or (!req_succeeded and @noise_level > 0)
86
+ channel = req_succeeded ? $stdout : $stderr
87
+ channel.puts("#{req_status} #{req_path}")
70
88
  end
71
89
 
72
- next unless resp.status == 200
90
+ next unless req_succeeded
73
91
  next unless store_response!(req_path, resp.body)
74
92
 
75
93
  if enqueue_links = capture_method_for(resp.content_type)
@@ -79,11 +97,19 @@ class Rack::StaticBuilder
79
97
 
80
98
  end
81
99
 
82
- if @noisy and counts[false] > 0
83
- $stderr.puts "\nFAILED: #{ counts[false] } requests returned non-200 and were discarded"
100
+ if req_stats[:failed] > 0 and not @preserve_on_error
101
+ @dest_dir.rmtree if @dest_dir.directory?
84
102
  end
85
103
 
86
- (counts[false] > 0)
104
+ req_stats
105
+ end
106
+
107
+ def build!
108
+ req_stats = self.build
109
+
110
+ raise BuildError, "#{ req_stats[:failed] } URLs requested with non-2XX responses" unless (req_stats[:failed] == 0)
111
+
112
+ req_stats
87
113
  end
88
114
 
89
115
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rackstatic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sean Keith McAuley