Module: Pindo::XcodeHelper

Included in:
Command::Utils::Renewproj
Defined in:
lib/pindo/module/xcode/xcodehelper.rb

Instance Method Summary collapse

Instance Method Details

#add_file_to_target(new_proj_name: nil, new_proj_path: nil, new_proj_obj: nil, old_proj_name: nil, old_proj_path: nil, old_proj_obj: nil) ⇒ Object



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
# File 'lib/pindo/module/xcode/xcodehelper.rb', line 356

def add_file_to_target(new_proj_name:nil, new_proj_path:nil, new_proj_obj:nil,  old_proj_name:nil, old_proj_path:nil, old_proj_obj:nil)

    old_proj_target = old_proj_obj.targets.first 
    new_proj_target = new_proj_obj.targets.first 

    old_proj_obj.groups.each do |group|

        if group.display_name == "Pods" || group.display_name == "Frameworks" || group.display_name == "Products"
            puts group.display_name
        else

            new_target = new_proj_target
            new_group_name = group.display_name

            if group.display_name == old_proj_name + "iMessage" || group.display_name == old_proj_name + "Keyboard" || group.display_name == old_proj_name + "Extension" || group.display_name == old_proj_name + "NotificationService" || group.display_name == old_proj_name + "NotificationContent"
                new_group_name = group.display_name.gsub(old_proj_name, new_proj_name)
                puts "new_group_name +++ #{new_group_name}"
                puts "group.display_name +++ #{group.display_name}"
                new_target = get_target_by_name(proj_obj:new_proj_obj,name:new_group_name)
            end
            new_group = new_proj_obj.main_group.find_subpath(new_group_name, true)	
            new_group.set_source_tree(group.source_tree)
            puts group.source_tree
            new_group.set_path(File.join('./', new_group_name))	
            add_files_proj_with_dir(new_proj_obj:new_proj_obj, new_target:new_target, new_group:new_group)

            
        end
    end

    new_entitlements_plist = File.join(new_proj_path, new_proj_name + ".entitlements")
    if File.exist?(new_entitlements_plist) 
        new_proj_obj.main_group.new_reference(new_proj_name + ".entitlements") 
    end

    old_proj_obj.targets.each do |target|
        new_target_name = target.name.to_s.gsub(old_proj_name, new_proj_name)
        new_target = get_target_by_name(proj_obj:new_proj_obj,name:new_target_name)

        unless new_target.nil?

            device_mode = target.build_configuration_list.get_setting("TARGETED_DEVICE_FAMILY")["Release"]
            new_target.build_configuration_list.set_setting("TARGETED_DEVICE_FAMILY",  device_mode)

            target.frameworks_build_phase.files_references.each do |file|
                group = new_proj_obj.frameworks_group['iOS'] || new_proj_obj.frameworks_group.new_group('iOS')
                ref = group.find_file_by_path(file.path)
                if ref.nil?
                    ref = group.new_file(file.path, :sdk_root)
                end   
                ref.source_tree = file.source_tree
                new_target.frameworks_build_phase.add_file_reference(ref, true)
            end

            # target.resources_build_phase.files_references.each do |file|

            # end
            # target.source_build_phase.files_references.each do |file|

            # end

            old_group = old_proj_obj.main_group.find_subpath("PResources", false)	
            unless old_group.nil?
                new_group = new_proj_obj.main_group.find_subpath("PResources", false)	
                old_group.files.each do |file|
                    ref = new_group.find_file_by_path(file.path)
                    unless ref.nil?
                        if target.resources_build_phase.include?(file)
                            new_target.resources_build_phase.add_file_reference(ref, true)
                        else
                            new_target.resources_build_phase.remove_file_reference(ref)
                        end
                    end   
                end
            end
            
            old_group = old_proj_obj.main_group.find_subpath("Resources", false)	
            unless old_group.nil?
                new_group = new_proj_obj.main_group.find_subpath("Resources", false)	
                old_group.files.each do |file|
                    ref = new_group.find_file_by_path(file.path)
                    unless ref.nil?
                        if target.resources_build_phase.include?(file)
                            new_target.resources_build_phase.add_file_reference(ref, true)
                        else
                            new_target.resources_build_phase.remove_file_reference(ref)
                        end
                    end   
                end
            end

            # extention
            if new_target_name != new_proj_name

                if File.exist?(File.join(new_proj_path, new_target_name, new_target_name + ".entitlements"))
                    new_target.build_configuration_list.set_setting('CODE_SIGN_ENTITLEMENTS', File.join(new_target_name, new_target_name + ".entitlements"))
                end
            else
                
                if File.exist?(File.join(new_proj_path, new_target_name + ".entitlements"))
                    new_target.build_configuration_list.set_setting('CODE_SIGN_ENTITLEMENTS', File.join(new_target_name + ".entitlements"))
                end
            end 

        end
    end

    embed_content_build_phase = new_proj_target.new_copy_files_build_phase("Embed App Extensions")
    embed_content_build_phase.symbol_dst_subfolder_spec=:plug_ins
    new_proj_obj.products_group.files.each do |file|
        if file.path.to_s.end_with?(".appex")
            new_proj_target.add_file_references([file])
            embed_content_build_phase.add_file_reference(file)
        end
    end

end

#add_files_proj_with_dir(new_proj_obj: nil, new_target: nil, new_group: nil) ⇒ Object



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
# File 'lib/pindo/module/xcode/xcodehelper.rb', line 26

def add_files_proj_with_dir(new_proj_obj:nil, new_target:nil, new_group:nil)

    if File.exist?(new_group.real_path) 
  
        Dir.foreach(new_group.real_path) do |entry|
            filePath = File.join(new_group.real_path, entry)
            
            # puts filePath
            if entry.to_s.start_with?(".") then

            elsif filePath.to_s.end_with?(".DS_Store", ".xcconfig") then
                # ignore

            elsif filePath.to_s.end_with?(".lproj") then
                if @variant_group.nil?
                    @variant_group = new_group.new_variant_group("Localizable.strings");
                end
                string_file = File.join(filePath, "Localizable.strings")
                fileReference = @variant_group.new_reference(string_file)
                new_target.add_resources([fileReference])

            elsif is_resource_group(entry) then
                fileReference = new_group.new_reference(filePath)
                new_target.add_resources([fileReference])
            elsif !File.directory?(filePath) then

                # 向group中增加文件引用
                fileReference = new_group.new_reference(filePath)
                # 如果不是头文件则继续增加到Build Phase中
                if filePath.to_s.end_with?(".m", ".mm", ".cpp", ".swift") then
                    new_target.add_file_references([fileReference])
            # elsif filePath.to_s.end_with?("pbobjc.m", "pbobjc.mm") then
                    # new_target.add_file_references([fileReference], '-fno-objc-arc')
                    
                elsif filePath.to_s.end_with?(".pch") then

                elsif filePath.to_s.end_with?(".entitlements") then

                elsif filePath.to_s.end_with?("Info.plist") && entry == "Info.plist" then
                    
                elsif filePath.to_s.end_with?(".h") then
                    # new_target.headers_build_phase.add_file_reference(fileReference)
                elsif filePath.to_s.end_with?(".framework") || filePath.to_s.end_with?(".a") then
                    new_target.frameworks_build_phases.add_file_reference(fileReference)
                elsif 
                    new_target.add_resources([fileReference])
                end
            # 目录情况下, 递归添加
            elsif File.directory?(filePath) && entry != '.' && entry != '..' then
                sub_group = new_group.find_subpath(entry, true)
                sub_group.set_source_tree(new_group.source_tree)
                sub_group.set_path(File.join(new_group.real_path, entry))
                add_files_proj_with_dir(new_proj_obj:new_proj_obj, new_target:new_target, new_group:sub_group)
            end
        end
    end
end

#config_project_target(new_proj_name: nil, new_proj_path: nil, new_proj_obj: nil, old_proj_name: nil, old_proj_path: nil, old_proj_obj: nil) ⇒ Object



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
# File 'lib/pindo/module/xcode/xcodehelper.rb', line 288

def config_project_target(new_proj_name:nil, new_proj_path:nil, new_proj_obj:nil,  old_proj_name:nil, old_proj_path:nil, old_proj_obj:nil)
    new_proj_obj.root_object.known_regions = new_proj_obj.root_object.known_regions || []
    new_proj_obj.root_object.known_regions = new_proj_obj.root_object.known_regions | ['Base', 'EN', 'en', 'CN', 'de', 'es', 'fr', 'it', 'ja', 'ko', 'nl', 'pt', 'ru', 'th', 'zh-Hans', 'zh-Hant', 'ar', 'ca', 'cs', 'da', 'el', 'fi', 'he','hu','id','ms','nb', 'pl', 'pt-BR', 'ro', 'sk','sv','tr','uk','vi']

    new_proj_obj.root_object.build_configuration_list.set_setting('VALID_ARCHS', "arm64")
    new_proj_obj.root_object.build_configuration_list.set_setting('SDKROOT', "iphoneos")
    new_proj_obj.root_object.build_configuration_list.set_setting('CODE_SIGN_IDENTITY[sdk=iphoneos*]', "iPhone Developer")
    new_proj_obj.root_object.build_configuration_list.set_setting('CODE_SIGN_IDENTITY*', "iPhone Developer")

    new_proj_obj.targets.each do |target|

        target.build_configurations.each do |config|
            if target.name.to_s.end_with?("Content") then
                config_target(new_proj_obj:new_proj_obj, new_target:target, config:config, bundle_id:@bundle_id_pushcontent, is_extention:true,setting_array:['push_notification'])
            elsif target.name.to_s.end_with?("Service") then
                config_target(new_proj_obj:new_proj_obj, new_target:target, config:config, bundle_id:@bundle_id_pushservice, is_extention:true,setting_array:['push_notification'])
            elsif target.name.to_s.end_with?("Keyboard") then
                config_target(new_proj_obj:new_proj_obj, new_target:target, config:config, bundle_id:@bundle_id_keyboard, is_extention:true,setting_array:['app_group'])
            elsif target.name.to_s.end_with?("iMessage") then
                
                config_target(new_proj_obj:new_proj_obj, new_target:target, config:config, bundle_id:@bundle_id_imessage, is_extention:true,setting_array:['app_group'])
                if File.exist?(File.join(new_proj_path, target.display_name, "Assets.xcassets"))
                    config.build_settings['ASSETCATALOG_COMPILER_APPICON_NAME'] = "iMessage App Icon"
                end
            elsif target.name.to_s.end_with?("Extension") then
                config_target(new_proj_obj:new_proj_obj, new_target:target, config:config, bundle_id:@bundle_id_extension, is_extention:true,setting_array:['app_group'])
            elsif target.name.to_s.end_with?("ExtensionAd") then
                config_target(new_proj_obj:new_proj_obj, new_target:target, config:config, bundle_id:@bundle_id_extensionad, is_extention:true,setting_array:['app_group'])
            elsif target.name.to_s.end_with?("ExtensionPorn") then
                config_target(new_proj_obj:new_proj_obj, new_target:target, config:config, bundle_id:@bundle_id_extensionporn, is_extention:true,setting_array:['app_group'])
            else
                config_target(new_proj_obj:new_proj_obj, new_target:target, config:config, bundle_id:@bundle_id, is_extention:false,setting_array:['app_group','push_notification', 'in_app_purchase'])
            end
        end

    end

end

#config_target(new_proj_obj: nil, new_target: nil, config: nil, bundle_id: nil, is_extention: false, setting_array: nil) ⇒ Object



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
# File 'lib/pindo/module/xcode/xcodehelper.rb', line 86

def config_target(new_proj_obj:nil, new_target:nil, config:nil, bundle_id:nil, is_extention:false, setting_array:nil)
    
    new_proj_obj.root_object.attributes['TargetAttributes'] = new_proj_obj.root_object.attributes['TargetAttributes'] || {}
    target_atts_obj = new_proj_obj.root_object.attributes['TargetAttributes']
    target_atts_obj[new_target.uuid] = target_atts_obj[new_target.uuid] || {}
    target_atts_obj[new_target.uuid]['DevelopmentTeam'] = "9WX2E4VC26"
    target_atts_obj[new_target.uuid]['ProvisioningStyle'] = "Manual"
    target_atts_obj[new_target.uuid]['SystemCapabilities'] = {}

    target_systemcapabilities = target_atts_obj[new_target.uuid]['SystemCapabilities']
    if setting_array.to_s.include?("in_app_purchase")
        target_systemcapabilities['com.apple.InAppPurchase'] = {}
        target_systemcapabilities['com.apple.InAppPurchase']['enabled'] = 1
    else
        target_systemcapabilities['com.apple.InAppPurchase'] = {}
        target_systemcapabilities['com.apple.InAppPurchase']['enabled'] = 0
    end

    if setting_array.to_s.include?("push_notification")
        target_systemcapabilities['com.apple.Push'] = {}
        target_systemcapabilities['com.apple.Push']['enabled'] = 1
    else
        target_systemcapabilities['com.apple.Push'] = {}
        target_systemcapabilities['com.apple.Push']['enabled'] = 0
    end
  
    if setting_array.to_s.include?("app_group")
        target_systemcapabilities['com.apple.Group'] = {}
        target_systemcapabilities['com.apple.Group']['enabled'] = 1
    else
        target_systemcapabilities['com.apple.Group'] = {}
        target_systemcapabilities['com.apple.Group']['enabled'] = 0
    end

    config.build_settings['ENABLE_BITCODE'] = "NO";
    config.build_settings['SDKROOT'] = "iphoneos"
    config.build_settings['CODE_SIGN_IDENTITY[sdk=iphoneos*]'] = "iPhone Distribution"
    config.build_settings['CODE_SIGN_STYLE'] = "Manual"
    config.build_settings['CODE_SIGN_IDENTITY'] = "iPhone Developer"
    config.build_settings['DEVELOPMENT_TEAM'] = "9WX2E4VC26"
    config.build_settings['PROVISIONING_PROFILE'] = ""
    config.build_settings['PRODUCT_BUNDLE_IDENTIFIER'] = bundle_id
    config.build_settings['PROVISIONING_PROFILE_SPECIFIER'] = "match Development " + bundle_id
    # config.build_settings['TARGETED_DEVICE_FAMILY'] = "1,2"
    if is_extention
        config.build_settings['INFOPLIST_FILE'] = new_target.name +  "/Info.plist"
        config.build_settings['SKIP_INSTALL'] = "YES"

        if new_target.name.include?("iMessage")

            config.build_settings['LD_RUNPATH_SEARCH_PATHS'] = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"
            config.build_settings['PRODUCT_NAME'] = "$(TARGET_NAME)"

        elsif new_target.name.include?("Extension") || new_target.name.include?("ExtensionAd") || new_target.name.include?("ExtensionPorn") then
            config.build_settings['LD_RUNPATH_SEARCH_PATHS'] = "$(inherited) @executable_path/Frameworks @executable_path/../../Frameworks"
            config.build_settings['PRODUCT_NAME'] = "$(TARGET_NAME)"
            config.build_settings['ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME'] = "AccentColor"
            config.build_settings['ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME'] = "WidgetBackground"
        else
            config.build_settings['CLANG_WARN_SUSPICIOUS_MOVES'] = "YES"
            config.build_settings['CLANG_WARN_INFINITE_RECURSION'] = "YES"
            config.build_settings['CLANG_WARN_DOCUMENTATION_COMMENTS'] = "YES"
        end

    else
        
        config.build_settings['ASSETCATALOG_COMPILER_APPICON_NAME'] = "AppIcon"
        config.build_settings['INFOPLIST_FILE'] = "AppEntry/Info.plist"
        config.build_settings['ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES'] = "$(inherited)"
        config.build_settings['LD_GENERATE_MAP_FILE'] = "$(inherited)"
        config.build_settings['GCC_PRECOMPILE_PREFIX_HEADER'] = "NO"
        config.build_settings['LIBRARY_SEARCH_PATHS'] = "$(inherited)"
        config.build_settings['OTHER_CFLAGS'] = "$(inherited)"
        config.build_settings['PRODUCT_NAME'] = "$(TARGET_NAME)";
        config.build_settings['PRECOMPS_INCLUDE_HEADERS_FROM_BUILT_PRODUCTS_DIR'] = "NO";

        macros = config.build_settings['GCC_PREPROCESSOR_DEFINITIONS']
        if macros.nil? || macros == "" 
            config.build_settings['GCC_PREPROCESSOR_DEFINITIONS'] = "$(inherited)"
        end
        
    end

end

#copy_to_newproject(new_proj_path: nil, new_proj_name: nil, old_proj_path: nil, old_proj_name: nil) ⇒ Object



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
# File 'lib/pindo/module/xcode/xcodehelper.rb', line 171

def copy_to_newproject(new_proj_path:nil, new_proj_name:nil,  old_proj_path:nil, old_proj_name:nil)
    FileUtils.cp_r(File.join(old_proj_path, "AppEntry"), new_proj_path)
    if File.exist?(File.join(old_proj_path, "U3DLib")) 
        FileUtils.cp_r(File.join(old_proj_path, "U3DLib"), new_proj_path) 
    end

    if File.exist?(File.join(old_proj_path, "flutter_box")) 
        FileUtils.cp_r(File.join(old_proj_path, "flutter_box"), new_proj_path) 
    end

    if File.exist?(File.join(old_proj_path, "AppLogic")) 
        FileUtils.cp_r(File.join(old_proj_path, "AppLogic"), new_proj_path) 
    end

    if File.exist?(File.join(old_proj_path, "AppUI")) 
        FileUtils.cp_r(File.join(old_proj_path, "AppUI"), new_proj_path) 
    end

    if File.exist?(File.join(old_proj_path, "PResources")) 
        FileUtils.cp_r(File.join(old_proj_path, "PResources"), new_proj_path) 
    end

    if File.exist?(File.join(old_proj_path, "Resources")) 
        FileUtils.cp_r(File.join(old_proj_path, "Resources"), new_proj_path) 
    end

    if File.exist?(File.join(old_proj_path, old_proj_name + "NotificationContent"))
        FileUtils.cp_r(File.join(old_proj_path, old_proj_name + "NotificationContent"), new_proj_path) 
        if new_proj_name != old_proj_name 
            FileUtils.mv(File.join(new_proj_path, old_proj_name + "NotificationContent"), File.join(new_proj_path, new_proj_name + "NotificationContent"))
        end
    end

    if File.exist?(File.join(old_proj_path, old_proj_name + "NotificationService"))
        FileUtils.cp_r(File.join(old_proj_path, old_proj_name + "NotificationService"), new_proj_path) 
        if new_proj_name != old_proj_name 
            FileUtils.mv(File.join(new_proj_path, old_proj_name + "NotificationService"), File.join(new_proj_path, new_proj_name + "NotificationService"))
        end
    end

    if File.exist?(File.join(old_proj_path, old_proj_name + "Keyboard"))
        FileUtils.cp_r(File.join(old_proj_path, old_proj_name + "Keyboard"), new_proj_path) 
        if new_proj_name != old_proj_name 
            FileUtils.mv(File.join(new_proj_path, old_proj_name + "Keyboard"), File.join(new_proj_path, new_proj_name + "Keyboard"))
            old_entitlements_plist = File.join(new_proj_path, new_proj_name + "Keyboard", old_proj_name + "Keyboard.entitlements")
            new_entitlements_plist = File.join(new_proj_path,  new_proj_name + "Keyboard", new_proj_name + "Keyboard.entitlements")
            if File.exist?(old_entitlements_plist) && old_entitlements_plist != new_entitlements_plist
                FileUtils.mv(old_entitlements_plist, new_entitlements_plist) 
                # entitlements_plist_dict = Xcodeproj::Plist.read_from_path(new_entitlements_plist)
                # entitlements_plist_dict['com.apple.security.application-groups'] = [@group_id]
                # Xcodeproj::Plist.write_to_path(entitlements_plist_dict, new_entitlements_plist)
            end
        end
    end

    if File.exist?(File.join(old_proj_path, old_proj_name + "iMessage"))
        FileUtils.cp_r(File.join(old_proj_path, old_proj_name + "iMessage"), new_proj_path) 
        if new_proj_name != old_proj_name 
            FileUtils.mv(File.join(new_proj_path, old_proj_name + "iMessage"), File.join(new_proj_path, new_proj_name + "iMessage"))
        end
        old_entitlements_plist = File.join(new_proj_path, new_proj_name + "iMessage", old_proj_name + "iMessage.entitlements")
        new_entitlements_plist = File.join(new_proj_path,  new_proj_name + "iMessage", new_proj_name + "iMessage.entitlements")
        if File.exist?(old_entitlements_plist) && old_entitlements_plist != new_entitlements_plist
            FileUtils.mv(old_entitlements_plist, new_entitlements_plist) 
        end
    end


    if File.exist?(File.join(old_proj_path, old_proj_name + "Extension"))
        FileUtils.cp_r(File.join(old_proj_path, old_proj_name + "Extension"), new_proj_path) 
        if new_proj_name != old_proj_name 
            FileUtils.mv(File.join(new_proj_path, old_proj_name + "Extension"), File.join(new_proj_path, new_proj_name + "Extension"))
        end
        old_entitlements_plist = File.join(new_proj_path, new_proj_name + "Extension", old_proj_name + "Extension.entitlements")
        new_entitlements_plist = File.join(new_proj_path,  new_proj_name + "Extension", new_proj_name + "Extension.entitlements")
        if File.exist?(old_entitlements_plist) && old_entitlements_plist != new_entitlements_plist
            FileUtils.mv(old_entitlements_plist, new_entitlements_plist) 
        end
    end


    if File.exist?(File.join(old_proj_path, "fastlane"))
        FileUtils.cp_r(File.join(old_proj_path, "fastlane"), new_proj_path) 
    end

    if File.exist?(File.join(old_proj_path, "Script"))
        FileUtils.cp_r(File.join(old_proj_path, "Script"), new_proj_path) 
    end

    if File.exist?(File.join(old_proj_path, "config.json"))
        FileUtils.cp_r(File.join(old_proj_path, "config.json"), new_proj_path) 
    end

    if File.exist?(File.join(old_proj_path, "VBDL.json"))
        FileUtils.cp_r(File.join(old_proj_path, "VBDL.json"), new_proj_path) 
    end

    old_entitlements_plist = File.join(old_proj_path, old_proj_name + ".entitlements")
    new_entitlements_plist = File.join(new_proj_path, new_proj_name + ".entitlements")
    if File.exist?(old_entitlements_plist) 
        FileUtils.cp_r(old_entitlements_plist, new_entitlements_plist) 
    end


    FileUtils.cp_r(File.join(old_proj_path, "Podfile"), new_proj_path) 
    text = File.read(File.join(new_proj_path, "Podfile"))
    new_contents = text.gsub(/target.*#{old_proj_name}/, "target \'#{new_proj_name}")
    File.open(File.join(new_proj_path, "Podfile"), "w") {|file| file.puts new_contents }
    
    if File.exist?(File.join(old_proj_path, "config.json"))
        FileUtils.cp_r(File.join(old_proj_path, "config.json"), new_proj_path)
    end


end

#create_project_target(new_proj_name: nil, new_proj_path: nil, new_proj_obj: nil, old_proj_name: nil, old_proj_path: nil, old_proj_obj: nil) ⇒ Object



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
# File 'lib/pindo/module/xcode/xcodehelper.rb', line 475

def create_project_target(new_proj_name:nil, new_proj_path:nil,  new_proj_obj:nil,  old_proj_name:nil, old_proj_path:nil, old_proj_obj:nil)
   
    ios_deployment_targe = "11.0"
    if @config_json && @config_json['project_info'] &&  @config_json['project_info']['ios_deployment_targe']
        ios_deployment_targe = @config_json['project_info']['ios_deployment_targe']
    end

    new_proj_target = new_proj_obj.new_target(:application, new_proj_name, :ios, ios_deployment_targe, nil, :objc)
    old_proj_target = old_proj_obj.targets.first 

    notification_content_target_name = new_proj_name + "NotificationContent"
    notification_content_target = nil
    notification_service_target_name = new_proj_name + "NotificationService"
    notification_service_target = nil
    keyboard_target_name = new_proj_name + "Keyboard"
    keyboard_target = nil
    imessage_target_name = new_proj_name + "iMessage"
    imessage_target = nil
    extension_target_name = new_proj_name + "Extension"
    extension_target = nil

    old_proj_obj.targets.each do |target|
        target.build_configurations.each do |config|
            if target.name.to_s.end_with?("Content") && notification_content_target.nil? then
                notification_content_target = new_proj_obj.new_target(:app_extension, notification_content_target_name, :ios, ios_deployment_targe, nil, :objc)
                new_proj_target.add_dependency(notification_content_target)
            elsif target.name.to_s.end_with?("Service") && notification_service_target.nil? then
                notification_service_target = new_proj_obj.new_target(:app_extension, notification_service_target_name, :ios, ios_deployment_targe, nil, :objc)
                new_proj_target.add_dependency(notification_service_target)
            elsif target.name.to_s.downcase.end_with?("keyboard") && keyboard_target.nil? then
                keyboard_target = new_proj_obj.new_target(:app_extension, keyboard_target_name, :ios, ios_deployment_targe, nil, :objc)
                new_proj_target.add_dependency(keyboard_target)
            elsif target.name.to_s.downcase.end_with?("imessage") && imessage_target.nil? then
                imessage_target = new_proj_obj.new_target(:messages_extension, imessage_target_name, :ios, ios_deployment_targe, nil, :objc)
                new_proj_target.add_dependency(imessage_target)
            elsif target.name.to_s.downcase.end_with?("extension") && imessage_target.nil? then
                extension_target = new_proj_obj.new_target(:app_extension, extension_target_name, :ios, ios_deployment_targe, nil, :objc)
                new_proj_target.add_dependency(extension_target)
            end
        end
    end

end

#get_target_by_name(proj_obj: nil, name: nil) ⇒ Object



8
9
10
11
12
13
14
15
16
# File 'lib/pindo/module/xcode/xcodehelper.rb', line 8

def get_target_by_name(proj_obj:nil, name:nil)
    new_target = nil
    proj_obj.targets.each do |target|
        if target.name.to_s.eql?(name)
            new_target = target
        end
    end
    return new_target
end

#is_resource_group(file) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/pindo/module/xcode/xcodehelper.rb', line 18

def is_resource_group(file)
    extname= file[/\.[^\.]+$/]
    if extname == '.bundle' || extname == '.xcassets' then
        return true
    end
    return false
end

#setting_new_project(new_proj_name: nil, new_proj_path: nil, new_proj_obj: nil, old_proj_name: nil, old_proj_path: nil, old_proj_obj: nil) ⇒ Object



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
# File 'lib/pindo/module/xcode/xcodehelper.rb', line 327

def setting_new_project(new_proj_name:nil, new_proj_path:nil, new_proj_obj:nil,  old_proj_name:nil, old_proj_path:nil, old_proj_obj:nil)

    old_proj_target = old_proj_obj.targets.first 
    new_proj_target = new_proj_obj.targets.first 

    if File.exist?(File.join(new_proj_path, "AppEntry/PrefixHeader.pch"))
        new_proj_target.build_configuration_list.set_setting('GCC_PREFIX_HEADER', "$(SRCROOT)/AppEntry/PrefixHeader.pch")
    end
    
    launch_storyboard_path = File.join(new_proj_path, "AppEntry", 'LaunchScreen.storyboard') 
    if File.exist?(launch_storyboard_path) 
        new_proj_target.build_configuration_list.set_setting('ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME', "")
        info_plist_path = File.join(new_proj_path, "AppEntry", "Info.plist")
        info_plist_dict = Xcodeproj::Plist.read_from_path(info_plist_path)
        info_plist_dict["UILaunchStoryboardName"] = "LaunchScreen"
        info_plist_dict["CFBundleIdentifier"] = "$(PRODUCT_BUNDLE_IDENTIFIER)"
        Xcodeproj::Plist.write_to_path(info_plist_dict, info_plist_path)
    else
        launch_path = File.join(new_proj_path, "AppEntry", 'Assets.xcassets', 'LaunchImage.launchimage')
        new_proj_target.build_configuration_list.set_setting('ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME', "LaunchImage")
        if File.exist?(launch_path) 
            new_proj_target.build_configuration_list.set_setting('ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME', "LaunchImage")
        end
    end
                
    new_proj_obj.save
end