Version assets

This commit is contained in:
2023-05-15 19:42:56 +10:00
parent 0a790e83a1
commit 4309453f51
10 changed files with 2418 additions and 8 deletions

27
version_assets.rb Normal file
View File

@@ -0,0 +1,27 @@
# get index.css, index.js
# generate hash
# rename files
# write asset manifest
require "securerandom"
require "json"
require "fileutils"
folder_path = File.join(__dir__, "/public/assets")
dist_path = File.join(__dir__, "/public/assets/dist")
hash = SecureRandom.urlsafe_base64(9)
filenames = {}
FileUtils.rm_rf("#{dist_path}/.", secure: true)
Dir.glob(folder_path + "/*.{js,css}").each do |f|
FileUtils.cp(f, dist_path)
end
Dir.glob(dist_path + "/*.{js,css}").each_with_object(filenames) do |f, memo|
filename = File.basename(f, File.extname(f))
memo[filename + File.extname(f)] = filename + "-" + hash + File.extname(f)
File.rename(f, dist_path + "/" + filename + "-" + hash + File.extname(f))
end
File.open(folder_path + "/asset-manifest.json", "wb") {|f| f.write(JSON.generate(filenames)) }