lib/percy/cli/snapshot_runner.rb in percy-cli-1.2.9 vs lib/percy/cli/snapshot_runner.rb in percy-cli-1.3.0
- old
+ new
@@ -1,8 +1,8 @@
require 'find'
require 'digest'
-require 'uri'
+require 'addressable/uri'
require 'thread/pool'
Thread.abort_on_exception = true
Thread::Pool.abort_on_exception = true
@@ -31,18 +31,20 @@
num_threads = options[:threads] || 10
snapshot_limit = options[:snapshot_limit]
baseurl = options[:baseurl] || '/'
enable_javascript = !!options[:enable_javascript]
include_all = !!options[:include_all]
+ ignore_regex = options[:ignore_regex]
widths = options[:widths].map { |w| Integer(w) }
raise ArgumentError, 'baseurl must start with /' if baseurl[0] != '/'
base_resource_options = {strip_prefix: strip_prefix, baseurl: baseurl}
# Find all the static files in the given root directory.
root_paths = _find_root_paths(root_dir, snapshots_regex: options[:snapshots_regex])
- resource_paths = _find_resource_paths(root_dir, include_all: include_all)
+ opts = {include_all: include_all, ignore_regex: ignore_regex}
+ resource_paths = _find_resource_paths(root_dir, opts)
root_resources = _list_resources(root_paths, base_resource_options.merge(is_root: true))
build_resources = _list_resources(resource_paths, base_resource_options)
all_resources = root_resources + build_resources
if root_resources.empty?
@@ -125,11 +127,13 @@
nil
end
end
def _find_root_paths(dir_path, options = {})
- _find_files(dir_path).select { |path| _include_root_path?(path, options) }
+ _find_files(dir_path)
+ .select { |path| _include_root_path?(path, options) }
+ .reject { |path| _ignore_resource_path?(path, options) }
end
def _find_resource_paths(dir_path, options = {})
_find_files(dir_path).select { |path| _include_resource_path?(path, options) }
end
@@ -143,11 +147,11 @@
strip_prefix = strip_prefix[0..-2] if strip_prefix[-1] == '/'
paths.each do |path|
sha = Digest::SHA256.hexdigest(File.read(path))
next if File.size(path) > MAX_FILESIZE_BYTES
- resource_url = URI.escape(File.join(baseurl, path.sub(strip_prefix, '')))
+ resource_url = Addressable::URI.escape(File.join(baseurl, path.sub(strip_prefix, '')))
resources << Percy::Client::Resource.new(
resource_url, sha: sha, is_root: options[:is_root], path: path,
)
end
@@ -208,9 +212,19 @@
# Skip git files.
return false if path =~ /\/\.git\//
return true if options[:include_all]
STATIC_RESOURCE_EXTENSIONS.include?(File.extname(path))
+ end
+
+ def _ignore_resource_path?(path, options)
+ return false unless options[:ignore_regex]
+
+ begin
+ path.match(options[:ignore_regex])
+ rescue StandardError
+ false
+ end
end
def _include_root_path?(path, options)
# Skip git files.
return false if path =~ /\/\.git\//