Sha256: fc1e35fcf325638c41944d5f3709c00b1ae3bc9debde7fbd5c8a7793e6d66b62

Contents?: true

Size: 1.6 KB

Versions: 7

Compression:

Stored size: 1.6 KB

Contents

#!/usr/bin/env ruby
require "rubygems"
require 'tempfile'
require "yui/compressor"
require "optparse"
require "#{File.dirname(__FILE__)}/../config/boot"

class AirFile
  class << self
    def copy_to_tmp
      FileUtils.rm_r Dir.glob(MoonwalkAir.tmp)
      FileUtils.mkdir(MoonwalkAir.tmp)
      FileUtils.cp("#{MoonwalkAir.root}/descriptor.xml", "#{MoonwalkAir.tmp}" )
      build_files = YAML.load_file("#{MoonwalkAir.config}/build.yml")["build_files"]
      build_files.each do |f|
        FileUtils.mkdir_p("#{MoonwalkAir.tmp}/#{File.dirname(f)}")
        FileUtils.cp_r(File.expand_path(f), "#{MoonwalkAir.tmp}/#{f}")
      end
    end

    def compress(path)
      yui = YUI::JavaScriptCompressor.new(:munge => true)
      Dir.glob("#{path}/**/*") do |file|
        compressed = File.open(file, 'r') { | f | yui.compress(f.read) }
        File.open(file, 'w+') { |f| f.puts compressed }
      end
    end

    def build!
      puts "copying files to tmp folder"
      copy_to_tmp

      puts "compressing and obfuscating files"
      compress("#{MoonwalkAir.tmp}/app/scripts")

      system "cd tmp && #{MoonwalkAir.air_bin}/adt -package -storetype pkcs12 -keystore #{MoonwalkAir.config}/cert.pfx #{MoonwalkAir.bin}/#{MoonwalkAir.app_name}.air descriptor.xml ."

      puts "cleaning tmp folder"
      FileUtils.rm_r Dir.glob("#{MoonwalkAir.tmp}/*")
      puts "=========================="
      puts "Finished build process"
    rescue => ex
      puts "=========================="
      puts "An error happen when try to build #{MoonwalkAir.app_name}.air file"
      puts "error: #{ex.message}"
    end
  end

end

AirFile.build!

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
moonwalkair-0.4.1 lib/moonwalkair/templates/script/build
moonwalkair-0.4.0 lib/moonwalkair/templates/script/build
moonwalkair-0.3.2 lib/moonwalkair/templates/script/build
moonwalkair-0.3.1 lib/moonwalkair/templates/script/build
moonwalkair-0.3.0 lib/moonwalkair/templates/script/build
moonwalkair-0.2.0 lib/moonwalkair/templates/script/build
moonwalkair-0.1.0 lib/moonwalkair/templates/script/build