asset_sync 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +4 -4
- data/CHANGELOG.md +21 -1
- data/README.md +49 -0
- data/asset_sync.gemspec +2 -1
- data/gemfiles/{rails_4_1.gemfile → rails_5_2.gemfile} +1 -1
- data/lib/asset_sync/config.rb +46 -1
- data/lib/asset_sync/multi_mime.rb +5 -0
- data/lib/asset_sync/version.rb +1 -1
- data/lib/tasks/asset_sync.rake +3 -1
- data/spec/unit/multi_mime_spec.rb +47 -0
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8f0a301ff99d58cacb580c68586d0dd58ccea76c4368e605cfec7c97f1ec8207
|
4
|
+
data.tar.gz: 62b5f062c8eec2f700961aa3c1f3b375a5c700c20fd5b795d034a76dda0bc3bf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac1d44af84bbfca4a10dcc6d03346337f90a4944d364b5b4721b20c5e2acd8c21187de149510452f97897b0b36c0351f8647ccfc3fc8da533c275db7d82e6502
|
7
|
+
data.tar.gz: c99b77189e305fab78cb03a0493b85056f707858f5703c27a5a4045a8a174e388c749d50ce9127d23abeddd855b7eff1501b2313c8adf84dbfb815ce52f7ab33
|
data/Appraisals
CHANGED
@@ -1,8 +1,4 @@
|
|
1
1
|
|
2
|
-
appraise "rails_4_1" do
|
3
|
-
gem "rails", "~> 4.1.0"
|
4
|
-
end
|
5
|
-
|
6
2
|
appraise "rails_4_2" do
|
7
3
|
gem "rails", "~> 4.2.0"
|
8
4
|
end
|
@@ -14,3 +10,7 @@ end
|
|
14
10
|
appraise "rails_5_1" do
|
15
11
|
gem "rails", "~> 5.1.0"
|
16
12
|
end
|
13
|
+
|
14
|
+
appraise "rails_5_2" do
|
15
|
+
gem "rails", "~> 5.2.0"
|
16
|
+
end
|
data/CHANGELOG.md
CHANGED
@@ -18,6 +18,25 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|
18
18
|
- Nothing
|
19
19
|
|
20
20
|
|
21
|
+
## [2.5.0] - 2018-10-25
|
22
|
+
|
23
|
+
### Added
|
24
|
+
|
25
|
+
- Add ruby only option `file_ext_to_mime_type_overrides`
|
26
|
+
(https://github.com/AssetSync/asset_sync/pull/374)
|
27
|
+
|
28
|
+
### Changed
|
29
|
+
|
30
|
+
- Start testing against rails 5.2, stop testing against rails 4.2
|
31
|
+
|
32
|
+
### Fixed
|
33
|
+
|
34
|
+
- Only enhance rake task assets:precompile if it's defined
|
35
|
+
(https://github.com/AssetSync/asset_sync/commit/e1eb1a16b06fd39def1759428a2d94733915bbff)
|
36
|
+
- Avoid ruby warning due to "method redefined"
|
37
|
+
(https://github.com/AssetSync/asset_sync/pull/371)
|
38
|
+
|
39
|
+
|
21
40
|
## [2.4.0] - 2017-12-20
|
22
41
|
|
23
42
|
### Added
|
@@ -861,7 +880,8 @@ Changes:
|
|
861
880
|
* Merge branch 'sinatra'
|
862
881
|
|
863
882
|
|
864
|
-
[Unreleased]: https://github.com/AssetSync/asset_sync/compare/v2.
|
883
|
+
[Unreleased]: https://github.com/AssetSync/asset_sync/compare/v2.5.0...HEAD
|
884
|
+
[2.5.0]: https://github.com/AssetSync/asset_sync/compare/v2.4.0...v2.5.0
|
865
885
|
[2.4.0]: https://github.com/AssetSync/asset_sync/compare/v2.3.0...v2.4.0
|
866
886
|
[2.3.0]: https://github.com/AssetSync/asset_sync/compare/v2.2.0...v2.3.0
|
867
887
|
[2.2.0]: https://github.com/AssetSync/asset_sync/compare/v2.1.0...v2.2.0
|
data/README.md
CHANGED
@@ -344,6 +344,24 @@ end
|
|
344
344
|
```
|
345
345
|
The blocks are run when local files are being scanned and uploaded
|
346
346
|
|
347
|
+
##### Config Method `file_ext_to_mime_type_overrides`
|
348
|
+
It's reported that `mime-types` 3.x returns `application/ecmascript` instead of `application/javascript`
|
349
|
+
Such change of mime type might cause some CDN to disable asset compression
|
350
|
+
So this gem has defined a default override for file ext `js` to be mapped to `application/javascript` by default
|
351
|
+
|
352
|
+
To customize the overrides:
|
353
|
+
```ruby
|
354
|
+
AssetSync.configure do |config|
|
355
|
+
# Clear the default overrides
|
356
|
+
config.file_ext_to_mime_type_overrides.clear
|
357
|
+
|
358
|
+
# Add/Edit overrides
|
359
|
+
# Will call `#to_s` for inputs
|
360
|
+
config.file_ext_to_mime_type_overrides.add(:js, :"application/x-javascript")
|
361
|
+
end
|
362
|
+
```
|
363
|
+
The blocks are run when local files are being scanned and uploaded
|
364
|
+
|
347
365
|
#### Fog (Required)
|
348
366
|
* **fog\_provider**: your storage provider *AWS* (S3) or *Rackspace* (Cloud Files) or *Google* (Google Storage) or *AzureRM* (Azure Blob)
|
349
367
|
* **fog\_directory**: your bucket name
|
@@ -523,6 +541,37 @@ namespace :assets do
|
|
523
541
|
end
|
524
542
|
```
|
525
543
|
|
544
|
+
## Webpacker (> 2.0) support
|
545
|
+
|
546
|
+
1. Add webpacker files and disable `run_on_precompile`:
|
547
|
+
```ruby
|
548
|
+
AssetSync.configure do |config|
|
549
|
+
# Disable automatic run on precompile in order to attach to webpacker rake task
|
550
|
+
config.run_on_precompile = false
|
551
|
+
# The block should return an array of file paths
|
552
|
+
config.add_local_file_paths do
|
553
|
+
# Support webpacker assets
|
554
|
+
public_root = Rails.root.join("public")
|
555
|
+
Dir.chdir(public_root) do
|
556
|
+
packs_dir = Webpacker.config.public_output_path.relative_path_from(public_root)
|
557
|
+
Dir[File.join(packs_dir, '/**/**')]
|
558
|
+
end
|
559
|
+
end
|
560
|
+
end
|
561
|
+
```
|
562
|
+
|
563
|
+
2. Add a `asset_sync.rake` in your `lib/tasks` directory that enhances the correct task, otherwise asset_sync runs before `webpacker:compile` does:
|
564
|
+
```
|
565
|
+
if defined?(AssetSync)
|
566
|
+
Rake::Task['webpacker:compile'].enhance do
|
567
|
+
Rake::Task["assets:sync"].invoke
|
568
|
+
end
|
569
|
+
end
|
570
|
+
```
|
571
|
+
|
572
|
+
### Caveat
|
573
|
+
By adding local files outside the normal Rails `assets` directory, the uploading part works, however checking that the asset was previously uploaded is not working because asset_sync is only fetching the files in the `assets` directory on the remote bucket. This will mean additional time used to upload the same assets again on every precompilation.
|
574
|
+
|
526
575
|
## Running the specs
|
527
576
|
|
528
577
|
Make sure you have a .env file with these details:-
|
data/asset_sync.gemspec
CHANGED
@@ -24,7 +24,8 @@ Gem::Specification.new do |s|
|
|
24
24
|
|
25
25
|
s.add_development_dependency "rspec"
|
26
26
|
s.add_development_dependency "bundler"
|
27
|
-
|
27
|
+
|
28
|
+
s.add_development_dependency('mime-types', ">= 3.0")
|
28
29
|
|
29
30
|
s.add_development_dependency "fog-aws"
|
30
31
|
s.add_development_dependency "fog-azure-rm"
|
@@ -5,6 +5,6 @@ source "https://rubygems.org"
|
|
5
5
|
gem "rcov", platforms: :mri_18, group: [:development, :test]
|
6
6
|
gem "simplecov", platforms: [:jruby, :mri_19, :ruby_19, :mri_20, :rbx], group: [:development, :test], require: false
|
7
7
|
gem "jruby-openssl", platform: :jruby
|
8
|
-
gem "rails", "~>
|
8
|
+
gem "rails", "~> 5.2.0"
|
9
9
|
|
10
10
|
gemspec path: "../"
|
data/lib/asset_sync/config.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require "active_model"
|
2
4
|
require "erb"
|
3
5
|
require "yaml"
|
@@ -17,7 +19,6 @@ module AssetSync
|
|
17
19
|
attr_accessor :always_upload
|
18
20
|
attr_accessor :ignored_files
|
19
21
|
attr_accessor :prefix
|
20
|
-
attr_accessor :public_path
|
21
22
|
attr_accessor :enabled
|
22
23
|
attr_accessor :custom_headers
|
23
24
|
attr_accessor :run_on_precompile
|
@@ -25,6 +26,7 @@ module AssetSync
|
|
25
26
|
attr_accessor :cdn_distribution_id
|
26
27
|
attr_accessor :cache_asset_regexps
|
27
28
|
attr_accessor :include_manifest
|
29
|
+
attr_writer :public_path
|
28
30
|
|
29
31
|
# FOG configuration
|
30
32
|
attr_accessor :fog_provider # Currently Supported ['AWS', 'Rackspace']
|
@@ -268,6 +270,11 @@ module AssetSync
|
|
268
270
|
end
|
269
271
|
end
|
270
272
|
|
273
|
+
#@api
|
274
|
+
def file_ext_to_mime_type_overrides
|
275
|
+
@file_ext_to_mime_type_overrides ||= FileExtToMimeTypeOverrides.new
|
276
|
+
end
|
277
|
+
|
271
278
|
private
|
272
279
|
|
273
280
|
# This is a proc to get additional local files paths
|
@@ -277,5 +284,43 @@ module AssetSync
|
|
277
284
|
def default_manifest_directory
|
278
285
|
File.join(::Rails.public_path, assets_prefix)
|
279
286
|
end
|
287
|
+
|
288
|
+
|
289
|
+
# @api private
|
290
|
+
class FileExtToMimeTypeOverrides
|
291
|
+
def initialize
|
292
|
+
# The default is to prevent new mime type `application/ecmascript` to be returned
|
293
|
+
# which disables compression on some CDNs
|
294
|
+
@overrides = {
|
295
|
+
"js" => "application/javascript",
|
296
|
+
}
|
297
|
+
end
|
298
|
+
|
299
|
+
# @api
|
300
|
+
def add(ext, mime_type)
|
301
|
+
# Symbol / Mime type object might be passed in
|
302
|
+
# But we want strings only
|
303
|
+
@overrides.store(
|
304
|
+
ext.to_s, mime_type.to_s,
|
305
|
+
)
|
306
|
+
end
|
307
|
+
|
308
|
+
# @api
|
309
|
+
def clear
|
310
|
+
@overrides = {}
|
311
|
+
end
|
312
|
+
|
313
|
+
|
314
|
+
# @api private
|
315
|
+
def key?(key)
|
316
|
+
@overrides.key?(key)
|
317
|
+
end
|
318
|
+
|
319
|
+
# @api private
|
320
|
+
def fetch(key)
|
321
|
+
@overrides.fetch(key)
|
322
|
+
end
|
323
|
+
|
324
|
+
end
|
280
325
|
end
|
281
326
|
end
|
data/lib/asset_sync/version.rb
CHANGED
data/lib/tasks/asset_sync.rake
CHANGED
@@ -19,7 +19,7 @@ if Rake::Task.task_defined?("assets:precompile:nondigest")
|
|
19
19
|
# will get executed before yaml or Rails initializers.
|
20
20
|
Rake::Task["assets:sync"].invoke if defined?(AssetSync) && AssetSync.config.run_on_precompile
|
21
21
|
end
|
22
|
-
|
22
|
+
elsif Rake::Task.task_defined?("assets:precompile")
|
23
23
|
Rake::Task["assets:precompile"].enhance do
|
24
24
|
# rails 3.1.1 will clear out Rails.application.config if the env vars
|
25
25
|
# RAILS_GROUP and RAILS_ENV are not defined. We need to reload the
|
@@ -27,4 +27,6 @@ else
|
|
27
27
|
# Rake::Task["assets:environment"].invoke if Rake::Task.task_defined?("assets:environment")
|
28
28
|
Rake::Task["assets:sync"].invoke if defined?(AssetSync) && AssetSync.config.run_on_precompile
|
29
29
|
end
|
30
|
+
else
|
31
|
+
# Nothing to be enhanced
|
30
32
|
end
|
@@ -36,6 +36,8 @@ describe AssetSync::MultiMime do
|
|
36
36
|
$".grep(/mime\//).each do |file_path|
|
37
37
|
$".delete(file_path)
|
38
38
|
end
|
39
|
+
|
40
|
+
AssetSync.config = AssetSync::Config.new
|
39
41
|
end
|
40
42
|
|
41
43
|
after(:all) do
|
@@ -69,4 +71,49 @@ describe AssetSync::MultiMime do
|
|
69
71
|
|
70
72
|
end
|
71
73
|
|
74
|
+
describe "use of option file_ext_to_mime_type_overrides" do
|
75
|
+
before(:each) do
|
76
|
+
require 'mime/types'
|
77
|
+
end
|
78
|
+
|
79
|
+
context "with default value" do
|
80
|
+
it "should return default value set by gem" do
|
81
|
+
expect(
|
82
|
+
AssetSync::MultiMime.lookup("js").to_s,
|
83
|
+
).to eq("application/javascript")
|
84
|
+
end
|
85
|
+
end
|
86
|
+
context "with empty value" do
|
87
|
+
before(:each) do
|
88
|
+
AssetSync.config = AssetSync::Config.new
|
89
|
+
AssetSync.configure do |config|
|
90
|
+
config.file_ext_to_mime_type_overrides.clear
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
it "should return value from mime-types gem" do
|
95
|
+
expect(
|
96
|
+
AssetSync::MultiMime.lookup("js").to_s,
|
97
|
+
).to eq(::MIME::Types.type_for("js").first.to_s)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
context "with custom value" do
|
101
|
+
before(:each) do
|
102
|
+
AssetSync.config = AssetSync::Config.new
|
103
|
+
AssetSync.configure do |config|
|
104
|
+
config.file_ext_to_mime_type_overrides.add(
|
105
|
+
:js,
|
106
|
+
:"application/x-javascript",
|
107
|
+
)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
it "should return custom value" do
|
112
|
+
expect(
|
113
|
+
AssetSync::MultiMime.lookup("js").to_s,
|
114
|
+
).to eq("application/x-javascript")
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
72
119
|
end
|
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.5.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:
|
14
|
+
date: 2018-10-25 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: fog-core
|
@@ -98,19 +98,19 @@ dependencies:
|
|
98
98
|
- !ruby/object:Gem::Version
|
99
99
|
version: '0'
|
100
100
|
- !ruby/object:Gem::Dependency
|
101
|
-
name:
|
101
|
+
name: mime-types
|
102
102
|
requirement: !ruby/object:Gem::Requirement
|
103
103
|
requirements:
|
104
104
|
- - ">="
|
105
105
|
- !ruby/object:Gem::Version
|
106
|
-
version: '0'
|
106
|
+
version: '3.0'
|
107
107
|
type: :development
|
108
108
|
prerelease: false
|
109
109
|
version_requirements: !ruby/object:Gem::Requirement
|
110
110
|
requirements:
|
111
111
|
- - ">="
|
112
112
|
- !ruby/object:Gem::Version
|
113
|
-
version: '0'
|
113
|
+
version: '3.0'
|
114
114
|
- !ruby/object:Gem::Dependency
|
115
115
|
name: fog-aws
|
116
116
|
requirement: !ruby/object:Gem::Requirement
|
@@ -189,10 +189,10 @@ files:
|
|
189
189
|
- UPGRADING.md
|
190
190
|
- asset_sync.gemspec
|
191
191
|
- docs/heroku.md
|
192
|
-
- gemfiles/rails_4_1.gemfile
|
193
192
|
- gemfiles/rails_4_2.gemfile
|
194
193
|
- gemfiles/rails_5_0.gemfile
|
195
194
|
- gemfiles/rails_5_1.gemfile
|
195
|
+
- gemfiles/rails_5_2.gemfile
|
196
196
|
- lib/asset_sync.rb
|
197
197
|
- lib/asset_sync/asset_sync.rb
|
198
198
|
- lib/asset_sync/config.rb
|
@@ -242,7 +242,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
242
242
|
version: '0'
|
243
243
|
requirements: []
|
244
244
|
rubyforge_project: asset_sync
|
245
|
-
rubygems_version: 2.7.
|
245
|
+
rubygems_version: 2.7.7
|
246
246
|
signing_key:
|
247
247
|
specification_version: 4
|
248
248
|
summary: Synchronises Assets in a Rails 3 application and Amazon S3/Cloudfront and
|