Created
September 29, 2016 20:33
-
-
Save plukevdh/1685a1bba397cc6f9756e6cd74bb8457 to your computer and use it in GitHub Desktop.
simple md5 hash digetsing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'digest' | |
require 'fileutils' | |
EXCLUDES = %w{.rb .md} | |
def exclude?(path) | |
EXCLUDES.any? {|pattern| path.end_with? pattern } | |
end | |
def md5_name(path) | |
digest = Digest::MD5.file path | |
"#{File.basename(path, ".*")}-#{digest}#{File.extname(path)}" | |
end | |
manifest = {} | |
Dir.glob("**/*") do |f| | |
next if !File.file?(f) || exclude?(f) | |
manifest_name = md5_name(f) | |
manifest[f] = manifest_name | |
path = "dist/#{File.dirname(f)}" | |
FileUtils.mkdir_p(path) | |
FileUtils.cp_r(f, "#{path}/#{manifest_name}") | |
end | |
puts manifest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment