5
5

More than 5 years have passed since last update.

ある画像フォルダとデプロイされた画像の差分を求めるメモ

Posted at

assetsフォルダ以下にあるファイルとdeployのときに生成されるmanifest.ymlを比較して、差分があるかどうかを求めるプログラム

  1. 色々画像が入ってるassetsフォルダが必要
  2. manifest.ymlも必要
  3. ダウンロードしてきた、ローカルのパスをfile_pathに設定して
files = []
Dir.glob('./assets/**/*').each do |f|
  scans = f.scan(%r{^\./assets/(([a-zA-Z0-9_]|/)+).+(\.[a-zA-Z]+)})
  file = ""
  unless scans.empty?
     file = scans[0][0] + scans[0][2]
     files << file
  end
end
files.uniq!

manifest = File.readlines("./manifest.yml")
manifest.delete_at(0)
deploy_files = []
manifest.each do |mani|
  splits = mani.split(":")
  deploy_files << splits[0]
end

diff = files - deploy_files

exist_file_path = []
diff.each do |p|
  file_path = "any/assets/#{p}"
  if File.exist? file_path
    exist_file_path << file_path
  end
end

puts exist_file_path
5
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
5