Sha256: b8b3af2de0b5de52f1742f2e1dc79b1c9f00201af4a74a788b4bf52823770291

Contents?: true

Size: 1.31 KB

Versions: 6

Compression:

Stored size: 1.31 KB

Contents

require "digest/md5"

module Pilot
  class PackageBuilder
    METADATA_FILE_NAME = "metadata.xml"

    attr_accessor :package_path

    def generate(apple_id: nil, ipa_path: nil, package_path: nil)
      self.package_path = File.join(package_path, "#{apple_id}.itmsp")
      FileUtils.rm_rf self.package_path rescue nil
      FileUtils.mkdir_p self.package_path

      lib_path = Helper.gem_path("pilot")

      ipa_path = copy_ipa(ipa_path)
      @data = {
        apple_id: apple_id,
        file_size: File.size(ipa_path),
        ipa_path: File.basename(ipa_path), # this is only the base name as the ipa is inside the package
        md5: Digest::MD5.hexdigest(File.read(ipa_path))
      }

      xml_path = File.join(lib_path, "lib/assets/XMLTemplate.xml.erb")
      xml = ERB.new(File.read(xml_path)).result(binding) # http://www.rrn.dk/rubys-erb-templating-system  
      
      File.write(File.join(self.package_path, METADATA_FILE_NAME), xml)
      Helper.log.info "Wrote XML data to '#{self.package_path}'".green if $verbose

      return package_path
    end

    private
      def copy_ipa(ipa_path)
        ipa_file_name = Digest::MD5.hexdigest(ipa_path)
        resulting_path = File.join(self.package_path, "#{ipa_file_name}.ipa")
        FileUtils.cp(ipa_path, resulting_path)

        return resulting_path
      end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
pilot-0.1.7 lib/pilot/package_builder.rb
pilot-0.1.6 lib/pilot/package_builder.rb
pilot-0.1.5 lib/pilot/package_builder.rb
pilot-0.1.4 lib/pilot/package_builder.rb
pilot-0.1.3 lib/pilot/package_builder.rb
pilot-0.1.2 lib/pilot/package_builder.rb