percy-cli 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/percy/cli/snapshot.rb +0 -94
- data/lib/percy/cli/version.rb +1 -1
- data/lib/percy/cli.rb +0 -5
- data/spec/percy/cli/snapshot_spec.rb +0 -38
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9850a1af689e2c117bbe0b183546e92e591b968b
|
4
|
+
data.tar.gz: c10b07dab5709b16be0222f7225a5f73e7a03275
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2222e6b6414985a6ed54370d39b564e0dc06f550c08113524ed04da580a0aee029f7e594df436339f82fcad1493cfe0b1940b0b7b8fa773f3bb6fcf4cbe2269e
|
7
|
+
data.tar.gz: 1ac69b7e3e58585558a9b6addcf73b2fe8a191148cf370fd658228a3513e4d21a16dc59b05d3cb8cd1ebdbad8aafb16e08427552ffa25111dcfb848f32672741
|
data/lib/percy/cli/snapshot.rb
CHANGED
@@ -16,48 +16,9 @@ module Percy
|
|
16
16
|
|
17
17
|
DEFAULT_SNAPSHOTS_REGEX = /\.(html|htm)$/
|
18
18
|
|
19
|
-
# Modified version of Diego Perini's URL regex. https://gist.github.com/dperini/729294
|
20
|
-
REMOTE_URL_REGEX_STRING = (
|
21
|
-
# protocol identifier
|
22
|
-
"(?:(?:https?:)?//)" +
|
23
|
-
"(?:" +
|
24
|
-
# IP address exclusion
|
25
|
-
# private & local networks
|
26
|
-
"(?!(?:10|127)(?:\\.\\d{1,3}){3})" +
|
27
|
-
"(?!(?:169\\.254|192\\.168)(?:\\.\\d{1,3}){2})" +
|
28
|
-
"(?!172\\.(?:1[6-9]|2\\d|3[0-1])(?:\\.\\d{1,3}){2})" +
|
29
|
-
# IP address dotted notation octets
|
30
|
-
# excludes loopback network 0.0.0.0
|
31
|
-
# excludes reserved space >= 224.0.0.0
|
32
|
-
# excludes network & broacast addresses
|
33
|
-
# (first & last IP address of each class)
|
34
|
-
"(?:[1-9]\\d?|1\\d\\d|2[01]\\d|22[0-3])" +
|
35
|
-
"(?:\\.(?:1?\\d{1,2}|2[0-4]\\d|25[0-5])){2}" +
|
36
|
-
"(?:\\.(?:[1-9]\\d?|1\\d\\d|2[0-4]\\d|25[0-4]))" +
|
37
|
-
"|" +
|
38
|
-
# host name
|
39
|
-
"(?:(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)" +
|
40
|
-
# domain name
|
41
|
-
"(?:\\.(?:[a-z\\u00a1-\\uffff0-9]-*)*[a-z\\u00a1-\\uffff0-9]+)*" +
|
42
|
-
# TLD identifier
|
43
|
-
"(?:\\.(?:[a-z\\u00a1-\\uffff]{2,}))" +
|
44
|
-
")" +
|
45
|
-
# port number
|
46
|
-
"(?::\\d{2,5})?" +
|
47
|
-
# resource path
|
48
|
-
"(?:/[^\\s\"']*)?"
|
49
|
-
)
|
50
|
-
HTML_REMOTE_URL_REGEX = Regexp.new("(<link.*?href=['\"](" + REMOTE_URL_REGEX_STRING + ")[^>]+)")
|
51
|
-
|
52
|
-
# Match all url("https://...") styles, with whitespace and quote variatinos.
|
53
|
-
CSS_REMOTE_URL_REGEX = Regexp.new(
|
54
|
-
"url\\s*\\([\"'\s]*(" + REMOTE_URL_REGEX_STRING + ")[\"'\s]*\\)"
|
55
|
-
)
|
56
|
-
|
57
19
|
def run_snapshot(root_dir, options = {})
|
58
20
|
repo = options[:repo] || Percy.config.repo
|
59
21
|
strip_prefix = File.absolute_path(options[:strip_prefix] || root_dir)
|
60
|
-
autoload_remote_resources = options[:autoload_remote_resources] || false
|
61
22
|
num_threads = options[:threads] || 10
|
62
23
|
snapshot_limit = options[:snapshot_limit]
|
63
24
|
|
@@ -66,12 +27,6 @@ module Percy
|
|
66
27
|
resource_paths = find_resource_paths(root_dir)
|
67
28
|
root_resources = build_resources(root_paths, strip_prefix, is_root: true)
|
68
29
|
related_resources = build_resources(resource_paths, strip_prefix)
|
69
|
-
|
70
|
-
if autoload_remote_resources
|
71
|
-
remote_urls = find_remote_urls(root_paths + resource_paths)
|
72
|
-
related_resources += build_remote_resources(remote_urls)
|
73
|
-
end
|
74
|
-
|
75
30
|
all_resources = root_resources + related_resources
|
76
31
|
|
77
32
|
if root_resources.empty?
|
@@ -144,25 +99,6 @@ module Percy
|
|
144
99
|
file_paths
|
145
100
|
end
|
146
101
|
|
147
|
-
def find_remote_urls(file_paths)
|
148
|
-
urls = []
|
149
|
-
file_paths.each do |path|
|
150
|
-
extension = File.extname(path)
|
151
|
-
case extension
|
152
|
-
when '.html'
|
153
|
-
content = File.read(path)
|
154
|
-
urls += content.scan(HTML_REMOTE_URL_REGEX).map do |match|
|
155
|
-
next if !match[0].include?('stylesheet') # Only include links with rel="stylesheet".
|
156
|
-
maybe_add_protocol(match[1])
|
157
|
-
end
|
158
|
-
when '.css'
|
159
|
-
content = File.read(path)
|
160
|
-
urls += content.scan(CSS_REMOTE_URL_REGEX).map { |match| maybe_add_protocol(match[0]) }
|
161
|
-
end
|
162
|
-
end
|
163
|
-
urls.compact.uniq
|
164
|
-
end
|
165
|
-
|
166
102
|
def maybe_add_protocol(url)
|
167
103
|
url[0..1] == '//' ? "http:#{url}" : url
|
168
104
|
end
|
@@ -182,36 +118,6 @@ module Percy
|
|
182
118
|
resources
|
183
119
|
end
|
184
120
|
|
185
|
-
def build_remote_resources(remote_urls)
|
186
|
-
resources = []
|
187
|
-
|
188
|
-
bar = Commander::UI::ProgressBar.new(
|
189
|
-
remote_urls.length,
|
190
|
-
title: 'Fetching remote resources...',
|
191
|
-
format: ':title |:progress_bar| :percent_complete% complete - :url',
|
192
|
-
width: 20,
|
193
|
-
complete_message: "Fetched #{remote_urls.length} remote resources.",
|
194
|
-
)
|
195
|
-
|
196
|
-
remote_urls.each do |url|
|
197
|
-
bar.increment url: url
|
198
|
-
begin
|
199
|
-
response = Faraday.get(url)
|
200
|
-
rescue Faraday::Error::ConnectionFailed, Faraday::SSLError => e
|
201
|
-
say_error e
|
202
|
-
next
|
203
|
-
end
|
204
|
-
if response.status != 200
|
205
|
-
say_error "Remote resource failed, skipping (#{response.status}): #{url}"
|
206
|
-
next
|
207
|
-
end
|
208
|
-
|
209
|
-
sha = Digest::SHA256.hexdigest(response.body)
|
210
|
-
resources << Percy::Client::Resource.new(url, sha: sha, content: response.body)
|
211
|
-
end
|
212
|
-
resources
|
213
|
-
end
|
214
|
-
|
215
121
|
# Uploads missing resources either for a build or snapshot.
|
216
122
|
def upload_missing_resources(build, obj, potential_resources, options = {})
|
217
123
|
# Upload the content for any missing resources.
|
data/lib/percy/cli/version.rb
CHANGED
data/lib/percy/cli.rb
CHANGED
@@ -45,10 +45,6 @@ module Percy
|
|
45
45
|
'--snapshot_limit NUM',
|
46
46
|
Integer,
|
47
47
|
"Max number of snapshots to upload, useful for testing. Default is unlimited."
|
48
|
-
c.option \
|
49
|
-
'--autoload_remote_resources',
|
50
|
-
'Attempts to parse HTML and CSS for remote resources, fetch them, and include in ' +
|
51
|
-
'snapshots. This can be very useful if your static website relies on remote resources.'
|
52
48
|
c.option \
|
53
49
|
'--threads NUM',
|
54
50
|
Integer,
|
@@ -56,7 +52,6 @@ module Percy
|
|
56
52
|
"Defaults to #{DEFAULT_NUM_THREADS}, max #{MAX_NUM_THREADS}."
|
57
53
|
|
58
54
|
c.action do |args, options|
|
59
|
-
options.default autoload_remote_resources: false
|
60
55
|
options.default threads: DEFAULT_NUM_THREADS
|
61
56
|
options.threads = MAX_NUM_THREADS if options.threads > MAX_NUM_THREADS
|
62
57
|
|
@@ -27,26 +27,6 @@ RSpec.describe Percy::Cli::Snapshot do
|
|
27
27
|
])
|
28
28
|
end
|
29
29
|
end
|
30
|
-
describe '#find_remote_urls' do
|
31
|
-
it 'returns remote resources referenced throughout the static website' do
|
32
|
-
root_paths = Percy::Cli.new.send(:find_root_paths, root_dir)
|
33
|
-
resource_paths = Percy::Cli.new.send(:find_resource_paths, root_dir)
|
34
|
-
|
35
|
-
remote_urls = Percy::Cli.new.send(:find_remote_urls, root_paths + resource_paths)
|
36
|
-
expect(remote_urls).to match_array([
|
37
|
-
# In index.html:
|
38
|
-
'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css',
|
39
|
-
'http://example.com:12345/test-no-protocol.css',
|
40
|
-
'http://example.com:12345/test-duplicate.css',
|
41
|
-
'http://example.com:12345/test-query-param.css?v=1',
|
42
|
-
'http://example.com:12345/test-single-quotes.css',
|
43
|
-
'http://example.com:12345/test-diff-tag-order.css',
|
44
|
-
|
45
|
-
# In base.css:
|
46
|
-
'http://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css',
|
47
|
-
])
|
48
|
-
end
|
49
|
-
end
|
50
30
|
describe '#build_resources' do
|
51
31
|
it 'returns resource objects' do
|
52
32
|
paths = [File.join(root_dir, 'css/base.css')]
|
@@ -81,24 +61,6 @@ RSpec.describe Percy::Cli::Snapshot do
|
|
81
61
|
expect(resources.first.path).to eq(paths.first)
|
82
62
|
end
|
83
63
|
end
|
84
|
-
describe '#build_remote_resources' do
|
85
|
-
it 'fetches the remote URLs and creates resource objects' do
|
86
|
-
urls = [
|
87
|
-
'https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css',
|
88
|
-
'http://example.com:12345/test-failure.css',
|
89
|
-
]
|
90
|
-
stub_request(:get, 'http://example.com:12345/test-failure.css').to_return(status: 400)
|
91
|
-
|
92
|
-
resources = Percy::Cli.new.send(:build_remote_resources, urls)
|
93
|
-
|
94
|
-
expect(resources.length).to eq(1)
|
95
|
-
expect(resources[0].resource_url).to eq(urls[0])
|
96
|
-
expect(resources[0].sha).to be
|
97
|
-
expect(resources[0].is_root).to be_nil
|
98
|
-
expect(resources[0].content).to be
|
99
|
-
expect(resources[0].path).to be_nil
|
100
|
-
end
|
101
|
-
end
|
102
64
|
describe '#upload_snapshot' do
|
103
65
|
xit 'uploads the given resources to the build' do
|
104
66
|
# TODO(fotinakis): tests for this.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: percy-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Perceptual Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commander
|
@@ -170,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
170
170
|
version: '0'
|
171
171
|
requirements: []
|
172
172
|
rubyforge_project:
|
173
|
-
rubygems_version: 2.
|
173
|
+
rubygems_version: 2.4.5
|
174
174
|
signing_key:
|
175
175
|
specification_version: 4
|
176
176
|
summary: Percy command-line interface
|