Skip to content

Instantly share code, notes, and snippets.

@plukevdh
Created September 29, 2016 20:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plukevdh/1685a1bba397cc6f9756e6cd74bb8457 to your computer and use it in GitHub Desktop.
Save plukevdh/1685a1bba397cc6f9756e6cd74bb8457 to your computer and use it in GitHub Desktop.
simple md5 hash digetsing
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