-
Notifications
You must be signed in to change notification settings - Fork 46
/
ionic_action.rb
278 lines (247 loc) · 9.59 KB
/
ionic_action.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
64
65
66
67
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
module Fastlane
module Actions
module SharedValues
CORDOVA_IOS_RELEASE_BUILD_PATH = :CORDOVA_IOS_RELEASE_BUILD_PATH
CORDOVA_ANDROID_RELEASE_BUILD_PATH = :CORDOVA_ANDROID_RELEASE_BUILD_PATH
end
class IonicAction < Action
# valid action params
ANDROID_ARGS_MAP = {
keystore_path: 'keystore',
keystore_password: 'storePassword',
key_password: 'password',
keystore_alias: 'alias',
build_number: 'versionCode'
}
IOS_ARGS_MAP = {
type: 'packageType',
team_id: 'developmentTeam',
provisioning_profile: 'provisioningProfile'
}
# do rewriting and copying of action params
def self.get_platform_args(params, args_map)
platform_args = []
args_map.each do |action_key, cli_param|
param_value = params[action_key]
unless param_value.to_s.empty?
platform_args << "--#{cli_param}=#{Shellwords.escape(param_value)}"
end
end
return platform_args.join(' ')
end
# map action params to the cli param they will be used for
def self.get_android_args(params)
if params[:key_password].empty?
params[:key_password] = params[:keystore_password]
end
return self.get_platform_args(params, ANDROID_ARGS_MAP)
end
def self.get_ios_args(params)
app_identifier = CredentialsManager::AppfileConfig.try_fetch_value(:app_identifier)
if params[:provisioning_profile].empty?
params[:provisioning_profile] = ENV['SIGH_UUID'] || ENV["sigh_#{app_identifier}_#{params[:type].sub('-', '')}"] # TODO: What does this do? Does it also work for `match`?
end
if params[:type] == 'adhoc'
params[:type] = 'ad-hoc'
end
if params[:type] == 'appstore'
params[:type] = 'app-store'
end
return self.get_platform_args(params, IOS_ARGS_MAP)
end
# add cordova platform if missing (run #1)
def self.check_and_add_platform(platform)
if platform && !File.directory?("./platforms/#{platform}")
sh "ionic cordova platform add #{platform}"
end
end
# app_name
def self.get_app_name
config = REXML::Document.new(File.open('config.xml'))
return config.elements['widget'].elements['name'].first.value # TODO: Simplify!? (Check logic in cordova)
end
# actual building! (run #2)
def self.build(params)
args = [params[:release] ? '--release' : '--debug']
args << '--device' if params[:device]
args << '--browserify' if params[:browserify]
android_args = self.get_android_args(params) if params[:platform].to_s == 'android'
ios_args = self.get_ios_args(params) if params[:platform].to_s == 'ios'
if params[:cordova_prepare]
# TODO: Remove params not allowed/used for `prepare`
sh "ionic cordova prepare #{params[:platform]} #{args.join(' ')}"
end
# special handling for `build_number` param
if params[:platform].to_s == 'ios' && !params[:build_number].to_s.empty?
cf_bundle_version = params[:build_number].to_s
Actions::UpdateInfoPlistAction.run(
xcodeproj: "./platforms/ios/#{self.get_app_name}.xcodeproj",
plist_path: "#{self.get_app_name}/#{self.get_app_name}-Info.plist",
block: lambda { |plist|
plist['CFBundleVersion'] = cf_bundle_version
}
)
end
# TODO: extract params - only attach correct platform args
sh "ionic cordova compile #{params[:platform]} #{args.join(' ')} -- #{ios_args} -- -- #{android_args}"
end
# export build paths (run #3)
def self.set_build_paths(is_release)
app_name = self.get_app_name
build_type = is_release ? 'release' : 'debug'
ENV['CORDOVA_ANDROID_RELEASE_BUILD_PATH'] = "./platforms/android/build/outputs/apk/android-#{build_type}.apk"
ENV['CORDOVA_IOS_RELEASE_BUILD_PATH'] = "./platforms/ios/build/device/#{app_name}.ipa"
# TODO: https://github.com/bamlab/fastlane-plugin-cordova/issues/7
end
def self.run(params)
self.check_and_add_platform(params[:platform])
self.build(params)
self.set_build_paths(params[:release])
end
#####################################################
# @!group Documentation
#####################################################
def self.description
"Build your Ionic app"
end
def self.details
"Easily integrate your Ionic build into a Fastlane setup"
end
def self.available_options
[
FastlaneCore::ConfigItem.new(
key: :platform,
env_name: "CORDOVA_PLATFORM",
description: "Platform to build on. Should be either android or ios",
is_string: true,
default_value: '',
verify_block: proc do |value|
UI.user_error!("Platform should be either android or ios") unless ['', 'android', 'ios'].include? value
end
),
FastlaneCore::ConfigItem.new(
key: :release,
env_name: "CORDOVA_RELEASE",
description: "Build for release if true, or for debug if false",
is_string: false,
default_value: true,
verify_block: proc do |value|
UI.user_error!("Release should be boolean") unless [false, true].include? value
end
),
FastlaneCore::ConfigItem.new(
key: :device,
env_name: "CORDOVA_DEVICE",
description: "Build for device",
is_string: false,
default_value: true,
verify_block: proc do |value|
UI.user_error!("Device should be boolean") unless [false, true].include? value
end
),
FastlaneCore::ConfigItem.new(
key: :type,
env_name: "CORDOVA_IOS_PACKAGE_TYPE",
description: "This will determine what type of build is generated by Xcode. Valid options are development, enterprise, adhoc, and appstore",
is_string: true,
default_value: 'appstore',
verify_block: proc do |value|
UI.user_error!("Valid options are development, enterprise, adhoc, and appstore.") unless ['development', 'enterprise', 'adhoc', 'appstore', 'ad-hoc', 'app-store'].include? value
end
),
FastlaneCore::ConfigItem.new(
key: :team_id,
env_name: "CORDOVA_IOS_TEAM_ID",
description: "The development team (Team ID) to use for code signing",
is_string: true,
default_value: CredentialsManager::AppfileConfig.try_fetch_value(:team_id)
),
FastlaneCore::ConfigItem.new(
key: :provisioning_profile,
env_name: "CORDOVA_IOS_PROVISIONING_PROFILE",
description: "GUID of the provisioning profile to be used for signing",
is_string: true,
default_value: ''
),
FastlaneCore::ConfigItem.new(
key: :keystore_path,
env_name: "CORDOVA_ANDROID_KEYSTORE_PATH",
description: "Path to the Keystore for Android",
is_string: true,
default_value: ''
),
FastlaneCore::ConfigItem.new(
key: :keystore_password,
env_name: "CORDOVA_ANDROID_KEYSTORE_PASSWORD",
description: "Android Keystore password",
is_string: true,
default_value: ''
),
FastlaneCore::ConfigItem.new(
key: :key_password,
env_name: "CORDOVA_ANDROID_KEY_PASSWORD",
description: "Android Key password (default is keystore password)",
is_string: true,
default_value: ''
),
FastlaneCore::ConfigItem.new(
key: :keystore_alias,
env_name: "CORDOVA_ANDROID_KEYSTORE_ALIAS",
description: "Android Keystore alias",
is_string: true,
default_value: ''
),
FastlaneCore::ConfigItem.new(
key: :build_number,
env_name: "CORDOVA_BUILD_NUMBER",
description: "Build Number for iOS",
optional: true,
is_string: false
),
FastlaneCore::ConfigItem.new(
key: :browserify,
env_name: "CORDOVA_BROWSERIFY",
description: "Specifies whether to browserify build or not",
default_value: false,
is_string: false
),
FastlaneCore::ConfigItem.new(
key: :cordova_prepare,
env_name: "CORDOVA_PREPARE",
description: "Specifies whether to run `ionic cordova prepare` before building",
default_value: true,
is_string: false
)
]
end
def self.output
[
['CORDOVA_ANDROID_RELEASE_BUILD_PATH', 'Path to the signed release APK if it was generated'],
['CORDOVA_IOS_RELEASE_BUILD_PATH', 'Path to the signed release IPA if it was generated']
]
end
def self.authors
['Jan Piotrowski']
end
def self.is_supported?(platform)
true
end
def self.example_code
[
"ionic(
platform: 'ios'
)",
"ionic(
platform: 'android',
keystore_path: './staging.keystore',
keystore_alias: 'alias_name',
keystore_password: 'store_password'
)"
]
end
def self.category
:building
end
end
end
end