asset_sync 2.1.0 → 2.2.0
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 +4 -4
- data/.editorconfig +7 -0
- data/CHANGELOG.md +19 -1
- data/README.md +14 -1
- data/lib/asset_sync/config.rb +24 -0
- data/lib/asset_sync/storage.rb +10 -4
- data/lib/asset_sync/version.rb +1 -1
- data/spec/unit/storage_spec.rb +88 -11
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5b188551b31d31cea82d0a2daa66ea13611526bf
|
4
|
+
data.tar.gz: 8dc71ab706a8da82c83030d1c0bcabe88d44e4d4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4666031ff720620d925adbfee0e5213abd28c96e2df89f37af6e88dfd96d76e3b439e4a0e52c373243ea5452078218b07afaacc86f4b35f8fdeed8fa660c37f9
|
7
|
+
data.tar.gz: bef8d1ecde9c3bb946016db35ec7f558b9dea0f51a96bb19a727f03d2560688b48901720a3d2e102cf1aad2e5b3a617021e1cdc2e37bb502912dbbb36c9ef422
|
data/.editorconfig
ADDED
data/CHANGELOG.md
CHANGED
@@ -18,6 +18,23 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
18
18
|
- Nothing
|
19
19
|
|
20
20
|
|
21
|
+
## [2.2.0] - 2016-07-12
|
22
|
+
|
23
|
+
### Added
|
24
|
+
|
25
|
+
- Add method `add_local_file_paths` to config for uploading additional files, like webpacker
|
26
|
+
(https://github.com/AssetSync/asset_sync/pull/347)
|
27
|
+
|
28
|
+
### Changed
|
29
|
+
|
30
|
+
- Nothing
|
31
|
+
|
32
|
+
### Fixed
|
33
|
+
|
34
|
+
- Fix too many files open when uploading local files
|
35
|
+
(https://github.com/AssetSync/asset_sync/pull/351)
|
36
|
+
|
37
|
+
|
21
38
|
## [2.1.0] - 2016-05-19
|
22
39
|
|
23
40
|
### Added
|
@@ -813,7 +830,8 @@ Changes:
|
|
813
830
|
* Merge branch 'sinatra'
|
814
831
|
|
815
832
|
|
816
|
-
[Unreleased]: https://github.com/AssetSync/asset_sync/compare/v2.
|
833
|
+
[Unreleased]: https://github.com/AssetSync/asset_sync/compare/v2.2.0...HEAD
|
834
|
+
[2.2.0]: https://github.com/AssetSync/asset_sync/compare/v2.1.0...v2.2.0
|
817
835
|
[2.1.0]: https://github.com/AssetSync/asset_sync/compare/v2.0.0...v2.1.0
|
818
836
|
[2.0.0]: https://github.com/AssetSync/asset_sync/compare/v1.3.0...v2.0.0
|
819
837
|
[1.3.0]: https://github.com/AssetSync/asset_sync/compare/v1.2.1...v1.3.0
|
data/README.md
CHANGED
@@ -253,7 +253,7 @@ production:
|
|
253
253
|
|
254
254
|
### Available Configuration Options
|
255
255
|
|
256
|
-
|
256
|
+
Most AssetSync configuration can be modified directly using environment variables with the **Built-in initializer**. e.g.
|
257
257
|
|
258
258
|
```ruby
|
259
259
|
AssetSync.config.fog_provider == ENV['FOG_PROVIDER']
|
@@ -274,6 +274,19 @@ AssetSync.config.gzip_compression == ENV['ASSET_SYNC_GZIP_COMPRESSION']
|
|
274
274
|
* **ignored\_files**: an array of files to ignore e.g. `['ignore_me.js', %r(ignore_some/\d{32}\.css)]` Useful if there are some files that are created dynamically on the server and you don't want to upload on deploy **default**: `[]`
|
275
275
|
* **cache\_asset\_regexps**: an array of files to add cache headers e.g. `['cache_me.js', %r(cache_some\.\d{8}\.css)]` Useful if there are some files that are added to sprockets assets list and need to be set as 'Cacheable' on uploaded server. Only rails compiled regexp is matched internally **default**: `[]`
|
276
276
|
|
277
|
+
##### Config Method `add_local_file_paths`
|
278
|
+
Adding local files by providing a block:
|
279
|
+
```ruby
|
280
|
+
AssetSync.configure do |config|
|
281
|
+
# The block should return an array of file paths
|
282
|
+
config.add_local_file_paths do
|
283
|
+
# Any code that returns paths of local asset files to be uploaded
|
284
|
+
# Like Webpacker
|
285
|
+
Dir[File.join(Webpacker::Configuration.fetch(:public_output_path), '/**/**')]
|
286
|
+
end
|
287
|
+
end
|
288
|
+
```
|
289
|
+
The blocks are run when local files are being scanned and uploaded
|
277
290
|
|
278
291
|
#### Fog (Required)
|
279
292
|
* **fog\_provider**: your storage provider *AWS* (S3) or *Rackspace* (Cloud Files) or *Google* (Google Storage)
|
data/lib/asset_sync/config.rb
CHANGED
@@ -67,6 +67,8 @@ module AssetSync
|
|
67
67
|
self.cdn_distribution_id = nil
|
68
68
|
self.invalidate = []
|
69
69
|
self.cache_asset_regexps = []
|
70
|
+
@additional_local_file_paths_procs = []
|
71
|
+
|
70
72
|
load_yml! if defined?(::Rails) && yml_exists?
|
71
73
|
end
|
72
74
|
|
@@ -220,8 +222,30 @@ module AssetSync
|
|
220
222
|
return options
|
221
223
|
end
|
222
224
|
|
225
|
+
# @api
|
226
|
+
def add_local_file_paths(&block)
|
227
|
+
@additional_local_file_paths_procs =
|
228
|
+
additional_local_file_paths_procs + [block]
|
229
|
+
end
|
230
|
+
|
231
|
+
# @api private
|
232
|
+
# This is to be called in Storage
|
233
|
+
# Not to be called by user
|
234
|
+
def additional_local_file_paths
|
235
|
+
return [] if additional_local_file_paths_procs.empty?
|
236
|
+
|
237
|
+
# Using `Array()` to ensure it works when single value is returned
|
238
|
+
additional_local_file_paths_procs.each_with_object([]) do |proc, paths|
|
239
|
+
paths.concat(Array(proc.call))
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
223
243
|
private
|
224
244
|
|
245
|
+
# This is a proc to get additional local files paths
|
246
|
+
# Since this is a proc it won't be able to be configured by a YAML file
|
247
|
+
attr_reader :additional_local_file_paths_procs
|
248
|
+
|
225
249
|
def default_manifest_directory
|
226
250
|
File.join(::Rails.public_path, assets_prefix)
|
227
251
|
end
|
data/lib/asset_sync/storage.rb
CHANGED
@@ -42,7 +42,8 @@ module AssetSync
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def local_files
|
45
|
-
@local_files ||=
|
45
|
+
@local_files ||=
|
46
|
+
(get_local_files + config.additional_local_file_paths).uniq
|
46
47
|
end
|
47
48
|
|
48
49
|
def always_upload_files
|
@@ -120,9 +121,11 @@ module AssetSync
|
|
120
121
|
one_year = 31557600
|
121
122
|
ext = File.extname(f)[1..-1]
|
122
123
|
mime = MultiMime.lookup(ext)
|
124
|
+
gzip_file_handle = nil
|
125
|
+
file_handle = File.open("#{path}/#{f}")
|
123
126
|
file = {
|
124
127
|
:key => f,
|
125
|
-
:body =>
|
128
|
+
:body => file_handle,
|
126
129
|
:public => true,
|
127
130
|
:content_type => mime
|
128
131
|
}
|
@@ -167,9 +170,10 @@ module AssetSync
|
|
167
170
|
|
168
171
|
if gzipped_size < original_size
|
169
172
|
percentage = ((gzipped_size.to_f/original_size.to_f)*100).round(2)
|
173
|
+
gzip_file_handle = File.open(gzipped)
|
170
174
|
file.merge!({
|
171
175
|
:key => f,
|
172
|
-
:body =>
|
176
|
+
:body => gzip_file_handle,
|
173
177
|
:content_encoding => 'gzip'
|
174
178
|
})
|
175
179
|
log "Uploading: #{gzipped} in place of #{f} saving #{percentage}%"
|
@@ -198,7 +202,9 @@ module AssetSync
|
|
198
202
|
})
|
199
203
|
end
|
200
204
|
|
201
|
-
|
205
|
+
bucket.files.create( file ) unless ignore
|
206
|
+
file_handle.close
|
207
|
+
gzip_file_handle.close if gzip_file_handle
|
202
208
|
end
|
203
209
|
|
204
210
|
def upload_files
|
data/lib/asset_sync/version.rb
CHANGED
data/spec/unit/storage_spec.rb
CHANGED
@@ -3,6 +3,10 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|
3
3
|
describe AssetSync::Storage do
|
4
4
|
include_context "mock Rails without_yml"
|
5
5
|
|
6
|
+
let(:file_like_object) do
|
7
|
+
double("file like object").as_null_object
|
8
|
+
end
|
9
|
+
|
6
10
|
describe '#upload_files' do
|
7
11
|
before(:each) do
|
8
12
|
@local_files = ["local_image2.jpg", "local_image1.jpg", "local_stylesheet1.css", "local_stylesheet2.css"]
|
@@ -13,7 +17,7 @@ describe AssetSync::Storage do
|
|
13
17
|
it 'should overwrite all remote files if set to ignore' do
|
14
18
|
@config.existing_remote_files = 'ignore'
|
15
19
|
storage = AssetSync::Storage.new(@config)
|
16
|
-
allow(storage).to receive(:
|
20
|
+
allow(storage).to receive(:get_local_files).and_return(@local_files)
|
17
21
|
allow(File).to receive(:file?).and_return(true) # Pretend they all exist
|
18
22
|
|
19
23
|
@local_files.each do |file|
|
@@ -26,7 +30,7 @@ describe AssetSync::Storage do
|
|
26
30
|
@config.always_upload = ['local_image.jpg', /local_image\d\.svg/]
|
27
31
|
|
28
32
|
storage = AssetSync::Storage.new(@config)
|
29
|
-
allow(storage).to receive(:
|
33
|
+
allow(storage).to receive(:get_local_files).and_return(@local_files)
|
30
34
|
allow(storage).to receive(:get_remote_files).and_return(@remote_files)
|
31
35
|
allow(File).to receive(:file?).and_return(true) # Pretend they all exist
|
32
36
|
|
@@ -40,7 +44,7 @@ describe AssetSync::Storage do
|
|
40
44
|
@config.ignored_files = ['local_image1.jpg', /local_stylesheet\d\.css/]
|
41
45
|
|
42
46
|
storage = AssetSync::Storage.new(@config)
|
43
|
-
allow(storage).to receive(:
|
47
|
+
allow(storage).to receive(:get_local_files).and_return(@local_files)
|
44
48
|
allow(storage).to receive(:get_remote_files).and_return(@remote_files)
|
45
49
|
allow(File).to receive(:file?).and_return(true) # Pretend they all exist
|
46
50
|
|
@@ -68,7 +72,78 @@ describe AssetSync::Storage do
|
|
68
72
|
]
|
69
73
|
|
70
74
|
storage = AssetSync::Storage.new(@config)
|
71
|
-
allow(storage).to receive(:
|
75
|
+
allow(storage).to receive(:get_local_files).and_return(@local_files)
|
76
|
+
allow(storage).to receive(:get_remote_files).and_return(@remote_files)
|
77
|
+
allow(File).to receive(:file?).and_return(true) # Pretend they all exist
|
78
|
+
|
79
|
+
updated_nonfingerprinted_files = [
|
80
|
+
'public/image.png',
|
81
|
+
'public/application.js',
|
82
|
+
]
|
83
|
+
(@local_files - @remote_files + updated_nonfingerprinted_files).each do |file|
|
84
|
+
expect(storage).to receive(:upload_file).with(file)
|
85
|
+
end
|
86
|
+
storage.upload_files
|
87
|
+
end
|
88
|
+
|
89
|
+
context "when config #add_local_file_paths is called" do
|
90
|
+
let(:additional_local_file_paths) do
|
91
|
+
["webpack/example_asset.jpg"]
|
92
|
+
end
|
93
|
+
|
94
|
+
before(:each) do
|
95
|
+
@config.add_local_file_paths do
|
96
|
+
additional_local_file_paths
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
let(:storage) do
|
101
|
+
AssetSync::Storage.new(@config)
|
102
|
+
end
|
103
|
+
|
104
|
+
let(:file_paths_should_be_uploaded) do
|
105
|
+
@local_files -
|
106
|
+
@remote_files -
|
107
|
+
storage.ignored_files +
|
108
|
+
storage.always_upload_files +
|
109
|
+
additional_local_file_paths
|
110
|
+
end
|
111
|
+
|
112
|
+
before do
|
113
|
+
# Stubbing
|
114
|
+
allow(storage).to receive(:get_local_files).and_return(@local_files)
|
115
|
+
allow(storage).to receive(:get_remote_files).and_return(@remote_files)
|
116
|
+
# Pretend the files all exist
|
117
|
+
allow(File).to receive(:file?).and_return(true)
|
118
|
+
end
|
119
|
+
|
120
|
+
it "uploads additional files in additional to local files" do
|
121
|
+
file_paths_should_be_uploaded.each do |file|
|
122
|
+
expect(storage).to receive(:upload_file).with(file)
|
123
|
+
end
|
124
|
+
storage.upload_files
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
it 'should upload additonal files' do
|
129
|
+
@local_files = [
|
130
|
+
'public/image.png',
|
131
|
+
'public/image-82389298328.png',
|
132
|
+
'public/image-a8389f9h324.png',
|
133
|
+
'public/application.js',
|
134
|
+
'public/application-b3389d983k1.js',
|
135
|
+
'public/application-ac387d53f31.js',
|
136
|
+
'public',
|
137
|
+
]
|
138
|
+
@remote_files = [
|
139
|
+
'public/image.png',
|
140
|
+
'public/image-a8389f9h324.png',
|
141
|
+
'public/application.js',
|
142
|
+
'public/application-b3389d983k1.js',
|
143
|
+
]
|
144
|
+
|
145
|
+
storage = AssetSync::Storage.new(@config)
|
146
|
+
allow(storage).to receive(:get_local_files).and_return(@local_files)
|
72
147
|
allow(storage).to receive(:get_remote_files).and_return(@remote_files)
|
73
148
|
allow(File).to receive(:file?).and_return(true) # Pretend they all exist
|
74
149
|
|
@@ -110,10 +185,10 @@ describe AssetSync::Storage do
|
|
110
185
|
remote_files = []
|
111
186
|
@config.cache_asset_regexps = [/\.[a-f0-9]{6}$/i, /\.[a-f0-9]{8}$/i]
|
112
187
|
storage = AssetSync::Storage.new(@config)
|
113
|
-
allow(storage).to receive(:
|
188
|
+
allow(storage).to receive(:get_local_files).and_return(local_files)
|
114
189
|
allow(storage).to receive(:get_remote_files).and_return(remote_files)
|
115
190
|
allow(File).to receive(:file?).and_return(true)
|
116
|
-
allow(File).to receive(:open).and_return(
|
191
|
+
allow(File).to receive(:open).and_return(file_like_object)
|
117
192
|
|
118
193
|
def check_file(file)
|
119
194
|
case file[:key]
|
@@ -155,7 +230,7 @@ describe AssetSync::Storage do
|
|
155
230
|
@config.fog_provider = 'AWS'
|
156
231
|
|
157
232
|
storage = AssetSync::Storage.new(@config)
|
158
|
-
allow(storage).to receive(:
|
233
|
+
allow(storage).to receive(:get_local_files).and_return(@local_files)
|
159
234
|
allow(storage).to receive(:get_remote_files).and_return(@remote_files)
|
160
235
|
allow(storage).to receive(:upload_file).and_return(true)
|
161
236
|
|
@@ -193,9 +268,10 @@ describe AssetSync::Storage do
|
|
193
268
|
}
|
194
269
|
}
|
195
270
|
storage = AssetSync::Storage.new(@config)
|
196
|
-
allow(storage).to receive(:
|
271
|
+
allow(storage).to receive(:get_local_files).and_return(@local_files)
|
197
272
|
allow(storage).to receive(:get_remote_files).and_return(@remote_files)
|
198
|
-
|
273
|
+
# Pretend they all exist
|
274
|
+
allow(File).to receive(:open).and_return(file_like_object)
|
199
275
|
|
200
276
|
bucket = double
|
201
277
|
files = double
|
@@ -216,9 +292,10 @@ describe AssetSync::Storage do
|
|
216
292
|
}
|
217
293
|
}
|
218
294
|
storage = AssetSync::Storage.new(@config)
|
219
|
-
allow(storage).to receive(:
|
295
|
+
allow(storage).to receive(:get_local_files).and_return(@local_files)
|
220
296
|
allow(storage).to receive(:get_remote_files).and_return(@remote_files)
|
221
|
-
|
297
|
+
# Pretend they all exist
|
298
|
+
allow(File).to receive(:open).and_return(file_like_object)
|
222
299
|
bucket = double
|
223
300
|
files = double
|
224
301
|
allow(storage).to receive(:bucket).and_return(bucket)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: asset_sync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Hamilton
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date: 2017-
|
14
|
+
date: 2017-07-12 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: fog-core
|
@@ -164,6 +164,7 @@ executables: []
|
|
164
164
|
extensions: []
|
165
165
|
extra_rdoc_files: []
|
166
166
|
files:
|
167
|
+
- ".editorconfig"
|
167
168
|
- ".gitignore"
|
168
169
|
- ".travis.yml"
|
169
170
|
- Appraisals
|