Module: Lono::Utils::Item::Zip

Included in:
AppFile::Build, Configset::S3File::Build
Defined in:
lib/lono/utils/item/zip.rb

Instance Method Summary collapse

Instance Method Details

#execute_zip(command) ⇒ Object



32
33
34
35
36
37
38
39
40
# File 'lib/lono/utils/item/zip.rb', line 32

def execute_zip(command)
  # puts "=> #{command}".color(:green) # uncomment to debug
  `#{command}`
  unless $?.success?
    puts "ERROR: Fail to run #{command}".color(:red)
    puts "Maybe zip is not installed or path is incorrect?"
    exit 1
  end
end

#zip(item) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/lono/utils/item/zip.rb', line 5

def zip(item)
  if item.directory?
    zip_directory(item)
  else
    zip_file(item)
  end
end

#zip_directory(item) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/lono/utils/item/zip.rb', line 22

def zip_directory(item)
  path = item.output_path
  zip_file = item.zip_file_name

  puts "Zipping folder and generating md5 named file from: #{path}"
  command = "cd #{path} && zip --symlinks -rq #{zip_file} ." # create zipfile witih directory
  execute_zip(command)
  FileUtils.mv("#{path}/#{zip_file}", "#{File.dirname(path)}/#{zip_file}") # move zip back to the parent directory
end

#zip_file(item) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/lono/utils/item/zip.rb', line 13

def zip_file(item)
  path = item.output_path
  zip_file = item.zip_file_name

  puts "Zipping file and generating md5 named file from: #{path}"
  command = "cd #{File.dirname(path)} && zip -q #{zip_file} #{File.basename(path)}" # create zipfile at same level of file
  execute_zip(command)
end