class Lono::Script::Build

Public Class Methods

scripts_name() click to toggle source

Only avaialble after script has been built.

# File lib/lono/script/build.rb, line 7
def self.scripts_name
  new.scripts_name
end

Public Instance Methods

create_tarball() click to toggle source
# File lib/lono/script/build.rb, line 35
def create_tarball
  # https://apple.stackexchange.com/questions/14980/why-are-dot-underscore-files-created-and-how-can-i-avoid-them
  # using system to avoid displaying command
  system "cd #{Lono.blueprint_root}/app && dot_clean ." if system("type dot_clean > /dev/null 2>&1")

  # https://serverfault.com/questions/110208/different-md5sums-for-same-tar-contents
  # Using tar czf directly results in a new m5sum each time because the gzip
  # timestamp is included.  So using:  tar -c ... | gzip -n
  sh "cd #{Lono.blueprint_root}/app && tar -c scripts | gzip -n > scripts.tgz" # temporary app/scripts.tgz file

  rename_with_md5!
end
md5sum() click to toggle source

cache this because the file will get removed

# File lib/lono/script/build.rb, line 63
def md5sum
  @md5sum ||= Digest::MD5.file("#{Lono.blueprint_root}/app/scripts.tgz").to_s[0..7]
end
rename_with_md5!() click to toggle source

Apppend a md5 to file after it's been created and moves it to output/scripts/scripts-.tgz

# File lib/lono/script/build.rb, line 50
def rename_with_md5!
  md5_path = "output/#{@blueprint}/scripts/scripts-#{md5sum}.tgz"
  FileUtils.mkdir_p(File.dirname(md5_path))
  FileUtils.mv("#{Lono.blueprint_root}/app/scripts.tgz", md5_path)
  md5_path
end
reset() click to toggle source
# File lib/lono/script/build.rb, line 31
def reset
  FileUtils.rm_f(SCRIPTS_INFO_PATH)
end
run() click to toggle source
# File lib/lono/script/build.rb, line 11
def run
  Lono::ProjectChecker.check
  reset
  if Dir["#{Lono.blueprint_root}/app/scripts/*"].empty?
    return
  else
    puts "Detected app/scripts for blueprint #{@blueprint}"
  end

  puts "Tarballing app/scripts folder to scripts.tgz"
  tarball_path = create_tarball
  save_scripts_info(tarball_path)
  puts "Tarball created at #{tarball_path}"
end
save_scripts_info(scripts_name) click to toggle source
# File lib/lono/script/build.rb, line 57
def save_scripts_info(scripts_name)
  FileUtils.mkdir_p(File.dirname(SCRIPTS_INFO_PATH))
  IO.write(SCRIPTS_INFO_PATH, scripts_name)
end
scripts_name() click to toggle source

Only avaialble after script has been built.

# File lib/lono/script/build.rb, line 27
def scripts_name
  IO.read(SCRIPTS_INFO_PATH).strip
end
sh(command) click to toggle source
# File lib/lono/script/build.rb, line 67
def sh(command)
  puts "=> #{command}"
  system command
end