percy-cli 1.2.1 → 1.2.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0bacd3f31c9a5045f5f9696e03a55b150d68bbc7
|
4
|
+
data.tar.gz: 363609d9f91e061966b7b88252b58682ee82ded1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dfac04fe59707361fe44d12198747a67537397f7e8cfd7440dd301ba7b86a23a403b4586050ac604a72ec43e76468c311bfc05fdeca327d07dbbf352f3a5f9de
|
7
|
+
data.tar.gz: 3bf6624f8fbc4929c59b6756b69fcfb951c94cf3bacd00404c40d24d7131e974071bd58e74d9cde208c3e965c70bf86dc98d989c3d63a04c6fc48fd1fa8b4575
|
data/lib/percy/cli/snapshot.rb
CHANGED
@@ -19,7 +19,8 @@ module Percy
|
|
19
19
|
|
20
20
|
def run_snapshot(root_dir, options = {})
|
21
21
|
repo = options[:repo] || Percy.config.repo
|
22
|
-
|
22
|
+
root_dir = File.expand_path(File.absolute_path(root_dir))
|
23
|
+
strip_prefix = File.expand_path(File.absolute_path(options[:strip_prefix] || root_dir))
|
23
24
|
num_threads = options[:threads] || 10
|
24
25
|
snapshot_limit = options[:snapshot_limit]
|
25
26
|
baseurl = options[:baseurl] || '/'
|
@@ -32,22 +33,22 @@ module Percy
|
|
32
33
|
# Find all the static files in the given root directory.
|
33
34
|
root_paths = find_root_paths(root_dir, snapshots_regex: options[:snapshots_regex])
|
34
35
|
resource_paths = find_resource_paths(root_dir)
|
35
|
-
root_resources =
|
36
|
-
|
37
|
-
all_resources = root_resources +
|
36
|
+
root_resources = list_resources(root_paths, base_resource_options.merge(is_root: true))
|
37
|
+
build_resources = list_resources(resource_paths, base_resource_options)
|
38
|
+
all_resources = root_resources + build_resources
|
38
39
|
|
39
40
|
if root_resources.empty?
|
40
41
|
say "No root resource files found. Are there HTML files in the given directory?"
|
41
42
|
exit(-1)
|
42
43
|
end
|
43
44
|
|
44
|
-
|
45
|
+
build_resources.each do |resource|
|
45
46
|
Percy.logger.debug { "Found build resource: #{resource.resource_url}" }
|
46
47
|
end
|
47
48
|
|
48
49
|
build = rescue_connection_failures do
|
49
50
|
say 'Creating build...'
|
50
|
-
build = Percy.create_build(repo, resources:
|
51
|
+
build = Percy.create_build(repo, resources: build_resources)
|
51
52
|
|
52
53
|
say 'Uploading build resources...'
|
53
54
|
upload_missing_resources(build, build, all_resources, {num_threads: num_threads})
|
@@ -56,7 +57,7 @@ module Percy
|
|
56
57
|
end
|
57
58
|
return if failed?
|
58
59
|
|
59
|
-
# Upload a snapshot for every root resource, and associate the
|
60
|
+
# Upload a snapshot for every root resource, and associate the build_resources.
|
60
61
|
output_lock = Mutex.new
|
61
62
|
snapshot_thread_pool = Thread.pool(num_threads)
|
62
63
|
total = snapshot_limit ? [root_resources.length, snapshot_limit].min : root_resources.length
|
@@ -113,10 +114,7 @@ module Percy
|
|
113
114
|
snapshots_regex = options[:snapshots_regex] || DEFAULT_SNAPSHOTS_REGEX
|
114
115
|
|
115
116
|
file_paths = []
|
116
|
-
|
117
|
-
path = File.absolute_path(relative_path)
|
118
|
-
# Skip directories.
|
119
|
-
next if !FileTest.file?(path)
|
117
|
+
_find_files(dir_path).each do |path|
|
120
118
|
# Skip files that don't match the snapshots_regex.
|
121
119
|
next if !path.match(snapshots_regex)
|
122
120
|
file_paths << path
|
@@ -126,11 +124,7 @@ module Percy
|
|
126
124
|
|
127
125
|
def find_resource_paths(dir_path)
|
128
126
|
file_paths = []
|
129
|
-
|
130
|
-
path = File.absolute_path(relative_path)
|
131
|
-
|
132
|
-
# Skip directories.
|
133
|
-
next if !FileTest.file?(path)
|
127
|
+
_find_files(dir_path).each do |path|
|
134
128
|
# Skip dot files.
|
135
129
|
next if path.match(/\/\./)
|
136
130
|
# Only include files with the above static extensions.
|
@@ -145,8 +139,8 @@ module Percy
|
|
145
139
|
url[0..1] == '//' ? "http:#{url}" : url
|
146
140
|
end
|
147
141
|
|
148
|
-
def
|
149
|
-
strip_prefix = options[:strip_prefix]
|
142
|
+
def list_resources(paths, options = {})
|
143
|
+
strip_prefix = File.expand_path(options[:strip_prefix])
|
150
144
|
baseurl = options[:baseurl]
|
151
145
|
resources = []
|
152
146
|
|
@@ -194,6 +188,18 @@ module Percy
|
|
194
188
|
uploader_thread_pool.wait
|
195
189
|
uploader_thread_pool.shutdown
|
196
190
|
end
|
191
|
+
|
192
|
+
# A file find method that follows directory and file symlinks.
|
193
|
+
def _find_files(*paths)
|
194
|
+
paths.flatten!
|
195
|
+
paths.map! { |p| Pathname.new(p) }
|
196
|
+
files = paths.select { |p| p.file? }
|
197
|
+
(paths - files).each do |dir|
|
198
|
+
files << _find_files(dir.children)
|
199
|
+
end
|
200
|
+
files.flatten.map { |path| path.to_s }
|
201
|
+
end
|
202
|
+
private :_find_files
|
197
203
|
end
|
198
204
|
end
|
199
205
|
end
|
data/lib/percy/cli/version.rb
CHANGED
@@ -3,6 +3,9 @@ require 'digest'
|
|
3
3
|
RSpec.describe Percy::Cli::Snapshot do
|
4
4
|
let(:root_dir) { File.expand_path('../testdata/', __FILE__) }
|
5
5
|
|
6
|
+
# Used for testing that paths are collapsed before use.r
|
7
|
+
let(:root_dir_relative) { root_dir + '/../testdata' }
|
8
|
+
|
6
9
|
describe '#run_snapshot' do
|
7
10
|
xit 'snapshots a root directory of static files' do
|
8
11
|
# TODO(fotinakis): tests for the full flow.
|
@@ -55,6 +58,11 @@ RSpec.describe Percy::Cli::Snapshot do
|
|
55
58
|
expect(paths).to match_array([
|
56
59
|
File.join(root_dir, 'index.html'),
|
57
60
|
File.join(root_dir, 'subdir/test.html'),
|
61
|
+
# Make sure file symlinks are followed.
|
62
|
+
File.join(root_dir, 'subdir/test_symlink.html'),
|
63
|
+
# Make sure directory symlinks are followed.
|
64
|
+
File.join(root_dir, 'subdir_symlink/test.html'),
|
65
|
+
File.join(root_dir, 'subdir_symlink/test_symlink.html'),
|
58
66
|
])
|
59
67
|
end
|
60
68
|
end
|
@@ -65,14 +73,19 @@ RSpec.describe Percy::Cli::Snapshot do
|
|
65
73
|
File.join(root_dir, 'css/base.css'),
|
66
74
|
File.join(root_dir, 'css/test with spaces.css'),
|
67
75
|
File.join(root_dir, 'images/jellybeans.png'),
|
76
|
+
# Make sure file symlinks are followed.
|
77
|
+
File.join(root_dir, 'images/jellybeans-symlink.png'),
|
78
|
+
# Make sure directory symlinks are followed.
|
79
|
+
File.join(root_dir, 'images_symlink/jellybeans.png'),
|
80
|
+
File.join(root_dir, 'images_symlink/jellybeans-symlink.png'),
|
68
81
|
])
|
69
82
|
end
|
70
83
|
end
|
71
|
-
describe '#
|
84
|
+
describe '#list_resources' do
|
72
85
|
it 'returns resource objects' do
|
73
86
|
paths = [File.join(root_dir, 'css/base.css')]
|
74
87
|
options = {baseurl: '/', strip_prefix: root_dir}
|
75
|
-
resources = Percy::Cli.new.send(:
|
88
|
+
resources = Percy::Cli.new.send(:list_resources, paths, options)
|
76
89
|
|
77
90
|
expect(resources.length).to eq(1)
|
78
91
|
expect(resources.first.sha).to eq(Digest::SHA256.hexdigest(File.read(paths.first)))
|
@@ -80,10 +93,18 @@ RSpec.describe Percy::Cli::Snapshot do
|
|
80
93
|
expect(resources.first.content).to be_nil
|
81
94
|
expect(resources.first.path).to eq(paths.first)
|
82
95
|
end
|
96
|
+
it 'correctly strips the prefix from resource_url' do
|
97
|
+
paths = [File.join(root_dir, 'index.html')]
|
98
|
+
options = {baseurl: '/', strip_prefix: root_dir_relative, is_root: true}
|
99
|
+
resources = Percy::Cli.new.send(:list_resources, paths, options)
|
100
|
+
|
101
|
+
expect(resources.length).to eq(1)
|
102
|
+
expect(resources.first.resource_url).to eq('/index.html')
|
103
|
+
end
|
83
104
|
it 'returns resource objects with is_root set if given' do
|
84
105
|
paths = [File.join(root_dir, 'index.html')]
|
85
106
|
options = {baseurl: '/', strip_prefix: root_dir, is_root: true}
|
86
|
-
resources = Percy::Cli.new.send(:
|
107
|
+
resources = Percy::Cli.new.send(:list_resources, paths, options)
|
87
108
|
|
88
109
|
expect(resources.length).to eq(1)
|
89
110
|
expect(resources.first.resource_url).to eq('/index.html')
|
@@ -95,7 +116,7 @@ RSpec.describe Percy::Cli::Snapshot do
|
|
95
116
|
it 'encodes the resource_url' do
|
96
117
|
paths = [File.join(root_dir, 'css/test with spaces.css')]
|
97
118
|
options = {baseurl: '/', strip_prefix: root_dir}
|
98
|
-
resources = Percy::Cli.new.send(:
|
119
|
+
resources = Percy::Cli.new.send(:list_resources, paths, options)
|
99
120
|
|
100
121
|
expect(resources.length).to eq(1)
|
101
122
|
expect(resources.first.resource_url).to eq('/css/test%20with%20spaces.css')
|
@@ -107,7 +128,7 @@ RSpec.describe Percy::Cli::Snapshot do
|
|
107
128
|
it 'prepends the baseurl if given' do
|
108
129
|
paths = [File.join(root_dir, 'index.html')]
|
109
130
|
options = {strip_prefix: root_dir, is_root: true, baseurl: '/test baseurl/'}
|
110
|
-
resources = Percy::Cli.new.send(:
|
131
|
+
resources = Percy::Cli.new.send(:list_resources, paths, options)
|
111
132
|
|
112
133
|
expect(resources.length).to eq(1)
|
113
134
|
expect(resources.first.resource_url).to eq('/test%20baseurl/index.html')
|
Binary file
|
@@ -0,0 +1 @@
|
|
1
|
+
<!DOCTYPE html><html>Hello World!</html>
|
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: 1.2.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Perceptual Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-03-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commander
|
@@ -132,9 +132,11 @@ files:
|
|
132
132
|
- spec/percy/cli/testdata/css/base.css
|
133
133
|
- spec/percy/cli/testdata/css/test with spaces.css
|
134
134
|
- spec/percy/cli/testdata/css/unrelated-no-extension
|
135
|
+
- spec/percy/cli/testdata/images/jellybeans-symlink.png
|
135
136
|
- spec/percy/cli/testdata/images/jellybeans.png
|
136
137
|
- spec/percy/cli/testdata/index.html
|
137
138
|
- spec/percy/cli/testdata/subdir/test.html
|
139
|
+
- spec/percy/cli/testdata/subdir/test_symlink.html
|
138
140
|
- spec/spec_helper.rb
|
139
141
|
homepage: ''
|
140
142
|
licenses:
|
@@ -165,7 +167,9 @@ test_files:
|
|
165
167
|
- spec/percy/cli/testdata/css/base.css
|
166
168
|
- spec/percy/cli/testdata/css/test with spaces.css
|
167
169
|
- spec/percy/cli/testdata/css/unrelated-no-extension
|
170
|
+
- spec/percy/cli/testdata/images/jellybeans-symlink.png
|
168
171
|
- spec/percy/cli/testdata/images/jellybeans.png
|
169
172
|
- spec/percy/cli/testdata/index.html
|
170
173
|
- spec/percy/cli/testdata/subdir/test.html
|
174
|
+
- spec/percy/cli/testdata/subdir/test_symlink.html
|
171
175
|
- spec/spec_helper.rb
|