Class: HighFive::Thor::Tasks::Dist

Inherits:
HighFive::Thor::Task show all
Includes:
AndroidHelper, IosHelper, Thor::Actions
Defined in:
lib/high_five/thor/tasks/dist.rb

Instance Method Summary collapse

Methods included from AndroidHelper

#android_manifest_path, #gradle_file_path, #parse_resolution, project_name_from_build_xml, #res_map, #valid_directories

Methods included from IosHelper

#info_plist_path, #ios_icon_sizes, #ios_path, uuid_from_mobileprovision, #xcodeproj_path

Methods inherited from HighFive::Thor::Task

inherited

Instance Method Details

#dist(platform) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/high_five/thor/tasks/dist.rb', line 25

def dist(platform)
  @environment            = options[:environment]
  @output_file_name       = options[:output_file_name]
  @sign_identity          = options[:sign_identity]
  @provisioning_profile   = options[:provisioning_profile]
  @platform_path          = options[:platform_path]
  @platform               = platform

  if @platform == "android" || @platform == "amazon"
    if @platform_path
      android_path = @platform_path
    else
      manifest_path = config.android_manifest || android_manifest_path
      android_path = File.dirname(manifest_path)
    end

    dist_android(android_path)
    if options[:install]
      install_android android_path
    end
  elsif @platform == "ios"
    raise "Please pass in the code sign identity to build an ios app. -s [sign_identity]" if @sign_identity.nil?
    raise "Please pass in the path to the provisioning profile to build an ios app. -p [provisioning_profile]" if @provisioning_profile.nil?

    ios_project_name = File.basename(Dir[ios_path + "/*.xcodeproj"].first, '.xcodeproj')
    ios_target = options[:target] || config.ios_target || ios_project_name
    keychain = ios_project_name.gsub(/\s/, '').gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').gsub(/([a-z\d])([A-Z])/,'\1_\2').tr("-", "_").downcase + '-ios.keychain'

    @output_file_name ||= ios_target

    uuid = HighFive::IosHelper.uuid_from_mobileprovision(@provisioning_profile)
    ENV['uuid'] = uuid
    FileUtils.cp(@provisioning_profile, "#{ENV['HOME']}/Library/MobileDevice/Provisioning Profiles/#{uuid}.mobileprovision")
    system_or_die("rm -rf #{ios_path}/build/*")
    system_or_die(%Q(cd "#{ios_path}";
      /usr/bin/xcodebuild -target "#{ios_target}" -configuration Release clean build "CONFIGURATION_BUILD_DIR=#{ios_path}/build" "CODE_SIGN_IDENTITY=#{@sign_identity}" PROVISIONING_PROFILE=$uuid))
    system_or_die(%Q(/usr/bin/xcrun -sdk iphoneos PackageApplication -v "#{ios_path}/build/#{ios_target}.app" -o "#{ios_path}/build/#{@output_file_name}.ipa" --embed "#{@provisioning_profile}"))
  end
end

#dist_android(android_path) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/high_five/thor/tasks/dist.rb', line 68

def dist_android(android_path)
  @output_file_name       = options[:output_file_name]
  ant_flags = options[:"ant-flags"] || ""
  # system_or_die("android update project --path #{android_path} --subprojects")
  gradle_file = File.join(android_path, "build.gradle")
  gradle = File.exists?(gradle_file) && !options[:ant]
  debug = options[:debug]
  if gradle
    if debug
      system_or_die("gradle -b #{gradle_file} clean assembleDebug")
    else
      system_or_die("gradle -b #{gradle_file} clean assembleRelease")
    end
  else
    if debug
      system_or_die("ant -file '#{android_path}/build.xml' clean debug")
    else
      system_or_die("ant -file '#{android_path}/build.xml' clean release #{ant_flags}")
    end
  end

  android_name = HighFive::AndroidHelper.project_name_from_build_xml("#{android_path}/build.xml")

  if @output_file_name
    if gradle
      if debug
        apk = Dir["#{android_path}/build/outputs/apk/*-debug.apk"][0]
      else
        apk = Dir["#{android_path}/build/outputs/apk/*-release.apk"][0]
      end
      @final_apk_path = "#{android_path}/build/outputs/apk/#{@output_file_name}.apk"
      say "copying final build #{apk} -> #{@final_apk_path}"
      FileUtils.cp("#{apk}", @final_apk_path)
    else
      if debug
        apk = Dir["#{android_path}/bin/#{android_name}-debug.apk"][0]
      else
        apk = Dir["#{android_path}/bin/#{android_name}-release.apk"][0]
      end
      @final_apk_path = "#{android_path}/bin/#{@output_file_name}.apk"
      say "copying final build #{apk} -> #{@final_apk_path}"
      FileUtils.cp("#{apk}", @final_apk_path)
    end
  end
end

#install_android(android_path) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/high_five/thor/tasks/dist.rb', line 115

def install_android(android_path)
  @output_file_name = options[:output_file_name]
  gradle_file = File.join(android_path, "build.gradle")
  gradle = File.exists?(gradle_file) && !options[:ant]
  debug = options[:debug]
  if debug
    if @output_file_name
      if gradle
        system_or_die("adb install -r #{android_path}/build/outputs/apk/#{@output_file_name}.apk")
      else
        system_or_die("adb install -r #{android_path}/bin/#{@output_file_name}.apk")
      end
    else
      if gradle
        system_or_die("adb install -r #{Dir["#{android_path}/build/outputs/apk/*-debug.apk"][0]}")
      else
        system_or_die("adb install -r #{Dir["#{android_path}/bin/*-debug.apk"][0]}")
      end
    end
  else
    system_or_die("ant -file '#{android_path}/build.xml' installr")
  end
end