webpacker_uploader 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.github/workflows/rubocop.yml +35 -0
- data/.github/workflows/ruby.yml +38 -0
- data/.gitignore +11 -0
- data/.rubocop.yml +125 -0
- data/CONTRIBUTING.md +22 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +123 -0
- data/MIT-LICENSE +21 -0
- data/README.md +63 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/webpacker_uploader.rb +23 -0
- data/lib/webpacker_uploader/instance.rb +36 -0
- data/lib/webpacker_uploader/manifest.rb +19 -0
- data/lib/webpacker_uploader/providers/aws.rb +34 -0
- data/lib/webpacker_uploader/version.rb +3 -0
- data/webpacker_uploader.gemspec +37 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: fbdb29fdfafeddb7feb884a38b52e8805a42551a9d6562a74b011b9673926cd1
|
4
|
+
data.tar.gz: 925e5c75c02b4b227b243a2a016de589e18b9072421ff20f4cc632a72834a74e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d5ac3ffbf041da9ec25dbc52e7dd8c6e63ee501a5a3eff6355efbf37124089d29c4ba6720b88310b5e083749aea1ac7c8be1a9c5692fb0eecfa6931a202cc8d5
|
7
|
+
data.tar.gz: 9d16ddae2c7ca1efcbc0f1f4dbb4c5002c0b28281f652ff92e2a0bc28d849c7bb9828ee9e26121c157cdcc9d0221c78983d8c093865da35cacfe2433b9bcc30f
|
@@ -0,0 +1,35 @@
|
|
1
|
+
name: RuboCop
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
name: RuboCop
|
8
|
+
runs-on: ${{ matrix.os }}
|
9
|
+
env:
|
10
|
+
BUNDLE_JOBS: 4
|
11
|
+
BUNDLE_RETRY: 3
|
12
|
+
strategy:
|
13
|
+
matrix:
|
14
|
+
os: [ ubuntu-latest ]
|
15
|
+
ruby: [
|
16
|
+
2.7
|
17
|
+
]
|
18
|
+
steps:
|
19
|
+
- uses: actions/checkout@v2
|
20
|
+
- uses: actions/cache@v2
|
21
|
+
with:
|
22
|
+
path: vendor/bundle
|
23
|
+
key: ${{ runner.os }}-rubocop-${{ hashFiles('**/Gemfile.lock') }}
|
24
|
+
restore-keys: |
|
25
|
+
${{ runner.os }}-rubocop-
|
26
|
+
- uses: ruby/setup-ruby@v1
|
27
|
+
with:
|
28
|
+
ruby-version: ${{ matrix.ruby }}
|
29
|
+
- name: Bundle install
|
30
|
+
run: |
|
31
|
+
gem install bundler -v 2.1.4
|
32
|
+
bundle config path vendor/bundle
|
33
|
+
bundle install
|
34
|
+
- name: Run RuboCop
|
35
|
+
run: bundle exec rubocop
|
@@ -0,0 +1,38 @@
|
|
1
|
+
name: Ruby tests
|
2
|
+
|
3
|
+
on: [push, pull_request]
|
4
|
+
|
5
|
+
jobs:
|
6
|
+
build:
|
7
|
+
name: Ruby tests
|
8
|
+
runs-on: ${{ matrix.os }}
|
9
|
+
env:
|
10
|
+
BUNDLE_JOBS: 4
|
11
|
+
BUNDLE_RETRY: 3
|
12
|
+
strategy:
|
13
|
+
fail-fast: false
|
14
|
+
matrix:
|
15
|
+
os: [ubuntu-latest]
|
16
|
+
ruby: [
|
17
|
+
2.5,
|
18
|
+
2.6,
|
19
|
+
2.7
|
20
|
+
]
|
21
|
+
steps:
|
22
|
+
- uses: actions/checkout@v2
|
23
|
+
- uses: actions/cache@v2
|
24
|
+
with:
|
25
|
+
path: vendor/bundle
|
26
|
+
key: ${{ runner.os }}-ruby-${{ matrix.ruby }}-gems-${{ hashFiles('**/Gemfile.lock') }}-${{ hashFiles('**/*.gemspec') }}
|
27
|
+
restore-keys: |
|
28
|
+
${{ runner.os }}-ruby-${{ matrix.ruby }}-gems-
|
29
|
+
- uses: ruby/setup-ruby@v1
|
30
|
+
with:
|
31
|
+
ruby-version: ${{ matrix.ruby }}
|
32
|
+
- name: Bundle install
|
33
|
+
run: |
|
34
|
+
gem install bundler -v 2.1.4
|
35
|
+
bundle config path vendor/bundle
|
36
|
+
bundle install
|
37
|
+
- name: Run tests
|
38
|
+
run: bundle exec rake test
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,125 @@
|
|
1
|
+
require: rubocop-performance
|
2
|
+
AllCops:
|
3
|
+
TargetRubyVersion: 2.5
|
4
|
+
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
|
5
|
+
# to ignore them, so only the ones explicitly set in this file are enabled.
|
6
|
+
DisabledByDefault: true
|
7
|
+
Exclude:
|
8
|
+
- 'lib/install/templates/**'
|
9
|
+
- 'vendor/**/*'
|
10
|
+
- 'node_modules/**/*'
|
11
|
+
|
12
|
+
# Prefer &&/|| over and/or.
|
13
|
+
Style/AndOr:
|
14
|
+
Enabled: true
|
15
|
+
|
16
|
+
# Do not use braces for hash literals when they are the last argument of a
|
17
|
+
# method call.
|
18
|
+
Style/BracesAroundHashParameters:
|
19
|
+
Enabled: true
|
20
|
+
|
21
|
+
# Align `when` with `case`.
|
22
|
+
Layout/CaseIndentation:
|
23
|
+
Enabled: true
|
24
|
+
|
25
|
+
# Align comments with method definitions.
|
26
|
+
Layout/CommentIndentation:
|
27
|
+
Enabled: true
|
28
|
+
|
29
|
+
# No extra empty lines.
|
30
|
+
Layout/EmptyLines:
|
31
|
+
Enabled: true
|
32
|
+
|
33
|
+
# In a regular class definition, no empty lines around the body.
|
34
|
+
Layout/EmptyLinesAroundClassBody:
|
35
|
+
Enabled: true
|
36
|
+
|
37
|
+
# In a regular method definition, no empty lines around the body.
|
38
|
+
Layout/EmptyLinesAroundMethodBody:
|
39
|
+
Enabled: true
|
40
|
+
|
41
|
+
# In a regular module definition, no empty lines around the body.
|
42
|
+
Layout/EmptyLinesAroundModuleBody:
|
43
|
+
Enabled: true
|
44
|
+
|
45
|
+
# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
|
46
|
+
Style/HashSyntax:
|
47
|
+
Enabled: true
|
48
|
+
|
49
|
+
# Method definitions after `private` or `protected` isolated calls need one
|
50
|
+
# extra level of indentation.
|
51
|
+
Layout/IndentationConsistency:
|
52
|
+
Enabled: true
|
53
|
+
EnforcedStyle: rails
|
54
|
+
|
55
|
+
# Two spaces, no tabs (for indentation).
|
56
|
+
Layout/IndentationWidth:
|
57
|
+
Enabled: true
|
58
|
+
|
59
|
+
Layout/SpaceAfterColon:
|
60
|
+
Enabled: true
|
61
|
+
|
62
|
+
Layout/SpaceAfterComma:
|
63
|
+
Enabled: true
|
64
|
+
|
65
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
66
|
+
Enabled: true
|
67
|
+
|
68
|
+
Layout/SpaceAroundKeyword:
|
69
|
+
Enabled: true
|
70
|
+
|
71
|
+
Layout/SpaceAroundOperators:
|
72
|
+
Enabled: true
|
73
|
+
|
74
|
+
Layout/SpaceBeforeFirstArg:
|
75
|
+
Enabled: true
|
76
|
+
|
77
|
+
# Defining a method with parameters needs parentheses.
|
78
|
+
Style/MethodDefParentheses:
|
79
|
+
Enabled: true
|
80
|
+
|
81
|
+
# Use `foo {}` not `foo{}`.
|
82
|
+
Layout/SpaceBeforeBlockBraces:
|
83
|
+
Enabled: true
|
84
|
+
|
85
|
+
# Use `foo { bar }` not `foo {bar}`.
|
86
|
+
Layout/SpaceInsideBlockBraces:
|
87
|
+
Enabled: true
|
88
|
+
|
89
|
+
# Use `{ a: 1 }` not `{a:1}`.
|
90
|
+
Layout/SpaceInsideHashLiteralBraces:
|
91
|
+
Enabled: true
|
92
|
+
|
93
|
+
Layout/SpaceInsideParens:
|
94
|
+
Enabled: true
|
95
|
+
|
96
|
+
# Check quotes usage according to lint rule below.
|
97
|
+
Style/StringLiterals:
|
98
|
+
Enabled: true
|
99
|
+
EnforcedStyle: double_quotes
|
100
|
+
|
101
|
+
# Detect hard tabs, no hard tabs.
|
102
|
+
Layout/Tab:
|
103
|
+
Enabled: true
|
104
|
+
|
105
|
+
# Blank lines should not have any spaces.
|
106
|
+
Layout/TrailingBlankLines:
|
107
|
+
Enabled: true
|
108
|
+
|
109
|
+
# No trailing whitespace.
|
110
|
+
Layout/TrailingWhitespace:
|
111
|
+
Enabled: true
|
112
|
+
|
113
|
+
# Use quotes for string literals when they are enough.
|
114
|
+
Style/UnneededPercentQ:
|
115
|
+
Enabled: true
|
116
|
+
|
117
|
+
# Align `end` with the matching keyword or starting expression except for
|
118
|
+
# assignments, where it should be aligned with the LHS.
|
119
|
+
Layout/EndAlignment:
|
120
|
+
Enabled: true
|
121
|
+
EnforcedStyleAlignWith: variable
|
122
|
+
|
123
|
+
# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
|
124
|
+
Lint/RequireParentheses:
|
125
|
+
Enabled: true
|
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Contributing
|
2
|
+
============
|
3
|
+
|
4
|
+
#### Fork the Project
|
5
|
+
|
6
|
+
Fork the [project on Github](https://github.com/tlatsas/webpacker_uploader) and check out your copy.
|
7
|
+
|
8
|
+
```
|
9
|
+
git clone https://github.com/<contributor>/webpacker_uploader.git
|
10
|
+
cd webpacker_uploader
|
11
|
+
git remote add upstream https://github.com/tlatsas/webpacker_uploader.git
|
12
|
+
```
|
13
|
+
|
14
|
+
#### Create a Topic Branch
|
15
|
+
|
16
|
+
Make sure your fork is up-to-date and create a topic branch for your feature or bug fix.
|
17
|
+
|
18
|
+
```
|
19
|
+
git checkout master
|
20
|
+
git pull upstream master
|
21
|
+
git checkout -b my-feature-branch
|
22
|
+
```
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,123 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
webpacker_uploader (0.1.0)
|
5
|
+
mime-types
|
6
|
+
webpacker (>= 5.1)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionpack (6.0.3.3)
|
12
|
+
actionview (= 6.0.3.3)
|
13
|
+
activesupport (= 6.0.3.3)
|
14
|
+
rack (~> 2.0, >= 2.0.8)
|
15
|
+
rack-test (>= 0.6.3)
|
16
|
+
rails-dom-testing (~> 2.0)
|
17
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
18
|
+
actionview (6.0.3.3)
|
19
|
+
activesupport (= 6.0.3.3)
|
20
|
+
builder (~> 3.1)
|
21
|
+
erubi (~> 1.4)
|
22
|
+
rails-dom-testing (~> 2.0)
|
23
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
24
|
+
activesupport (6.0.3.3)
|
25
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
26
|
+
i18n (>= 0.7, < 2)
|
27
|
+
minitest (~> 5.1)
|
28
|
+
tzinfo (~> 1.1)
|
29
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
30
|
+
ast (2.4.1)
|
31
|
+
aws-eventstream (1.1.0)
|
32
|
+
aws-partitions (1.376.0)
|
33
|
+
aws-sdk-core (3.108.0)
|
34
|
+
aws-eventstream (~> 1, >= 1.0.2)
|
35
|
+
aws-partitions (~> 1, >= 1.239.0)
|
36
|
+
aws-sigv4 (~> 1.1)
|
37
|
+
jmespath (~> 1.0)
|
38
|
+
aws-sdk-kms (1.38.0)
|
39
|
+
aws-sdk-core (~> 3, >= 3.99.0)
|
40
|
+
aws-sigv4 (~> 1.1)
|
41
|
+
aws-sdk-s3 (1.81.1)
|
42
|
+
aws-sdk-core (~> 3, >= 3.104.3)
|
43
|
+
aws-sdk-kms (~> 1)
|
44
|
+
aws-sigv4 (~> 1.1)
|
45
|
+
aws-sigv4 (1.2.2)
|
46
|
+
aws-eventstream (~> 1, >= 1.0.2)
|
47
|
+
builder (3.2.4)
|
48
|
+
concurrent-ruby (1.1.7)
|
49
|
+
crass (1.0.6)
|
50
|
+
erubi (1.9.0)
|
51
|
+
i18n (1.8.5)
|
52
|
+
concurrent-ruby (~> 1.0)
|
53
|
+
jaro_winkler (1.5.4)
|
54
|
+
jmespath (1.4.0)
|
55
|
+
loofah (2.7.0)
|
56
|
+
crass (~> 1.0.2)
|
57
|
+
nokogiri (>= 1.5.9)
|
58
|
+
method_source (1.0.0)
|
59
|
+
mime-types (3.3.1)
|
60
|
+
mime-types-data (~> 3.2015)
|
61
|
+
mime-types-data (3.2020.0512)
|
62
|
+
mini_portile2 (2.4.0)
|
63
|
+
minitest (5.14.2)
|
64
|
+
nokogiri (1.10.10)
|
65
|
+
mini_portile2 (~> 2.4.0)
|
66
|
+
parallel (1.19.2)
|
67
|
+
parser (2.7.1.4)
|
68
|
+
ast (~> 2.4.1)
|
69
|
+
rack (2.2.3)
|
70
|
+
rack-proxy (0.6.5)
|
71
|
+
rack
|
72
|
+
rack-test (1.1.0)
|
73
|
+
rack (>= 1.0, < 3)
|
74
|
+
rails-dom-testing (2.0.3)
|
75
|
+
activesupport (>= 4.2.0)
|
76
|
+
nokogiri (>= 1.6)
|
77
|
+
rails-html-sanitizer (1.3.0)
|
78
|
+
loofah (~> 2.3)
|
79
|
+
railties (6.0.3.3)
|
80
|
+
actionpack (= 6.0.3.3)
|
81
|
+
activesupport (= 6.0.3.3)
|
82
|
+
method_source
|
83
|
+
rake (>= 0.8.7)
|
84
|
+
thor (>= 0.20.3, < 2.0)
|
85
|
+
rainbow (3.0.0)
|
86
|
+
rake (12.3.3)
|
87
|
+
rubocop (0.68.1)
|
88
|
+
jaro_winkler (~> 1.5.1)
|
89
|
+
parallel (~> 1.10)
|
90
|
+
parser (>= 2.5, != 2.5.1.1)
|
91
|
+
rainbow (>= 2.2.2, < 4.0)
|
92
|
+
ruby-progressbar (~> 1.7)
|
93
|
+
unicode-display_width (>= 1.4.0, < 1.6)
|
94
|
+
rubocop-performance (1.3.0)
|
95
|
+
rubocop (>= 0.68.0)
|
96
|
+
ruby-progressbar (1.10.1)
|
97
|
+
semantic_range (2.3.0)
|
98
|
+
thor (1.0.1)
|
99
|
+
thread_safe (0.3.6)
|
100
|
+
tzinfo (1.2.7)
|
101
|
+
thread_safe (~> 0.1)
|
102
|
+
unicode-display_width (1.5.0)
|
103
|
+
webpacker (5.2.1)
|
104
|
+
activesupport (>= 5.2)
|
105
|
+
rack-proxy (>= 0.6.1)
|
106
|
+
railties (>= 5.2)
|
107
|
+
semantic_range (>= 2.3.0)
|
108
|
+
zeitwerk (2.4.0)
|
109
|
+
|
110
|
+
PLATFORMS
|
111
|
+
ruby
|
112
|
+
|
113
|
+
DEPENDENCIES
|
114
|
+
aws-sdk-s3
|
115
|
+
bundler (>= 1.3.0)
|
116
|
+
minitest (~> 5.0)
|
117
|
+
rake (>= 11.1)
|
118
|
+
rubocop (< 0.69)
|
119
|
+
rubocop-performance
|
120
|
+
webpacker_uploader!
|
121
|
+
|
122
|
+
BUNDLED WITH
|
123
|
+
2.1.4
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Tasos Latsas
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# WebpackerUploader
|
2
|
+
|
3
|
+
Webpacker uploader provides an easy way to upload your assets to AWS S3.
|
4
|
+
It knows which files to upload by reading the `manifest.json` file.
|
5
|
+
|
6
|
+
This is particularly useful if you serve your application's assets through a combination of
|
7
|
+
S3 + CDN, outside of your Rails application.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem "webpacker_uploader"
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle install
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install webpacker_uploader
|
24
|
+
|
25
|
+
To use the aws provider install the aws-sdk-s3 gem. Add in your Gemfile:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
gem "aws-sdk-s3", require: false
|
29
|
+
```
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
require 'webpacker_uploader'
|
35
|
+
require 'webpacker_uploader/providers/aws'
|
36
|
+
|
37
|
+
provider_options = {
|
38
|
+
credentials: { profile_name: "staging" },
|
39
|
+
region: "eu-central-1",
|
40
|
+
bucket: "application-assets-20200929124523451600000001"
|
41
|
+
}
|
42
|
+
|
43
|
+
provider = WebpackerUploader::Providers::Aws.new(provider_options)
|
44
|
+
WebpackerUploader.upload!(provider)
|
45
|
+
```
|
46
|
+
|
47
|
+
## Development
|
48
|
+
|
49
|
+
After checking out the repo, run `bin/setup` to install dependencies.
|
50
|
+
Then, run `rake test` to run the tests. You can also run `bin/console` for an
|
51
|
+
interactive prompt that will allow you to experiment.
|
52
|
+
|
53
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/tlatsas/webpacker_uploader.
|
58
|
+
|
59
|
+
See [CONTRIBUTING](CONTRIBUTING.md).
|
60
|
+
|
61
|
+
## License
|
62
|
+
|
63
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "webpacker_uploader"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "active_support/core_ext/object/blank"
|
4
|
+
require "active_support/logger"
|
5
|
+
require "active_support/tagged_logging"
|
6
|
+
|
7
|
+
module WebpackerUploader
|
8
|
+
extend self
|
9
|
+
|
10
|
+
def instance=(instance)
|
11
|
+
@instance = instance
|
12
|
+
end
|
13
|
+
|
14
|
+
def instance
|
15
|
+
@instance ||= WebpackerUploader::Instance.new
|
16
|
+
end
|
17
|
+
|
18
|
+
delegate :logger, :logger=, :upload!, to: :instance
|
19
|
+
end
|
20
|
+
|
21
|
+
require "webpacker_uploader/instance"
|
22
|
+
require "webpacker_uploader/manifest"
|
23
|
+
require "webpacker_uploader/version"
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "mime-types"
|
4
|
+
|
5
|
+
class WebpackerUploader::Instance
|
6
|
+
# TODO make this configurable
|
7
|
+
IGNORE_EXTENSION = %w[.map].freeze
|
8
|
+
public_constant :IGNORE_EXTENSION
|
9
|
+
|
10
|
+
cattr_accessor(:logger) { ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) }
|
11
|
+
|
12
|
+
def manifest
|
13
|
+
@manifest ||= WebpackerUploader::Manifest.new
|
14
|
+
end
|
15
|
+
|
16
|
+
def upload!(provider)
|
17
|
+
manifest.assets.each do |name, path|
|
18
|
+
path = path[1..-1]
|
19
|
+
file_path = Rails.root.join("public", path)
|
20
|
+
|
21
|
+
if name.end_with?(*IGNORE_EXTENSION)
|
22
|
+
logger.info("Skipping: #{file_path}")
|
23
|
+
else
|
24
|
+
logger.info("Processing: #{file_path}")
|
25
|
+
provider.upload!(path, file_path, content_type_for(path)) unless name.end_with?(*IGNORE_EXTENSION)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def content_type_for(file)
|
33
|
+
fallback = MIME::Types.type_for(file).first.content_type
|
34
|
+
Rack::Mime.mime_type(File.extname(file), fallback)
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class WebpackerUploader::Manifest
|
4
|
+
attr_reader :assets
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@assets = load
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def load
|
13
|
+
if ::Webpacker.config.public_manifest_path.exist?
|
14
|
+
JSON.parse(::Webpacker.config.public_manifest_path.read).except("entrypoints")
|
15
|
+
else
|
16
|
+
{}
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "aws-sdk-s3"
|
4
|
+
|
5
|
+
module WebpackerUploader
|
6
|
+
module Providers
|
7
|
+
class Aws
|
8
|
+
attr_reader :client
|
9
|
+
attr_reader :resource
|
10
|
+
attr_reader :bucket
|
11
|
+
|
12
|
+
def initialize(options)
|
13
|
+
@client = ::Aws::S3::Client.new(credentials: credentials(options[:credentials]), region: options[:region])
|
14
|
+
@resource = ::Aws::S3::Resource.new(client: @client)
|
15
|
+
@bucket = @resource.bucket(options[:bucket])
|
16
|
+
end
|
17
|
+
|
18
|
+
def upload!(object_key, file, content_type = "")
|
19
|
+
object = @bucket.object(object_key)
|
20
|
+
object.upload_file(file, content_type: content_type)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def credentials(options)
|
26
|
+
if options[:profile_name].present?
|
27
|
+
::Aws::SharedCredentials.new(profile_name: options[:profile_name])
|
28
|
+
else
|
29
|
+
::Aws::Credentials.new(options[:access_key_id], options[:secret_access_key])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require_relative "lib/webpacker_uploader/version"
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "webpacker_uploader"
|
5
|
+
s.version = WebpackerUploader::VERSION
|
6
|
+
s.authors = ["Tasos Latsas"]
|
7
|
+
s.email = ["tlatsas@hey.com"]
|
8
|
+
|
9
|
+
s.summary = "Uploads manifest.json file contents to the cloud"
|
10
|
+
s.description = "Uploads manifest.json file contents to the cloud"
|
11
|
+
s.homepage = "https://github.com/tlatsas/webpacker_uploader"
|
12
|
+
s.license = "MIT"
|
13
|
+
|
14
|
+
s.required_ruby_version = Gem::Requirement.new(">= 2.5.0")
|
15
|
+
|
16
|
+
s.metadata = {
|
17
|
+
"homepage_uri" => s.homepage,
|
18
|
+
"source_code_uri" => "https://github.com/tlatsas/webpacker_uploader/tree/v#{s.version}"
|
19
|
+
}
|
20
|
+
|
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) }
|
29
|
+
s.require_paths = ["lib"]
|
30
|
+
|
31
|
+
s.add_dependency "webpacker", ">= 5.1"
|
32
|
+
s.add_dependency "mime-types"
|
33
|
+
|
34
|
+
s.add_development_dependency "bundler", ">= 1.3.0"
|
35
|
+
s.add_development_dependency "rubocop", "< 0.69"
|
36
|
+
s.add_development_dependency "rubocop-performance"
|
37
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: webpacker_uploader
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tasos Latsas
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-10-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: webpacker
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '5.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '5.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mime-types
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.3.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.3.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rubocop
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "<"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0.69'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "<"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0.69'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rubocop-performance
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: Uploads manifest.json file contents to the cloud
|
84
|
+
email:
|
85
|
+
- tlatsas@hey.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".github/workflows/rubocop.yml"
|
91
|
+
- ".github/workflows/ruby.yml"
|
92
|
+
- ".gitignore"
|
93
|
+
- ".rubocop.yml"
|
94
|
+
- CONTRIBUTING.md
|
95
|
+
- Gemfile
|
96
|
+
- Gemfile.lock
|
97
|
+
- MIT-LICENSE
|
98
|
+
- README.md
|
99
|
+
- Rakefile
|
100
|
+
- bin/console
|
101
|
+
- bin/setup
|
102
|
+
- lib/webpacker_uploader.rb
|
103
|
+
- lib/webpacker_uploader/instance.rb
|
104
|
+
- lib/webpacker_uploader/manifest.rb
|
105
|
+
- lib/webpacker_uploader/providers/aws.rb
|
106
|
+
- lib/webpacker_uploader/version.rb
|
107
|
+
- webpacker_uploader.gemspec
|
108
|
+
homepage: https://github.com/tlatsas/webpacker_uploader
|
109
|
+
licenses:
|
110
|
+
- MIT
|
111
|
+
metadata:
|
112
|
+
homepage_uri: https://github.com/tlatsas/webpacker_uploader
|
113
|
+
source_code_uri: https://github.com/tlatsas/webpacker_uploader/tree/v0.1.0
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
119
|
+
requirements:
|
120
|
+
- - ">="
|
121
|
+
- !ruby/object:Gem::Version
|
122
|
+
version: 2.5.0
|
123
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
|
+
requirements:
|
125
|
+
- - ">="
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: '0'
|
128
|
+
requirements: []
|
129
|
+
rubygems_version: 3.1.2
|
130
|
+
signing_key:
|
131
|
+
specification_version: 4
|
132
|
+
summary: Uploads manifest.json file contents to the cloud
|
133
|
+
test_files: []
|