webpacker_uploader 0.1.0 → 0.5.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.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WebpackerUploader
2
- VERSION = "0.1.0"
4
+ VERSION = "0.5.0"
3
5
  end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class ConfigurationTest < Minitest::Test
6
+ def setup
7
+ @config = WebpackerUploader::Configuration.new
8
+ end
9
+
10
+ def teardown
11
+ WebpackerUploader.reset!
12
+ end
13
+
14
+ def test_default_config_options
15
+ assert_empty @config.ignored_extensions
16
+
17
+ assert_instance_of ActiveSupport::Logger, @config.logger
18
+
19
+ assert @config.log_output
20
+ assert @config.log_output?
21
+
22
+ public_manifest_path = Pathname.new(File.expand_path("test_app/public/packs/manifest.json", __dir__))
23
+ assert_equal public_manifest_path, @config.public_manifest_path
24
+
25
+ public_path = Pathname.new(File.expand_path("test_app/public/", __dir__))
26
+ assert_equal public_path, @config.public_path
27
+ end
28
+
29
+ def test_changing_config_options
30
+ @config.ignored_extensions = [".css", ".js"]
31
+ assert_equal [".css", ".js"], @config.ignored_extensions
32
+
33
+ @config.logger = Logger.new(STDOUT)
34
+ assert_instance_of Logger, @config.logger
35
+
36
+ @config.log_output = false
37
+ refute @config.log_output
38
+ refute @config.log_output?
39
+
40
+ @config.public_manifest_path = "test_app/manifest.json"
41
+ assert_equal "test_app/manifest.json", @config.public_manifest_path.to_s
42
+
43
+ @config.public_path = "test_app"
44
+ assert_equal "test_app", @config.public_path.to_s
45
+ end
46
+
47
+ def test_configure_block
48
+ WebpackerUploader.configure do |c|
49
+ c.ignored_extensions = [".js"]
50
+ c.logger = Logger.new(STDOUT)
51
+ c.log_output = false
52
+ c.public_manifest_path = "path/to/manifest.json"
53
+ c.public_path = "path/to/public/dir"
54
+ end
55
+
56
+ assert_equal [".js"], WebpackerUploader.config.ignored_extensions
57
+ assert_instance_of Logger, WebpackerUploader.config.logger
58
+ refute WebpackerUploader.config.log_output
59
+ refute WebpackerUploader.config.log_output?
60
+ assert_equal "path/to/manifest.json", WebpackerUploader.config.public_manifest_path.to_s
61
+ assert_equal "path/to/public/dir", WebpackerUploader.config.public_path.to_s
62
+
63
+ assert_raises(NoMethodError) do
64
+ WebpackerUploader.configure do |c|
65
+ c.unknown = true
66
+ end
67
+ end
68
+ end
69
+
70
+ def test_pathname_casting
71
+ WebpackerUploader.config do |c|
72
+ c.public_manifest_path = "path/to/manifest.json"
73
+ c.public_path = "path/to/public/dir"
74
+ end
75
+
76
+ assert_instance_of Pathname, WebpackerUploader.config.public_manifest_path
77
+ assert_instance_of Pathname, WebpackerUploader.config.public_path
78
+
79
+ WebpackerUploader.configure do |c|
80
+ c.public_manifest_path = Pathname.new("path/to/manifest.json")
81
+ c.public_path = Pathname.new("path/to/public/dir")
82
+ end
83
+
84
+ assert_instance_of Pathname, WebpackerUploader.config.public_manifest_path
85
+ assert_instance_of Pathname, WebpackerUploader.config.public_path
86
+ end
87
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class ManifestTest < Minitest::Test
6
+ def setup
7
+ @manifest = ::WebpackerUploader::Manifest.new
8
+ end
9
+
10
+ def teardown
11
+ WebpackerUploader.reset!
12
+ end
13
+
14
+ def test_assets
15
+ assert_includes @manifest.assets, "application.css"
16
+ assert_includes @manifest.assets, "application.js"
17
+ assert_includes @manifest.assets, "application.png"
18
+ refute_includes @manifest.assets, "entrypoints"
19
+ end
20
+
21
+ def test_missing_manifest
22
+ WebpackerUploader.config.public_manifest_path = "missing.json"
23
+ @empty_manifest = WebpackerUploader::Manifest.new
24
+
25
+ assert_empty @empty_manifest.assets
26
+ end
27
+ end
data/test/mime_test.rb ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class MimeTest < Minitest::Test
6
+ def test_for_webp
7
+ # Rack < 3.x does not support this so we have a fallback mechanism in place
8
+ assert_equal "image/webp", WebpackerUploader::Mime.mime_type("image-dd6b1cd38bfa093df600.webp")
9
+ end
10
+
11
+ def test_for_sourcemap
12
+ assert_equal "application/octet-stream", WebpackerUploader::Mime.mime_type("application-dd6b1cd38bfa093df600.css.map")
13
+ end
14
+ end
@@ -0,0 +1,103 @@
1
+ # Note: You must restart bin/webpack-dev-server for changes to take effect
2
+
3
+ default: &default
4
+ source_path: app/javascript
5
+ source_entry_path: packs
6
+ public_root_path: public
7
+ public_output_path: packs
8
+ cache_path: tmp/cache/webpacker
9
+ webpack_compile_output: false
10
+
11
+ # Additional paths webpack should lookup modules
12
+ # ['app/assets', 'engine/foo/app/assets']
13
+ additional_paths:
14
+ - app/assets
15
+ - /etc/yarn
16
+
17
+ # This configuration option is deprecated and is only here for testing, to
18
+ # ensure backwards-compatibility. Please use `additional_paths`.
19
+ resolved_paths:
20
+ - app/elm
21
+
22
+ # Reload manifest.json on all requests so we reload latest compiled packs
23
+ cache_manifest: false
24
+
25
+ # Extract and emit a css file
26
+ extract_css: false
27
+
28
+ static_assets_extensions:
29
+ - .jpg
30
+ - .jpeg
31
+ - .png
32
+ - .gif
33
+ - .tiff
34
+ - .ico
35
+ - .svg
36
+
37
+ extensions:
38
+ - .mjs
39
+ - .js
40
+ - .sass
41
+ - .scss
42
+ - .css
43
+ - .module.sass
44
+ - .module.scss
45
+ - .module.css
46
+ - .png
47
+ - .svg
48
+ - .gif
49
+ - .jpeg
50
+ - .jpg
51
+ - .elm
52
+
53
+ development:
54
+ <<: *default
55
+ compile: true
56
+
57
+ # Reference: https://webpack.js.org/configuration/dev-server/
58
+ dev_server:
59
+ https: false
60
+ host: localhost
61
+ port: 3035
62
+ public: localhost:3035
63
+ hmr: false
64
+ # Inline should be set to true if using HMR
65
+ inline: true
66
+ overlay: true
67
+ disable_host_check: true
68
+ use_local_ip: false
69
+ pretty: false
70
+
71
+ test:
72
+ <<: *default
73
+ compile: true
74
+
75
+ # Compile test packs to a separate directory
76
+ public_output_path: packs-test
77
+
78
+ production:
79
+ <<: *default
80
+
81
+ # Production depends on precompilation of packs prior to booting for performance.
82
+ compile: false
83
+
84
+ # Extract and emit a css file
85
+ extract_css: true
86
+
87
+ # Cache manifest.json for performance
88
+ cache_manifest: true
89
+
90
+ staging:
91
+ <<: *default
92
+
93
+ # Production depends on precompilation of packs prior to booting for performance.
94
+ compile: false
95
+
96
+ # Extract and emit a css file
97
+ extract_css: true
98
+
99
+ # Cache manifest.json for performance
100
+ cache_manifest: true
101
+
102
+ # Compile staging packs to a separate directory
103
+ public_output_path: packs-staging
@@ -0,0 +1,33 @@
1
+ {
2
+ "bootstrap.css": "/packs/bootstrap-c38deda30895059837cf.css",
3
+ "application.css": "/packs/application-dd6b1cd38bfa093df600.css",
4
+ "application.css.map": "/packs/application-dd6b1cd38bfa093df600.css.map",
5
+ "bootstrap.js": "/packs/bootstrap-300631c4f0e0f9c865bc.js",
6
+ "application.js": "/packs/application-k344a6d59eef8632c9d1.js",
7
+ "application.png": "/packs/application-k344a6d59eef8632c9d1.png",
8
+ "fonts/fa-regular-400.woff2": "/packs/fonts/fa-regular-400-944fb546bd7018b07190a32244f67dc9.woff2",
9
+ "media/images/image.jpg": "/packs/media/images/image-c38deda30895059837cf.jpg",
10
+ "media/images/image-2x.jpg": "/packs/media/images/image-2x-7cca48e6cae66ec07b8e.jpg",
11
+ "media/images/nested/image.jpg": "/packs/media/images/nested/image-c38deda30895059837cf.jpg",
12
+ "media/images/mb-icon.png": "/packs/media/images/mb-icon-c38deda30895059837cf.png",
13
+ "media/images/nested/mb-icon.png": "/packs/media/images/nested/mb-icon-c38deda30895059837cf.png",
14
+ "entrypoints": {
15
+ "application": {
16
+ "js": [
17
+ "/packs/vendors~application~bootstrap-c20632e7baf2c81200d3.chunk.js",
18
+ "/packs/vendors~application-e55f2aae30c07fb6d82a.chunk.js",
19
+ "/packs/application-k344a6d59eef8632c9d1.js"
20
+ ],
21
+ "css": [
22
+ "/packs/1-c20632e7baf2c81200d3.chunk.css",
23
+ "/packs/application-k344a6d59eef8632c9d1.chunk.css"
24
+ ]
25
+ },
26
+ "hello_stimulus": {
27
+ "css": [
28
+ "/packs/1-c20632e7baf2c81200d3.chunk.css",
29
+ "/packs/hello_stimulus-k344a6d59eef8632c9d1.chunk.css"
30
+ ]
31
+ }
32
+ }
33
+ }
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "minitest/autorun"
4
+ require "rails"
5
+ require "rails/test_help"
6
+ require "webpacker"
7
+ require "webpacker_uploader"
8
+
9
+ module TestApp
10
+ class Application < ::Rails::Application
11
+ config.root = File.join(File.dirname(__FILE__), "test_app")
12
+ config.eager_load = true
13
+ end
14
+ end
15
+
16
+ TestApp::Application.initialize!
17
+
18
+ module WebpackerUploader::Providers
19
+ class TestProvider
20
+ def initialize(asset_objects)
21
+ @asset_objects = asset_objects
22
+ end
23
+
24
+ def upload!(object_key, file, content_type = "")
25
+ @asset_objects << { object_key: object_key, file: file, content_type: content_type }
26
+ end
27
+ end
28
+ end
29
+
30
+ module WebpackerUploader
31
+ def reset!
32
+ WebpackerUploader.instance.config = nil
33
+ end
34
+ module_function :reset!
35
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "test_helper"
4
+
5
+ class WebpackerUploaderTest < Minitest::Test
6
+ def setup
7
+ @asset_objects = []
8
+ @provider = WebpackerUploader::Providers::TestProvider.new(@asset_objects)
9
+
10
+ WebpackerUploader.config.log_output = false
11
+ end
12
+
13
+ def teardown
14
+ WebpackerUploader.reset!
15
+ end
16
+
17
+ def test_upload
18
+ WebpackerUploader.upload!(@provider)
19
+
20
+ assert_equal "packs/bootstrap-c38deda30895059837cf.css", @asset_objects.first[:object_key]
21
+ assert_instance_of Pathname, @asset_objects.first[:file]
22
+ assert_equal "text/css", @asset_objects.first[:content_type]
23
+ end
24
+
25
+ def test_upload_with_prefix
26
+ WebpackerUploader.upload!(@provider, prefix: "prefix")
27
+
28
+ assert_equal "prefix/packs/bootstrap-c38deda30895059837cf.css", @asset_objects.first[:object_key]
29
+ assert_instance_of Pathname, @asset_objects.first[:file]
30
+ assert_equal "text/css", @asset_objects.first[:content_type]
31
+ end
32
+ end
@@ -15,23 +15,21 @@ Gem::Specification.new do |s|
15
15
 
16
16
  s.metadata = {
17
17
  "homepage_uri" => s.homepage,
18
+ "bug_tracker_uri" => "https://github.com/tlatsas/webpacker_uploader/issues",
19
+ "changelog_uri" => "https://github.com/tlatsas/webpacker_uploader/blob/main/CHANGELOG.md",
18
20
  "source_code_uri" => "https://github.com/tlatsas/webpacker_uploader/tree/v#{s.version}"
19
21
  }
20
22
 
21
- # Specify which files should be added to the gem when it is released.
22
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
23
- s.files = Dir.chdir(File.expand_path("..", __FILE__)) do
24
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
25
- end
26
-
27
- s.bindir = "exe"
28
- s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ s.files = `git ls-files`.split("\n").reject { |f| f.match(%r{^(bin|test|.github)/}) }
24
+ s.test_files = `git ls-files -- test/*`.split("\n")
29
25
  s.require_paths = ["lib"]
30
26
 
31
27
  s.add_dependency "webpacker", ">= 5.1"
32
28
  s.add_dependency "mime-types"
29
+ s.add_dependency "rack", "~> 2.0"
33
30
 
34
31
  s.add_development_dependency "bundler", ">= 1.3.0"
35
- s.add_development_dependency "rubocop", "< 0.69"
32
+ s.add_development_dependency "rubocop", "1.11.0"
36
33
  s.add_development_dependency "rubocop-performance"
34
+ s.add_development_dependency "rubocop-minitest"
37
35
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webpacker_uploader
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tasos Latsas
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2020-10-01 00:00:00.000000000 Z
11
+ date: 2021-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: webpacker
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rack
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: bundler
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -56,16 +70,16 @@ dependencies:
56
70
  name: rubocop
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - "<"
73
+ - - '='
60
74
  - !ruby/object:Gem::Version
61
- version: '0.69'
75
+ version: 1.11.0
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - "<"
80
+ - - '='
67
81
  - !ruby/object:Gem::Version
68
- version: '0.69'
82
+ version: 1.11.0
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rubocop-performance
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,20 @@ dependencies:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-minitest
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
83
111
  description: Uploads manifest.json file contents to the cloud
84
112
  email:
85
113
  - tlatsas@hey.com
@@ -87,30 +115,39 @@ executables: []
87
115
  extensions: []
88
116
  extra_rdoc_files: []
89
117
  files:
90
- - ".github/workflows/rubocop.yml"
91
- - ".github/workflows/ruby.yml"
92
118
  - ".gitignore"
93
119
  - ".rubocop.yml"
120
+ - ".yardopts"
121
+ - CHANGELOG.md
94
122
  - CONTRIBUTING.md
95
123
  - Gemfile
96
124
  - Gemfile.lock
97
125
  - MIT-LICENSE
98
126
  - README.md
99
127
  - Rakefile
100
- - bin/console
101
- - bin/setup
102
128
  - lib/webpacker_uploader.rb
129
+ - lib/webpacker_uploader/configuration.rb
103
130
  - lib/webpacker_uploader/instance.rb
104
131
  - lib/webpacker_uploader/manifest.rb
132
+ - lib/webpacker_uploader/mime.rb
105
133
  - lib/webpacker_uploader/providers/aws.rb
106
134
  - lib/webpacker_uploader/version.rb
135
+ - test/configuration_test.rb
136
+ - test/manifest_test.rb
137
+ - test/mime_test.rb
138
+ - test/test_app/config/webpacker.yml
139
+ - test/test_app/public/packs/manifest.json
140
+ - test/test_helper.rb
141
+ - test/webpacker_uploader_test.rb
107
142
  - webpacker_uploader.gemspec
108
143
  homepage: https://github.com/tlatsas/webpacker_uploader
109
144
  licenses:
110
145
  - MIT
111
146
  metadata:
112
147
  homepage_uri: https://github.com/tlatsas/webpacker_uploader
113
- source_code_uri: https://github.com/tlatsas/webpacker_uploader/tree/v0.1.0
148
+ bug_tracker_uri: https://github.com/tlatsas/webpacker_uploader/issues
149
+ changelog_uri: https://github.com/tlatsas/webpacker_uploader/blob/main/CHANGELOG.md
150
+ source_code_uri: https://github.com/tlatsas/webpacker_uploader/tree/v0.5.0
114
151
  post_install_message:
115
152
  rdoc_options: []
116
153
  require_paths:
@@ -126,8 +163,15 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
163
  - !ruby/object:Gem::Version
127
164
  version: '0'
128
165
  requirements: []
129
- rubygems_version: 3.1.2
166
+ rubygems_version: 3.1.4
130
167
  signing_key:
131
168
  specification_version: 4
132
169
  summary: Uploads manifest.json file contents to the cloud
133
- test_files: []
170
+ test_files:
171
+ - test/configuration_test.rb
172
+ - test/manifest_test.rb
173
+ - test/mime_test.rb
174
+ - test/test_app/config/webpacker.yml
175
+ - test/test_app/public/packs/manifest.json
176
+ - test/test_helper.rb
177
+ - test/webpacker_uploader_test.rb