Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support CDN usage #177

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/bootstrap.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# frozen_string_literal: true

require 'bootstrap/version'
require 'bootstrap/vendor'
require 'popper_js'

module Bootstrap
Expand Down
11 changes: 11 additions & 0 deletions lib/bootstrap/vendor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

module Bootstrap
BOOTSTRAP_SHA = "8fa0d3010112dca5dd6dd501173415856001ba8b"
VENDOR_VERSION = "4.3.1"
VENDOR_INTEGRITY = {
"bootstrap.min.js" => "sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM",
"bootstrap.bundle.min.js" => "sha384-xrRywqdh3PHs8keKZN+8zzc5TX0GRTLCcmivcbNJWm2rs5C8PRhcEn3czEjhAO9o",
"bootstrap.min.css" => "sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T",
}
end
3 changes: 1 addition & 2 deletions lib/bootstrap/version.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

module Bootstrap
VERSION = '4.3.1'
BOOTSTRAP_SHA = '8fa0d3010112dca5dd6dd501173415856001ba8b'
VERSION = '4.3.1'
end
25 changes: 19 additions & 6 deletions tasks/updater.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
require 'forwardable'
require 'term/ansicolor'
require 'fileutils'
require 'digest'

require_relative 'updater/scss'
require_relative 'updater/js'
Expand Down Expand Up @@ -45,7 +46,7 @@ def update_bootstrap

update_scss_assets
update_javascript_assets
store_version
store_metadata
end

def save_file(path, content, mode='w')
Expand All @@ -58,10 +59,22 @@ def upstream_version
@upstream_version ||= get_json(file_url 'package.json')['version']
end

# Update version.rb file with BOOTSTRAP_SHA
def store_version
path = 'lib/bootstrap/version.rb'
content = File.read(path).sub(/BOOTSTRAP_SHA\s*=\s*['"][^'"]*['"]/, "BOOTSTRAP_SHA = '#@branch_sha'")
File.open(path, 'w') { |f| f.write(content) }
def store_metadata
integrity_lines = read_files('dist/js', %w(bootstrap.min.js bootstrap.bundle.min.js)).
merge(read_files('dist/css', %w(bootstrap.min.css))).
transform_values { |content| "sha384-#{Digest::SHA384.base64digest(content)}" }.
map { |filename, integrity| " #{filename.inspect} => #{integrity.inspect}," }

File.write("lib/bootstrap/vendor.rb", <<~RUBY)
# frozen_string_literal: true

module Bootstrap
BOOTSTRAP_SHA = #{@branch_sha.to_s.inspect}
VENDOR_VERSION = #{upstream_version.to_s.inspect}
VENDOR_INTEGRITY = {
#{integrity_lines.join("\n")}
}
end
RUBY
end
end