-
Notifications
You must be signed in to change notification settings - Fork 2
/
push.rb
1347 lines (1106 loc) · 46.8 KB
/
push.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
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Push Generator - v1.2.0
# ©Christopher Guess 2018
require 'optparse'
require 'byebug'
require 'yaml'
require 'json'
require 'erb'
require 'fileutils'
require 'find'
require 'mini_magick'
require 'pp'
require 'commander/import'
require 'open3'
require 'java-properties'
require 'pty'
require 'expect'
require 'credentials_manager'
require 'fileutils'
program :name, 'Push App Generator'
program :version, '1.2.0'
program :description, 'A script to automatically generate iOS and Android apps for the Push ecosystem'
Options = Struct.new(:file_name, :upgrade, :production, :development, :snapshot, :beta, :mode, :android_path, :ios_path, :offline, :new, :certs, :force)
Languages = { "az": "Azerbaijnai",
"bg": "Bulgaria",
"bs": "Bosnian",
"en": "English",
"ka": "Georgian",
"ro": "Romanian",
"sr": "Serbian",
"ru": "Russian"
}
class Parser
def self.parse(options)
args = Options.new(options)
opt_parser = OptionParser.new do |opts|
opts.banner = "Usage: bundle exec ruby push.rb [options]"
opts.on("-fFILE", "--file=FILE", "File name for settings") do |n|
args.file_name = n
end
opts.on("-u", "--upgrade", "Flag for upgrading the code of the apps. Exits after the upgrade is complete and build settings are ignored.") do |n|
args.upgrade = true
end
opts.on("-p", "--production", "Flag for production push") do
args.production = true
end
opts.on("-s", "--snapshot", "Flag for only making screenshots BROKEN") do
args.snapshot = true
end
opts.on("-b", "--beta", "Flag for beta push") do
args.beta = true
end
opts.on("-d", "--development", "Flag to set up an initial development version. In Android this changes the app name to com.pushapp.press for Git purposes.") do
args.development = true
end
opts.on("-o", "--offline", "Flag for testing when offline, supercedes beta/production flags") do
args.offline = true
end
opts.on("-n", "--new", "Flag creating a new application, runs 'produce' to create app on iTunes and Apple Developer Console") do
args.new = true
end
opts.on("-c", "--certs", "Flag for generating push notification certificates and prepping them for proper installation. Right now only works for iOS.") do
args.certs = true
end
opts.on("--force", "Flag for forcing pem regeneration. Ignored by the rest of the commands.") do
args.force = true
end
opts.on("-mMODE", "--mode=mode", "Flag for Android (android) or iOS (ios), e.g. -m android") do |n|
args.mode = n
end
opts.on("-aANDROID_PATH", "--android-path=android_path", "Path to Android base app, if not passed the user will be prompted during the build") do |n|
args.android_path = n
end
opts.on("-iIOS_PATH", "--ios-path=ios_path", "Path to iOS base app, if not passed the user will be prompted during the build") do |n|
args.ios_path = n
end
opts.on("-h", "--help", "Prints this help") do
puts opts
exit
end
end
opt_parser.parse!(options)
return args
end
end
class Generator
def self.generate options, version_number, build_number, mode, production=false, settings_only=false
#1.) Check if there's a file indicated in the call - DONE
#2.) If there's not a file, look for push-mobile.yml - DONE
file_content = load_file(options[:file_name], 'push-mobile.yml')
if(file_content.nil?)
return
end
#3.) Load and parse file - DONE
settings = parse_yaml_content(file_content)
credentials_content = load_file(settings['credentials-file'], 'push-mobile-credentials.yml')
credentials = parse_yaml_content(credentials_content)
#4.) Check format
settings = verify_settings_format settings
credentials = verify_credentials_format credentials
if(credentials.nil?)
return
end
settings[:credentials] = credentials
settings[:build_number] = build_number
settings[:version_number] = version_number
settings[:language_names] = parse_languages settings['languages']
settings[:itunes_languages] = handle_apple_languages settings['languages']
if(!settings['default_language'].nil? && settings['default_language'].empty?)
settings[:default_language_name] = settings[:language_names].first
else
settings[:default_language_name] = Languages[settings['default_language']]
end
# Check if the images coming in are the proper ratios
if !ImageProcessor.check_image_is_square settings['icon-large']
message = []
message << "The icon image " + settings['icon-large'].yellow + " is not square."
message << "Please crop the image so that it is the same height as width before proceeding."
error message
end
if !ImageProcessor.check_image_is_longer_than_wide settings['icon-navigation-bar']
message = []
message << "The icon image " + settings['icon-large'].yellow + " must be wider than tall."
message << "Please rotate or resize the image so that it is wider than tall."
error message
end
settings[:debug] = !production
return settings if settings_only == true
# pp settings
#5.) Parse file into iOS format
case mode
when :iOS
generateiOSSettingsFile settings
when :android
generateAndroidSettingsFile settings
end
return settings
#pp generateiOSSettingsFile settings
#6.) Parse file into Android format
#8.) Run Fastlane for iOS
#9.) Run Fastlane for Android
#10.) Success!!!
end
def self.load_file file_name, default_name
if(file_name.nil? || file_name.empty?)
file_name = default_name
end
if(File.file?(file_name) == false)
pp "Missing file named #{file_name} to parse."
return nil
else
content = ""
File.open(file_name, "r") do |f|
f.each_line do |line|
content += line
end
end
return content
end
end
def self.copy_file start_location, end_location
error = nil
if(start_location.nil? || start_location.empty?)
error = "Start location cannot be empty"
elsif(start_location.nil? || start_location.empty?)
error = "Start location cannot be empty"
elsif(File.file?(start_location) == false)
error = "No file named #{start_location} found to copy"
end
if(!error.nil?)
pp error
return
end
FileUtils.cp(start_location, end_location)
end
def self.parse_yaml_content content
return YAML.load(content)
end
def self.verify_settings_format settings
settings_to_verify = ['name', 'short-name', 'ios-bundle-identifier', 'languages', 'icon-large', 'icon-navigation-bar', 'navigation-bar-color', 'navigation-text-color']
settings_to_verify.each do |setting|
self.check_for_setting(setting, settings)
end
# Make sure the languages is set up correctly etc.
if(settings['languages'].size == 0)
raise "More than one language must be included in the 'languages' array"
end
# If the default language is not in the languages array throw an error
# If there is no default language, set the first in the list to it
if(settings.has_key?('default-language'))
default_language = settings['default-language']
if(settings['languages'].include?(default_language) == false)
raise "'default-language' must be included in 'language' array"
end
else
settings['default-language'] = settings['languages'].first
pp settings['languages']
end
if(settings.has_key?('icon-background-color') == false)
settings['icon-background-color'] = '#FFFFFF'
end
if(settings.has_key?('launch-background-color') == false)
settings['launch-background-color'] = '#FFFFFF'
end
if(settings.has_key?('login-required') == false)
settings['login-required'] = 'false'
end
if(settings.has_key?('credentials-file') == false)
settings['credentials-file'] = 'push-mobile-credentials.yml'
end
return settings
end
def self.verify_credentials_format credentials
settings_to_verify = ['server-url', 'origin-url', 'uniqush', 'play-store-app-number', 'fabric-key', 'apple-developer-email','apple-developer-team-id']
settings_to_verify.each do |setting|
self.check_for_setting(setting, credentials)
end
return credentials
end
def self.check_for_setting setting_name, settings
if(settings.has_key?(setting_name) == false)
raise "No '#{setting_name}' key found in settings"
end
if(settings[setting_name].nil? || settings[setting_name].empty?)
puts "'#{setting_name}' in settings file not properly formatted.".red
exit
end
return true
end
def self.parse_languages languages
language_strings = []
languages.each do |language|
if(Languages.has_key?(language.to_sym))
language_strings << Languages[language.to_sym]
else
puts "The language '#{language}' is not currently supported by Push.\nIf you'd like to add it please check ***link to doc****".red
exit
end
end
return language_strings
end
def self.handle_apple_languages languages
# So Apple supports a lot less languages on the app store than it does in ios
# This makes sure that we don't accidently try to register a wrong language
# If there's none, we default to general "English"
available_languages = ["Brazilian Portuguese", "Danish", "Dutch", "English", "English_Australian", "English_CA", "English_UK", "Finnish", "French", "French_CA", "German", "Greek", "Indonesian", "Italian", "Japanese", "Korean", "Malay", "Norwegian", "Portuguese", "Russian", "Simplified Chinese", "Spanish", "Spanish_MX", "Swedish", "Thai", "Traditional Chinese", "Turkish", "Vietnamese"]
languages = languages.map{|language| Languages[language.to_sym] if available_languages.include?(Languages[language.to_sym])}.compact
languages = ['English'] if languages.empty?
return languages
end
def self.generateiOSSettingsFile settings
template = self.loadTemplate('iOS-Security')
rendered_template = self.generateSettingsFile settings, template
saveFile 'ios/SecretKeys.plist', rendered_template
template = self.loadTemplate('iOS-Settings')
rendered_template = self.generateSettingsFile settings, template
saveFile 'ios/CustomizedSettings.plist', rendered_template
template = self.loadTemplate('iOS-Info')
rendered_template = self.generateSettingsFile settings, template
saveFile 'ios/Info.plist', rendered_template
template = self.loadTemplate('iOS-PBX')
rendered_template = self.generateSettingsFile settings, template
saveFile 'ios/project.pbxproj', rendered_template
template = self.loadTemplate('iOS-Fastfile')
rendered_template = self.generateSettingsFile settings, template
saveFile 'ios/Fastfile', rendered_template
template = self.loadTemplate('iOS-Appfile')
rendered_template = self.generateSettingsFile settings, template
saveFile 'ios/Appfile', rendered_template
template = self.loadTemplate('iOS-Snapfile')
rendered_template = self.generateSettingsFile settings, template
saveFile 'ios/Snapfile', rendered_template
end
def self.generateAndroidSettingsFile settings
template = self.loadTemplate('Android-Safe-Variables')
rendered_template = self.generateSettingsFile settings, template
saveFile 'android/safe_variables.gradle', rendered_template
template = self.loadTemplate('Android-Colors')
rendered_template = self.generateSettingsFile settings, template
saveFile 'android/colors.xml', rendered_template
template = self.loadTemplate('Android-Manifest')
rendered_template = self.generateSettingsFile settings, template
saveFile 'android/AndroidManifest.xml', rendered_template
template = self.loadTemplate('Android-Manifest-Debug')
rendered_template = self.generateSettingsFile settings, template
saveFile 'android/AndroidManifestDebug.xml', rendered_template
template = self.loadTemplate('Android-Build-Gradle')
rendered_template = self.generateSettingsFile settings, template
saveFile 'android/build.gradle', rendered_template
template = self.loadTemplate('Android-Screengrabfile')
rendered_template = self.generateSettingsFile settings, template
saveFile 'android/Screengrabfile', rendered_template
template = self.loadTemplate('Android-Fastfile')
rendered_template = self.generateSettingsFile settings, template
saveFile 'android/Fastfile', rendered_template
template = self.loadTemplate('Android-Appfile')
rendered_template = self.generateSettingsFile settings, template
saveFile 'android/Appfile', rendered_template
end
def self.generateSettingsFile settings, template
b = binding
b.local_variable_set :setting, settings
@rendered
ERB.new(template, nil, '%<>-', "@rendered").result(b)
return @rendered
end
def self.loadTemplate type
content = nil
case type
when 'iOS-Security'
content = self.load_file('templates/ios/ios_secrets_template.erb', 'templates/ios/ios_secrets_template.erb')
when 'iOS-Settings'
content = self.load_file('templates/ios/ios_settings_template.erb', 'templates/ios/ios_settings_template.erb')
when 'iOS-Info'
content = self.load_file('templates/ios/ios_info_template.erb', 'templates/ios/ios_info_template.erb')
when 'iOS-PBX'
content = self.load_file('templates/ios/ios_project_pbxproj.erb', 'templates/ios/ios_project_pbxproj.erb')
when 'iOS-Fastfile'
content = self.load_file('templates/ios/ios_fastfile_template.erb', 'templates/ios/ios_fastfile_template.erb')
when 'iOS-Appfile'
content = self.load_file('templates/ios/ios_appfile_template.erb', 'templates/ios/ios_appfile_template.erb')
when 'iOS-Snapfile'
content = self.load_file('templates/ios/ios_snapfile_template.erb', 'templates/ios/ios_snapfile_template.erb')
when 'Android-Safe-Variables'
content = self.load_file('templates/android/android_safe_variable_gradle_template.erb', 'templates/android/android_safe_variable_gradle_template.erb')
when 'Android-Colors'
content = self.load_file('templates/android/android_colors_xml.erb', 'templates/android/android_colors_xml.erb')
when 'Android-Manifest'
content = self.load_file('templates/android/android_manifest_xml.erb', 'templates/android/android_manifest_xml.erb')
when 'Android-Manifest-Debug'
content = self.load_file('templates/android/android_manifest_debug_xml.erb', 'templates/android/android_manifest_debug_xml.erb')
when 'Android-Build-Gradle'
content = self.load_file('templates/android/android_build_gradle.erb', 'templates/android/android_build_gradle.erb')
when 'Android-Screengrabfile'
content = self.load_file('templates/android/android_screengrabfile.erb', 'templates/android/android_build_gradle.erb')
when 'Android-Fastfile'
content = self.load_file('templates/android/android_fastfile.erb', 'templates/android/android_fastfile.erb')
when 'Android-Appfile'
content = self.load_file('templates/android/android_appfile.erb', 'templates/android/android_appfile.erb')
end
return content
end
def self.saveFile file_name, content
dirname = File.dirname(file_name)
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
if(File.exist?(file_name))
File.delete(file_name)
end
File.open(file_name, 'w') do |file|
file.puts(content)
end
end
def self.setAndroidTitle settings, root_path
#Set the name of the app in all relevant language files
folders = ["values"]
settings['languages'].each do |language|
if(language == "sr")
folders << "values-b+sr+Latn"
elsif(language != "en")
folders << "values-" + language
end
end
folders.each do |folder|
path = root_path + "/app/src/main/res/" + folder + "/strings.xml"
text = File.read(path)
replaced_text = text.gsub(/<string name=\"app_name\">[A-z0-9\s]*<\/string>/, "<string name=\"app_name\">#{settings['name']}<\/string>")
tmp_file_path = 'templates/android/strings/' + folder + '_strings.xml'
File.write(tmp_file_path, replaced_text)
FileUtils.cp(tmp_file_path, path)
end
end
end
class ImageProcessor
def self.check_image_is_square image_name
image = MiniMagick::Image.open("images/#{image_name}")
raise "Image not found at images/#{image_name}" if image.nil?
return image.dimensions[0] == image.dimensions[1] ? true : false
end
def self.check_image_is_longer_than_wide image_name
image = MiniMagick::Image.open("images/#{image_name}")
raise "Image not found at images/#{image_name}" if image.nil?
return image.dimensions[0] >= image.dimensions[1] ? true : false
end
def self.process_ios_logo image_name, final_location
image_sizes = {
["images/images-generated/ios/app-store-icon.png"] => "1024x1024",
["images/images-generated/ios/launch-screen-logo@3x.png"] => "708x708",
["images/images-generated/ios/logo-512.png"] => "512x512",
["images/images-generated/ios/icon-appstore.png"] => "512x512",
["images/images-generated/ios/icon@2x-2.png","images/images-generated/ios/icon@2x-6.png"] => "360x360",
["images/images-generated/ios/icon 167x167-1.png"] => "180x180",
["images/images-generated/ios/icon 167x167.png", "images/images-generated/ios/icon 167x167-2.png"] => "167x167",
["images/images-generated/ios/icon@2x-4.png", "images/images-generated/ios/icon 152x152.png"] => "152x152",
["images/images-generated/ios/icon 120x120.png", "images/images-generated/ios/icon@3x-1.png"] => "120x120",
["images/images-generated/ios/icon-spotlight@3x.png"] => "80x80",
["images/images-generated/ios/icon@3x.png"] => "87x87",
["images/images-generated/ios/icon@2x-3.png","images/images-generated/ios/icon@2x-5.png",] => "80x80",
["images/images-generated/ios/icon-spotlight@2x.png"] => "80x80",
["images/images-generated/ios/icon@1x-2.png"] => "76x76",
["images/images-generated/ios/icon@2x-1.png","images/images-generated/ios/icon@2x.png"] => "58x58",
["images/images-generated/ios/icon@1x-1.png"] => "40x40",
["images/images-generated/ios/icon-spotlight.png"] => "80x80",
["images/images-generated/ios/icon@1x.png"] => "29x29",
}
process image_sizes, image_name, final_location
end
def self.process_ios_header_icon image_name, final_location
image_sizes = {
["images/images-generated/ios/logo@3x.png"] => "500x132",
["images/images-generated/ios/logo@2x.png"] => "500x88",
["images/images-generated/ios/logo@1x.png"] => "500x44",
}
process image_sizes, image_name, final_location
end
def self.process_android_logo image_name, final_location
feature_graphic_image_sizes = {
["images/images-generated/andoird/feature_graphic.png"] => "1024x500"
}
xxhdpi_image_sizes = {
["images/images-generated/android/ic_launcher.png"] => "144x144",
}
drawable_image_sizes = {
["images/images-generated/android/ic_launcher.png"] => "144x144",
}
xhdpi_image_sizes = {
["images/images-generated/android/ic_launcher.png"] => "96x96",
}
hdpi_image_sizes = {
["images/images-generated/android/ic_launcher.png"] => "72x72",
}
mdpi_image_sizes = {
["images/images-generated/android/ic_launcher.png"] => "48x48",
}
process feature_graphic_image_sizes, image_name, (final_location + "/mipmap-xxxhdpi")
process xxhdpi_image_sizes, image_name, (final_location + "/mipmap-xxhdpi")
process drawable_image_sizes, image_name, (final_location + "/drawable")
process xhdpi_image_sizes, image_name, (final_location + "/mipmap-xhdpi")
process hdpi_image_sizes, image_name, (final_location + "/mipmap-hdpi")
process mdpi_image_sizes, image_name, (final_location + "/mipmap-mdpi")
end
def self.process_android_button_images color, final_location
change_color 'images/android/ic_language.png', color, 'ic_language.png'
xxhdpi_image_sizes = {
["images/images-generated/android/ic_language.png"] => "108x78",
}
xhdpi_image_sizes = {
["images/images-generated/android/ic_language.png"] => "72x52",
}
hdpi_image_sizes = {
["images/images-generated/android/ic_language.png"] => "54x39",
}
mdpi_image_sizes = {
["images/images-generated/android/ic_language.png"] => "36x26",
}
process_mipmap_images [xxhdpi_image_sizes, xhdpi_image_sizes, hdpi_image_sizes, mdpi_image_sizes], 'images-generated/android/ic_language.png', final_location
change_color 'images/android/about.png', color, 'about.png'
xxhdpi_image_sizes = {
["images/images-generated/android/about.png"] => "68x70",
}
xhdpi_image_sizes = {
["images/images-generated/android/about.png"] => "68x70",
}
hdpi_image_sizes = {
["images/images-generated/android/about.png"] => "34x35",
}
mdpi_image_sizes = {
["images/images-generated/android/about.png"] => "34x35",
}
process_mipmap_images [xxhdpi_image_sizes, xhdpi_image_sizes, hdpi_image_sizes, mdpi_image_sizes], 'images-generated/android/about.png', final_location
change_color 'images/android/ic_action_cancel.png', color, 'ic_action_cancel.png'
xxhdpi_image_sizes = {
["images/images-generated/android/ic_action_cancel.png"] => "96x96",
}
xhdpi_image_sizes = {
["images/images-generated/android/ic_action_cancel.png"] => "64x64",
}
hdpi_image_sizes = {
["images/images-generated/android/ic_action_cancel.png"] => "34x35",
}
mdpi_image_sizes = {
["images/images-generated/android/ic_action_cancel.png"] => "34x35",
}
process_mipmap_images [xxhdpi_image_sizes, xhdpi_image_sizes, hdpi_image_sizes, mdpi_image_sizes], 'images-generated/android/ic_action_cancel.png', final_location
change_color 'images/android/ic_search_white.png', color, 'ic_search_white.png'
xxhdpi_image_sizes = {
["images/images-generated/android/ic_search_white.png"] => "144x144",
}
xhdpi_image_sizes = {
["images/images-generated/android/ic_search_white.png"] => "96x96",
}
hdpi_image_sizes = {
["images/images-generated/android/ic_search_white.png"] => "72x72",
}
mdpi_image_sizes = {
["images/images-generated/android/ic_search_white.png"] => "48x48",
}
process_mipmap_images [xxhdpi_image_sizes, xhdpi_image_sizes, hdpi_image_sizes, mdpi_image_sizes], 'images-generated/android/ic_search_white.png', final_location
change_color 'images/android/ic_share_white_48dp.png', color, 'ic_share_white_48dp.png'
xxhdpi_image_sizes = {
["images/images-generated/android/ic_share_white_48dp.png"] => "144x144",
}
xhdpi_image_sizes = {
["images/images-generated/android/ic_share_white_48dp.png"] => "96x96",
}
hdpi_image_sizes = {
["images/images-generated/android/ic_share_white_48dp.png"] => "72x72",
}
mdpi_image_sizes = {
["images/images-generated/android/ic_share_white_48dp.png"] => "48x48",
}
process_mipmap_images [xxhdpi_image_sizes, xhdpi_image_sizes, hdpi_image_sizes, mdpi_image_sizes], 'images-generated/android/ic_share_white_48dp.png', final_location
#1.) change the colors
#2.) size the files correctly
#3.) place them into the correct android mipmap folders
#copy from the header right below
end
def self.process_mipmap_images sizes, name, final_location
process sizes[0], name, (final_location + "/mipmap-xxhdpi")
process sizes[1], name, (final_location + "/mipmap-xhdpi")
process sizes[2], name, (final_location + "/mipmap-hdpi")
process sizes[3], name, (final_location + "/mipmap-mdpi")
end
def self.process_android_header_icon image_name, final_location
xxhdpi_image_sizes = {
["images/images-generated/android/logo.png"] => "800x128",
}
xhdpi_image_sizes = {
["images/images-generated/android/logo.png"] => "800x92",
}
hdpi_image_sizes = {
["images/images-generated/android/logo.png"] => "800x64",
}
mdpi_image_sizes = {
["images/images-generated/android/logo.png"] => "800x48",
}
process xxhdpi_image_sizes, image_name, (final_location + "/mipmap-xxhdpi")
process xhdpi_image_sizes, image_name, (final_location + "/mipmap-xhdpi")
process hdpi_image_sizes, image_name, (final_location + "/mipmap-hdpi")
process mdpi_image_sizes, image_name, (final_location + "/mipmap-mdpi")
end
def self.process image_sizes, image_name, final_location
dirname = File.dirname(final_location)
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
image = MiniMagick::Image.open("images/#{image_name}")
image_sizes.keys.each do |key|
key.each do |file_name|
image.resize image_sizes[key]
image.format "png"
dirname = File.dirname(file_name)
FileUtils.mkdir_p(dirname) unless File.directory?(dirname)
image.write file_name
FileUtils.cp(file_name, final_location)
end
end
end
def self.change_color image_name, color, final_name
#image = MiniMagick::Image.open("images/#{image_name}")
MiniMagick::Tool::Convert.new do |convert|
#convert.fill(start_color)
convert.merge! [image_name, '-channel', 'RGB', '-fill', color, '+opaque', color, '-fuzz', '20%', "images/images-generated/android/#{final_name}"]
end #=> `mogrify -resize 100x100 -negate image.jpg`
end
#Takes hex
def self.generateSolidColor color, file_name
MiniMagick::Tool::Convert.new do |convert|
convert.merge! ["-size", "1200x1200", "xc:#{color}"]
convert << file_name
end
end
end
def generateIOS options, version_number = "1.0", build_number = "1"
settings = Generator.generate options, version_number.strip, build_number.strip, :iOS
if(options[:ios_path].nil? || options[:ios_path].empty?)
p "Current path is: #{Dir.pwd}"
project_path = ask "iOS Project Path: "
project_path.strip!
else
project_path = options[:ios_path]
p "iOS build path is #{project_path}"
end
if(File.exist?(project_path) == false)
p "iOS build path directory not found."
abort
end
keys_final_location = project_path + "/" + "Push"
FileUtils.cp("./ios/SecretKeys.plist", keys_final_location)
FileUtils.cp("./ios/CustomizedSettings.plist", keys_final_location)
FileUtils.cp("./ios/Info.plist", keys_final_location)
FileUtils.cp("./ios/project.pbxproj", project_path + "/Push.xcodeproj")
FileUtils.cp("./ios/Fastfile", project_path + "/fastlane")
FileUtils.cp("./ios/Appfile", project_path + "/fastlane")
FileUtils.cp("./ios/Snapfile", project_path + "/fastlane")
ImageProcessor.process_ios_logo settings['icon-large'], project_path + "/Push/Assets.xcassets/AppIcon.appiconset"
ImageProcessor.process_ios_logo settings['icon-large'], project_path + "/Push"
ImageProcessor.process_ios_header_icon settings['icon-navigation-bar'], project_path + "/Push"
solid_color_image = "images/images-generated/launch-background-color@3x.png"
ImageProcessor.generateSolidColor settings['launch-background-color'], solid_color_image
FileUtils.cp(solid_color_image, project_path + "/Push")
suffix = ""
if(settings['suffix'].nil? == false && settings['suffix'].empty? == false)
suffix = "-#{settings['suffix']}"
end
settings['languages'].each do |language|
about_file_path = project_path + "/Push/" + "about_text-#{language}.html"
if(File.file?(about_file_path))
File.delete(about_file_path)
end
begin
FileUtils.cp("about-html/about_text-#{language}#{suffix}.html", about_file_path)
rescue
message = []
message << " No " + "about-html/about_text-#{language}#{suffix}.html".yellow + " file found for "+"#{settings['suffix']}".green
message << " This is because you have not added the about.html file for the language "+ Languages[language.to_sym].green+"."
message << "\n"
message << " Please create the about file and try running this again."
error message
end
end
if(File.file?("promotions/promotions#{suffix}.yml"))
FileUtils.cp("promotions/promotions#{suffix}.yml", project_path + "/Assets/promotions.yml")
end
file_suffix = nil
Dir.chdir(project_path) do
if(options[:snapshot] == true)
p system('snapshot')
break
end
lane = nil
if(options[:offline] == true)
lane = "ios offline"
file_suffix = "offline"
elsif(options[:development] == true)
lane = "ios bootstrap"
file_suffix = "dev"
elsif(options[:production] == true)
lane = "ios deploy"
file_suffix = "prod"
elsif(options[:beta] == true)
build_notes = ask "Build notes?: "
lane = "ios beta notes:#{build_notes}"
file_suffix = "beta"
else
lane = "ios gen_test"
file_suffix = "beta"
end
# The first time through we need to make sure that all the gems are installed in the iOS
# app repository.
p system("bundle install")
p system("bundle exec fastlane create") if(options[:new] == true)
loop do
cmd = "bundle exec fastlane #{lane}"
status = true
error = nil
exit_status = nil
#TTY::Command.new(pty: true).run(cmd)
CredentialsManager::AccountManager.new().password
# PTY.spawn(cmd) do |reader, writer, pid|
# begin
# # Do stuff with the output here. Just printing to show it works
# reader.each { |line| print line }
# # reader.expect "Please enter the 6 digit code:" do
# # code = ask ("Two factor code: ")
# # writer.puts code
# # end
# # reader.expect /Password/ do
# # password = ask "Password: "
# # writer.puts password
# # end
# # reader.expect /(Multiple Teams found on the Developer Portal, please enter).+/ do
# # code = ask "Number of organization."
# # writer.puts code
# # end
# reader.expect "Could not find App with App Identifier" do
# byebug
# status = false
# error = :no_app
# end
# reader.expect "Missing password for user" do
# byebug
# status = false
# error = :missing_password
# end
# rescue Errno::EIO
# puts "Errno:EIO error, but this probably just means " +
# "that the process has finished giving output"
# end
# end
#response = process(cmd, {log: true, pty: true})
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
while line = stdout.gets
puts line
if line.include?("Could not find App with App Identifier")
status = false
error = :no_app
elsif line.include?("Missing password for user")
status = false
error = :missing_password
end
end
exit_status = wait_thr.value
end
if(!status)
case error
when :no_app
say "It seems as if the app doesn't exist yet on your Apple developer account"
should_continue = agree "Would you like to add it [yes/no]?: "
when :missing_password
add_apple_developer_user settings[:credentials]['apple-developer-email']
should_continue = true
else
p "Unknown error occured. Please file a bug report at https://github.com/PushOCCRP/Push-Generator"
should_continue = false
end
exit if should_continue == false
add_appple_developer_app settings
else
exit unless exit_status == :success
say "Everything looks like it worked properly. 🎈🎈🎈"
break;
end
end
end
Generator.copy_file(project_path + "/Push.ipa", "#{Dir.pwd}/finals/ios/#{binaryName(settings, file_suffix)}.ipa")
end
def add_appple_developer_app settings
cmd = "produce -q '#{settings['name']}' -c '#{settings['company-name']}'"
status = true
exit_status = nil
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
while line = stdout.gets
puts line
status = false if line.include?("Missing password for user")
end
exit_status = wait_thr.value
end
if(!status)
add_appple_developer_user settings[:credentials]['apple-developer-email']
else
exit unless exit_status.success?
end
end
def add_apple_developer_user email
say "Please login to your Apple Developer Account: #{email}".green
password = ask("Password: ") { |q| q.echo = "*" }
cmd = "fastlane fastlane-credentials add --username #{email} --password #{password}"
status = false
Open3.popen3(cmd) do |stdin, stdout, stderr, wait_thr|
while line = stdout.gets
puts line
status = true if line.include?("added to keychain.")
end
exit_status = wait_thr.value
exit unless exit_status.success?
end
p "Added #{email} to your keychain."
end
def generateAndroid options, version_number = "1.0", build_number = "1"
settings = Generator.generate options, version_number, build_number, :android, options[:production]
suffix = ""
if(settings['suffix'].nil? == false && settings['suffix'].empty? == false)
suffix = "-#{settings['suffix']}"
end
if(options[:android_path].nil? || options[:android_path].empty?)
p "Current path is: #{Dir.pwd}"
project_path = ask "Android Project Path: "
project_path.strip!
else
project_path = options[:android_path]
p "Android build path is #{project_path}"
end
if(File.exist?(project_path) == false)
p "Android base project directory not found."
abort
end
Generator.setAndroidTitle settings, project_path
keys_final_location = project_path + "/" + "app"
if(!File.file?("./google-service/google-services#{suffix}.json"))
message = []
message << " No " + "google-services.json".yellow + " file found for "+"#{settings['suffix']}".green
message << " You probably need to create one still."
message << "\n"
message << " Instructions can be found in the README.md files, but here are some tips:"
message << " You can create your App in the Firebase console at " + "https://console.firebase.google.com".blue
message << " Next, click 'Add Firebase to your Android app' and fill in the details"
message << " Copy the "+"google-services.json".green + " file to the "+"./google-services".green + " folder in this repository"
error message
return
end
if(!File.file?("./google-services-account/google-services-account#{suffix}.json"))
message = []
message << " No " + "google-services-account.json".yellow + " file found for "+"#{settings['suffix']}".green
message << " You probably need to create one still."
message << "\n"
message << " Instructions can be found in the README.md files, but here are some tips:"
message << " To create the file go here: https://docs.fastlane.tools/getting-started/android/setup/"
message << " Copy the downloaded .json file to the "+"./google-services-account".green + " folder in this repository"
error message
return
end
# First we have to get the previous name being set
old_application_id = getPreviousAndroidApplicationID project_path
FileUtils.cp_r("./google-service/google-services#{suffix}.json", keys_final_location + "/google-services.json", remove_destination: true)
FileUtils.cp_r("./google-services-account/google-services-account#{suffix}.json", keys_final_location + "/google-services-account.json", remove_destination: true)
FileUtils.cp("./android/safe_variables.gradle", keys_final_location)
FileUtils.cp("./android/colors.xml", keys_final_location + "/src/main/res/values/")
FileUtils.cp("./android/AndroidManifest.xml", keys_final_location + "/src/main/")
FileUtils.cp("./android/AndroidManifestDebug.xml", keys_final_location + "/src/debug/AndroidManifest.xml")
FileUtils.cp("./android/build.gradle", keys_final_location)
FileUtils.cp("./android/Screengrabfile", keys_final_location + "/../fastlane/Screengrabfile")
FileUtils.cp("./android/Fastfile", keys_final_location + "/../fastlane/Fastfile")
FileUtils.cp("./android/Appfile", keys_final_location + "/../fastlane/Appfile")
ImageProcessor.process_android_logo settings['icon-large'], project_path + "/app/src/main/res"
ImageProcessor.process_android_header_icon settings['icon-navigation-bar'], project_path + "/app/src/main/res"
ImageProcessor.process_android_button_images settings['navigation-text-color'], project_path + "/app/src/main/res"
=begin
solid_color_image = "images/images-generated/launch-background-color@3x.png"
ImageProcessor.generateSolidColor settings['launch-background-color'], solid_color_image
FileUtils.cp(solid_color_image, project_path + "/Push")
=end
settings['languages'].each do |language|
FileUtils.cp("about-html/about_text-#{language}#{suffix}.html", project_path + "/app/src/main/assets/" + "about_text-#{language}.html")