Sha256: e7a1ff5f9e793acfca6e010ed2a51c80e3efd41c241c796010024a61c99d5be2

Contents?: true

Size: 1.71 KB

Versions: 26

Compression:

Stored size: 1.71 KB

Contents

require 'action_view'

# Examples:
#
#   zip = Jets::Builders::Md5Zip.new("/tmp/jets/demo/stage/code")
#   zip.create
#
#   zip = Jets::Builders::Md5Zip.new("/tmp/jets/demo/stage/bundled")
#   zip.create
#
class Jets::Builders
  class Md5Zip
    include ActionView::Helpers::NumberHelper # number_to_human_size
    include Util

    def initialize(folder)
      @path = "#{Jets.build_root}/#{folder}"
      @checksum = Md5.checksums[folder]
    end

    def create
      headline "Creating zip file for #{@path}"

      # https://serverfault.com/questions/265675/how-can-i-zip-compress-a-symlink
      command = "cd #{@path} && zip --symlinks -rq #{zip_file} ."
      sh(command)
      # move out of the lower folder to the stage folder
      # mv /tmp/jets/demo/stage/code/code.zip /tmp/jets/demo/stage/code.zip
      FileUtils.mkdir_p(File.dirname(zip_dest))
      FileUtils.mv("#{@path}/#{zip_file}", zip_dest)

      # mv /tmp/jets/demo/stage/zips/code.zip /tmp/jets/demo/stage/zips/code-a8a604aa.zip
      FileUtils.mv(zip_dest, md5_dest)

      file_size = number_to_human_size(File.size(md5_dest))
      puts "Zip file created at: #{md5_dest.colorize(:green)} (#{file_size})"
    end

    # /tmp/jets/demo/stage/zips/code.zip
    def zip_dest
      stage_area, filename = File.dirname(@path), File.basename(@path)
      zip_area = stage_area + '/zips' # /tmp/jets/demo/stage/zips
      zip_file = filename + '.zip' # code.zip
      "#{zip_area}/#{zip_file}" # /tmp/jets/demo/stage/zips/code.zip
    end

    def zip_file
      File.basename(zip_dest)
    end

    # /tmp/jets/demo/stage/zips/code-SHA.zip
    def md5_dest
      zip_dest.sub(".zip", "-#{@checksum}.zip")
    end

    def md5_name
      File.basename(md5_dest)
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
jets-1.2.1 lib/jets/builders/md5_zip.rb
jets-1.2.0 lib/jets/builders/md5_zip.rb
jets-1.1.5 lib/jets/builders/md5_zip.rb
jets-1.1.4 lib/jets/builders/md5_zip.rb
jets-1.1.3 lib/jets/builders/md5_zip.rb
jets-1.1.2 lib/jets/builders/md5_zip.rb
jets-1.1.1 lib/jets/builders/md5_zip.rb
jets-1.1.0 lib/jets/builders/md5_zip.rb
jets-1.0.18 lib/jets/builders/md5_zip.rb
jets-1.0.17 lib/jets/builders/md5_zip.rb
jets-1.0.16 lib/jets/builders/md5_zip.rb
jets-1.0.15 lib/jets/builders/md5_zip.rb
jets-1.0.13 lib/jets/builders/md5_zip.rb
jets-1.0.12 lib/jets/builders/md5_zip.rb
jets-1.0.11 lib/jets/builders/md5_zip.rb
jets-1.0.10 lib/jets/builders/md5_zip.rb
jets-1.0.9 lib/jets/builders/md5_zip.rb
jets-1.0.8 lib/jets/builders/md5_zip.rb
jets-1.0.7 lib/jets/builders/md5_zip.rb
jets-1.0.6 lib/jets/builders/md5_zip.rb