percy-cli 0.2.0 → 0.2.1
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 +11 -4
- data/lib/percy/cli/version.rb +1 -1
- data/lib/percy/cli.rb +6 -0
- data/spec/percy/cli/snapshot_spec.rb +18 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: caa2b62dccd292c0e266963747b0a97d6d847422
|
4
|
+
data.tar.gz: 25c5d6de30979ea5aee24e2123255f072515bc29
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50dfa8bfd63712646e7194f850bca142c48e21c0e038b3a969b0d0d61aa993868e7b6befccca972959ddf779b395eaec58fa4a4a250262fd6b92ec045fe43c98
|
7
|
+
data.tar.gz: a7c9084be4c0dea839901c0894361467a586c09148c2bc81f45748bf5530d849aab7ec38d19335a58e6f088101f3976aa8b5d858070a14fc5f657cf082bf2e5f
|
data/lib/percy/cli/snapshot.rb
CHANGED
@@ -21,12 +21,16 @@ module Percy
|
|
21
21
|
strip_prefix = File.absolute_path(options[:strip_prefix] || root_dir)
|
22
22
|
num_threads = options[:threads] || 10
|
23
23
|
snapshot_limit = options[:snapshot_limit]
|
24
|
+
baseurl = options[:baseurl] || '/'
|
25
|
+
raise ArgumentError.new('baseurl must start with /') if baseurl[0] != '/'
|
26
|
+
|
27
|
+
base_resource_options = {strip_prefix: strip_prefix, baseurl: baseurl}
|
24
28
|
|
25
29
|
# Find all the static files in the given root directory.
|
26
30
|
root_paths = find_root_paths(root_dir, snapshots_regex: options[:snapshots_regex])
|
27
31
|
resource_paths = find_resource_paths(root_dir)
|
28
|
-
root_resources = build_resources(root_paths,
|
29
|
-
related_resources = build_resources(resource_paths,
|
32
|
+
root_resources = build_resources(root_paths, base_resource_options.merge(is_root: true))
|
33
|
+
related_resources = build_resources(resource_paths, base_resource_options)
|
30
34
|
all_resources = root_resources + related_resources
|
31
35
|
|
32
36
|
if root_resources.empty?
|
@@ -103,7 +107,9 @@ module Percy
|
|
103
107
|
url[0..1] == '//' ? "http:#{url}" : url
|
104
108
|
end
|
105
109
|
|
106
|
-
def build_resources(paths,
|
110
|
+
def build_resources(paths, options = {})
|
111
|
+
strip_prefix = options[:strip_prefix]
|
112
|
+
baseurl = options[:baseurl]
|
107
113
|
resources = []
|
108
114
|
|
109
115
|
# Strip trailing slash from strip_prefix.
|
@@ -111,7 +117,8 @@ module Percy
|
|
111
117
|
|
112
118
|
paths.each do |path|
|
113
119
|
sha = Digest::SHA256.hexdigest(File.read(path))
|
114
|
-
resource_url = URI.escape(path.sub(strip_prefix, ''))
|
120
|
+
resource_url = URI.escape(File.join(baseurl, path.sub(strip_prefix, '')))
|
121
|
+
|
115
122
|
resources << Percy::Client::Resource.new(
|
116
123
|
resource_url, sha: sha, is_root: options[:is_root], path: path)
|
117
124
|
end
|
data/lib/percy/cli/version.rb
CHANGED
data/lib/percy/cli.rb
CHANGED
@@ -29,6 +29,12 @@ module Percy
|
|
29
29
|
command :snapshot do |c|
|
30
30
|
c.syntax = 'snapshot <root_dir>'
|
31
31
|
c.description = 'Snapshot a folder of static files.'
|
32
|
+
c.option \
|
33
|
+
'--baseurl PATH',
|
34
|
+
String,
|
35
|
+
'The live URL base path. Defaults to "/". Set this if your site is hosted in ' +
|
36
|
+
'a subdirectory in production that does not exist locally. If using Jekyll, this ' +
|
37
|
+
'should be the same as your "baseurl" config.'
|
32
38
|
c.option \
|
33
39
|
'--strip_prefix PATH',
|
34
40
|
String,
|
@@ -30,7 +30,8 @@ RSpec.describe Percy::Cli::Snapshot do
|
|
30
30
|
describe '#build_resources' do
|
31
31
|
it 'returns resource objects' do
|
32
32
|
paths = [File.join(root_dir, 'css/base.css')]
|
33
|
-
|
33
|
+
options = {baseurl: '/', strip_prefix: root_dir}
|
34
|
+
resources = Percy::Cli.new.send(:build_resources, paths, options)
|
34
35
|
|
35
36
|
expect(resources.length).to eq(1)
|
36
37
|
expect(resources.first.sha).to eq(Digest::SHA256.hexdigest(File.read(paths.first)))
|
@@ -40,7 +41,8 @@ RSpec.describe Percy::Cli::Snapshot do
|
|
40
41
|
end
|
41
42
|
it 'returns resource objects with is_root set if given' do
|
42
43
|
paths = [File.join(root_dir, 'index.html')]
|
43
|
-
|
44
|
+
options = {baseurl: '/', strip_prefix: root_dir, is_root: true}
|
45
|
+
resources = Percy::Cli.new.send(:build_resources, paths, options)
|
44
46
|
|
45
47
|
expect(resources.length).to eq(1)
|
46
48
|
expect(resources.first.resource_url).to eq('/index.html')
|
@@ -51,7 +53,8 @@ RSpec.describe Percy::Cli::Snapshot do
|
|
51
53
|
end
|
52
54
|
it 'encodes the resource_url' do
|
53
55
|
paths = [File.join(root_dir, 'css/test with spaces.css')]
|
54
|
-
|
56
|
+
options = {baseurl: '/', strip_prefix: root_dir}
|
57
|
+
resources = Percy::Cli.new.send(:build_resources, paths, options)
|
55
58
|
|
56
59
|
expect(resources.length).to eq(1)
|
57
60
|
expect(resources.first.resource_url).to eq('/css/test%20with%20spaces.css')
|
@@ -60,6 +63,18 @@ RSpec.describe Percy::Cli::Snapshot do
|
|
60
63
|
expect(resources.first.content).to be_nil
|
61
64
|
expect(resources.first.path).to eq(paths.first)
|
62
65
|
end
|
66
|
+
it 'prepends the baseurl if given' do
|
67
|
+
paths = [File.join(root_dir, 'index.html')]
|
68
|
+
options = {strip_prefix: root_dir, is_root: true, baseurl: '/test baseurl/'}
|
69
|
+
resources = Percy::Cli.new.send(:build_resources, paths, options)
|
70
|
+
|
71
|
+
expect(resources.length).to eq(1)
|
72
|
+
expect(resources.first.resource_url).to eq('/test%20baseurl/index.html')
|
73
|
+
expect(resources.first.sha).to eq(Digest::SHA256.hexdigest(File.read(paths.first)))
|
74
|
+
expect(resources.first.is_root).to be_truthy
|
75
|
+
expect(resources.first.content).to be_nil
|
76
|
+
expect(resources.first.path).to eq(paths.first)
|
77
|
+
end
|
63
78
|
end
|
64
79
|
describe '#upload_snapshot' do
|
65
80
|
xit 'uploads the given resources to the build' do
|
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.2.
|
4
|
+
version: 0.2.1
|
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-
|
11
|
+
date: 2015-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: commander
|