middleman-cdn 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 69067babbcf6c181de78867c0a26cd0419f1cd7f
4
- data.tar.gz: 9a2adde88d7fce458d9c04d29dd48728403c708d
3
+ metadata.gz: 1e79d37359ea1e80126fd90bee4767bde571842d
4
+ data.tar.gz: ede9b99ab9222ebf86bb7d3735fc6cacae481fd5
5
5
  SHA512:
6
- metadata.gz: 1f353a06b8b40e21e040c5797c504f15afe500b5264ea476e91ba587f7ea26e2e8114aac2bfc9bea10f03c5dab5886d7630cca98ecbc6534557268154c9b01ac
7
- data.tar.gz: 2627680904f589d2901a5732549c19105ea017dcbafcac74f986efd57f1747c3e1ab194f0d8bba957c8fa0d1c848ab695b818eb380fe64ea84e6e8aa3a8eb835
6
+ metadata.gz: 74d22ceecce8e729df8b9e11e8a840ad5c55b051730d1d962bcece2520b890bf92a792c7e920ee85317f3f775c46e5a3d1646f1ee7bbbb317121f31687f51c28
7
+ data.tar.gz: 87f355883c41f5956f4b6752c8ecb16a02a6228750d11f7f841c4ae5fb164c717d078f0a05189cd79f823dce88414f79e829f993a58e5ef3760a2c9d36c46809
@@ -22,8 +22,6 @@ TEXT
22
22
  end
23
23
 
24
24
  def invalidate(options, files)
25
- puts "## Invalidating files on CloudFlare"
26
-
27
25
  options[:client_api_key] ||= ENV['CLOUDFLARE_CLIENT_API_KEY']
28
26
  options[:email] ||= ENV['CLOUDFLARE_EMAIL']
29
27
  [:client_api_key, :email, :zone, :base_urls].each do |key|
@@ -41,12 +39,12 @@ TEXT
41
39
  cloudflare = ::CloudFlare::connection(options[:client_api_key], options[:email])
42
40
  begin
43
41
  url = "#{base_url}#{file}"
44
- print "Invalidating #{url}... "
42
+ ::Middleman::Cli::CDN.say_status("cloudflare".yellow + " invalidating #{url}... ", incomplete: true)
45
43
  cloudflare.zone_file_purge(options[:zone], "#{base_url}#{file}")
46
44
  rescue => e
47
- puts "Error: #{e.message}"
45
+ ::Middleman::Cli::CDN.say_status(", " + "error: #{e.message}".light_red, header: false)
48
46
  else
49
- puts "✓"
47
+ ::Middleman::Cli::CDN.say_status("✓".light_green, header: false)
50
48
  end
51
49
  end
52
50
  end
@@ -22,8 +22,6 @@ TEXT
22
22
  end
23
23
 
24
24
  def invalidate(options, files)
25
- puts "## Invalidating files on CloudFront"
26
-
27
25
  options[:access_key_id] ||= ENV['AWS_ACCESS_KEY_ID']
28
26
  options[:secret_access_key] ||= ENV['AWS_SECRET_ACCESS_KEY']
29
27
  [:access_key_id, :secret_access_key, :distribution_id].each do |key|
@@ -39,19 +37,22 @@ TEXT
39
37
  distribution = cloudfront.distributions.get(options[:distribution_id])
40
38
 
41
39
  if files.count <= INVALIDATION_LIMIT
42
- puts "Invalidating #{files.count} files. It might take 10 to 15 minutes until all files are invalidated."
43
- puts 'Please check the AWS Management Console to see the status of the invalidation.'
40
+ ::Middleman::Cli::CDN.say_status("cloudfront".yellow + " invalidating #{files.count} files... ", incomplete: true)
44
41
  invalidation = distribution.invalidations.create(:paths => files)
45
42
  raise StandardError, %(Invalidation status is #{invalidation.status}. Expected "InProgress") unless invalidation.status == 'InProgress'
43
+ ::Middleman::Cli::CDN.say_status("✓".light_green, header: false)
46
44
  else
47
45
  slices = files.each_slice(INVALIDATION_LIMIT)
48
- puts "Invalidating #{files.count} files in #{slices.count} batch(es). It might take 10 to 15 minutes per batch until all files are invalidated."
46
+ ::Middleman::Cli::CDN.say_status("cloudfront".yellow + " invalidating #{files.count} files in #{slices.count} batch(es) ")
49
47
  slices.each_with_index do |slice, i|
50
- puts "Invalidating batch #{i + 1}..."
48
+ ::Middleman::Cli::CDN.say_status("cloudfront".yellow + " invalidating batch #{i + 1}... ", incomplete: true)
51
49
  invalidation = distribution.invalidations.create(:paths => slice)
52
50
  invalidation.wait_for { ready? } unless i == slices.count - 1
51
+ ::Middleman::Cli::CDN.say_status("✓".light_green, header: false)
53
52
  end
54
53
  end
54
+ ::Middleman::Cli::CDN.say_status("cloudfront".yellow + " It might take 10 to 15 minutes until all files are invalidated.")
55
+ ::Middleman::Cli::CDN.say_status("cloudfront".yellow + ' Please check the AWS Management Console to see the status of the invalidation.')
55
56
  end
56
57
  end
57
58
 
@@ -32,10 +32,8 @@ module Middleman
32
32
  raise Error, "ERROR: You must specify a config for one of the supported CDNs.\n#{example_configuration}"
33
33
  end
34
34
 
35
- # CloudFront limits the amount of files which can be invalidated by one request to 1000.
36
- # If there are more than 1000 files to invalidate, do so sequentially and wait until each validation is ready.
37
- # If there are max 1000 files, create the invalidation and return immediately.
38
35
  files = list_files(options.filter)
36
+ ::Middleman::Cli::CDN.say_status("Invalidating #{files.count} files with filter: #{options.filter.source}")
39
37
  return if files.empty?
40
38
 
41
39
  cdns_keyed.each do |cdn_key, cdn|
@@ -44,6 +42,17 @@ module Middleman
44
42
  end
45
43
  end
46
44
 
45
+ def self.say_status(status, incomplete: false, header: true)
46
+ message = ""
47
+ message << :cdn.to_s.rjust(12).light_green + " " if header
48
+ message << status
49
+ if incomplete
50
+ print message
51
+ else
52
+ puts message
53
+ end
54
+ end
55
+
47
56
  protected
48
57
 
49
58
  def cdns
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module CDN
3
- VERSION = '0.1.2'
3
+ VERSION = '0.1.3'
4
4
  end
5
5
  end
@@ -20,6 +20,7 @@ Gem::Specification.new do |s|
20
20
 
21
21
  s.add_dependency 'fog', '~> 1.9'
22
22
  s.add_dependency 'cloudflare', '~> 2.0'
23
+ s.add_dependency 'colorize'
23
24
 
24
25
  s.add_development_dependency 'cucumber', '~> 1.3'
25
26
  s.add_development_dependency 'aruba', '~> 0.5'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-cdn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leigh McCulloch
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: colorize
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: cucumber
43
57
  requirement: !ruby/object:Gem::Requirement