-
Notifications
You must be signed in to change notification settings - Fork 2
/
create_swift_app.sh
executable file
·600 lines (470 loc) · 19.9 KB
/
create_swift_app.sh
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
#!/bin/bash
# Ensure execution permissions for the script
chmod +x "$0"
# Store the list of installed gems before installation
before_install=$(gem list --local | cut -d" " -f1)
# Check if the xcodeproj is installed, if not install it
if ! gem list -i xcodeproj > /dev/null 2>&1; then
echo "Installing xcodeproj..."
gem install xcodeproj --user-install
XCODEPROJ_INSTALLED=true
else
echo "xcodeproj gem is already installed."
fi
# Store the list of installed gems after installation
after_install=$(gem list --local | cut -d" " -f1)
# Find the newly installed gems
newly_installed=$(comm -13 <(echo "$before_install" | sort) <(echo "$after_install" | sort))
# Get new app name from user
echo -e "\033[31mEnter the new app name: \033[0m\c"
read NEW_APP_NAME
if [ -z "$NEW_APP_NAME" ]; then
echo "Error: New app name cannot be empty."
exit 1
fi
OLD_APP_NAME="SwiftAppTemplate"
DESTINATION_PATH="$HOME/Desktop/$NEW_APP_NAME"
# Create the destination directory if it doesn't exist
mkdir -p "$DESTINATION_PATH"
git clone https://github.com/shurutech/iOSKickstart.git "$DESTINATION_PATH"
# Navigate to the cloned directory
cd "$DESTINATION_PATH" || exit
# Rename the .xcodeproj directory
mv "$OLD_APP_NAME.xcodeproj" "$NEW_APP_NAME.xcodeproj"
# Rename the main project folder containing Swift files and views
mv "$OLD_APP_NAME" "$NEW_APP_NAME"
# Check if .git directory exists and remove it
if [ -d ".git" ]; then
rm -rf .git
echo "Unlinked project from Git repository."
else
echo "Project is not linked to a Git repository."
fi
function delete_lines() {
if [ "$#" -lt 2 ]; then
echo "Usage: delete_lines <file_path> <line_numbers>"
return 1
fi
file_path="$1"
shift
line_numbers=("$@")
if [ ! -f "$file_path" ]; then
echo "Error: File not found - $file_path"
return 1
fi
sed_args=""
for arg in "${line_numbers[@]}"; do
if [[ "$arg" == *-* ]]; then
# Handle ranges
start=$(echo "$arg" | cut -d'-' -f1)
end=$(echo "$arg" | cut -d'-' -f2)
sed_args="${sed_args}${start},${end}d; "
else
# Individual line numbers
sed_args="${sed_args}${arg}d; "
fi
done
sed_args="${sed_args%??}" # Remove the trailing "; "
sed -i.bak "$sed_args" "$file_path"
echo "Lines ${line_numbers[*]} deleted from $file_path"
}
# Define the paths to your configuration files
DEBUG_CONFIG_FILE="$DESTINATION_PATH/$NEW_APP_NAME/Configuration/Debug.xcconfig"
RELEASE_CONFIG_FILE="$DESTINATION_PATH/$NEW_APP_NAME/Configuration/Release.xcconfig"
# Define the new values for APP_NAME and APP_BUNDLE_ID
NEW_APP_BUNDLE_ID="com.example.$NEW_APP_NAME"
OLD_BUNDLE_ID="com.shurutech.$OLD_APP_NAME"
# Update APP_NAME and APP_BUNDLE_ID in the Debug Configuration
sed -i '' "s/$OLD_BUNDLE_ID"Debug"/$NEW_APP_BUNDLE_ID"Debug"/g" "$DEBUG_CONFIG_FILE"
sed -i '' "s/$OLD_APP_NAME Debug/$NEW_APP_NAME Debug/g" "$DEBUG_CONFIG_FILE"
# Update APP_NAME and APP_BUNDLE_ID in the Release Configuration
sed -i '' "s/$OLD_BUNDLE_ID/$NEW_APP_BUNDLE_ID/g" "$RELEASE_CONFIG_FILE"
sed -i '' "s/$OLD_APP_NAME/$NEW_APP_NAME/g" "$RELEASE_CONFIG_FILE"
# Ask the user to include the side menu or not
echo -e "\033[31mDo you require a side menu? (Yn): \033[0m\c"
read REQUIRE_SIDE_MENU
REMOVE_SIDE_MENU=false
if [ "$REQUIRE_SIDE_MENU" = "n" ] || [ "$REQUIRE_SIDE_MENU" = "N" ]; then
REMOVE_SIDE_MENU=true
pathOfSideMenuFolder="$DESTINATION_PATH/$NEW_APP_NAME/Screens/SideMenu"
echo "Removing folder: $pathOfSideMenuFolder"
rm -rf "$pathOfSideMenuFolder"
pathToMainCoordinator="$DESTINATION_PATH/$NEW_APP_NAME/Screens/MainTabView/MainTabCoordinator.swift"
# Check and update permissions
if [ ! -r "$pathToMainCoordinator" ]; then
chmod +r "$pathToMainCoordinator"
fi
#Removing from MainTabCoordinator
delete_lines "$pathToMainCoordinator" 12 19 24-28 44-60
elif [ "$REQUIRE_SIDE_MENU" = "y" ] || [ "$REQUIRE_SIDE_MENU" = "Y" ]; then
echo "Side menu will be added."
else
echo "Incorrect input given."
fi
# Ask user to enter number of tabs required in app
echo -e "\033[31mEnter the number of tabs between 2 to 5: \033[0m\c"
read NUM_TABS
if [ "$NUM_TABS" -ge 2 ] && [ "$NUM_TABS" -le 5 ]; then
echo "Continuing with $NUM_TABS tabs."
else
echo "Invalid number of tabs. Please enter a number between 2 and 5."
exit 1
fi
declare -a TAB_TITLES
declare -a TAB_ICONS
for ((i=1; i<=NUM_TABS; i++)); do
TAB_TITLES[$i]="Tab$i"
TAB_ICONS[$i]="$i.circle.fill"
done
TAB_ENUM_CODE="enum Tab: CaseIterable{"
TAB_VIEW_CODE="TabView(selection: \$viewModel.selectedTab, content: {"
for ((i=1; i<=NUM_TABS; i++)); do
title=${TAB_TITLES[$i]}
icon=${TAB_ICONS[$i]}
viewName="${title}Screen()"
TAB_ENUM_CODE+="
case $(echo $title | awk '{print tolower($0)}')"
TAB_VIEW_CODE+="
$viewName.tabItem { TabItem(title: \"$title\", icon: \"$icon\") }.tag(Tab.$(echo $title | awk '{print tolower($0)}'))"
done
TAB_VIEW_CODE+="
})"
TAB_ENUM_CODE+="
}"
SWIFT_FILE_PATH="$DESTINATION_PATH/$NEW_APP_NAME/Screens/MainTabView/MainTabCoordinator.swift"
SWIFT_VIEW_MODEL_FILE_PATH="$DESTINATION_PATH/$NEW_APP_NAME/Screens/MainTabView/ViewModels/MainTabViewModel.swift"
# Write the new tab view code to a temporary file
echo "$TAB_VIEW_CODE" > tab_view_temp.txt
echo "$TAB_ENUM_CODE" > tab_enum_temp.txt
# Find the start line of the old TabView code
START_LINE=$(grep -n "TabView(selection: \$viewModel.selectedTab," "$SWIFT_FILE_PATH" | head -1 | cut -d: -f1)
START_LINE_ENUM=$(grep -n "enum Tab: CaseIterable{" "$SWIFT_VIEW_MODEL_FILE_PATH" | head -1 | cut -d: -f1)
# Find the end line of the old TabView code, looking for the line with '})'
END_LINE=$(awk -v start="$START_LINE" 'NR > start && /}\)/ {print NR; exit}' "$SWIFT_FILE_PATH")
END_LINE_ENUM=$(awk -v start="$START_LINE_ENUM" 'NR > start && /}/ {print NR; exit}' "$SWIFT_VIEW_MODEL_FILE_PATH")
# Delete the old TabView section
sed -i '' "${START_LINE},${END_LINE}d" "$SWIFT_FILE_PATH"
sed -i '' "${START_LINE_ENUM},${END_LINE_ENUM}d" "$SWIFT_VIEW_MODEL_FILE_PATH"
# Insert the new TabView code before the original start line
awk -v line="$START_LINE" -v file="tab_view_temp.txt" 'NR==line{system("cat " file)} {print}' "$SWIFT_FILE_PATH" > temp.swift && mv temp.swift "$SWIFT_FILE_PATH"
awk -v line="$START_LINE_ENUM" -v file="tab_enum_temp.txt" 'NR==line{system("cat " file)} {print}' "$SWIFT_VIEW_MODEL_FILE_PATH" > temp.swift && mv temp.swift "$SWIFT_VIEW_MODEL_FILE_PATH"
# Remove the temporary file
rm tab_view_temp.txt
rm tab_enum_temp.txt
for ((i=5; i>NUM_TABS; i--)); do
rm -f "$DESTINATION_PATH/$NEW_APP_NAME/Screens/MainTabView/TabViews/Tab${i}Screen.swift"
done
# Ask the user to include the tnc screen or not
echo -e "\033[31mDo you require a terms and condition screen? (Yn): \033[0m\c"
read REQUIRE_TNC_SCREEN
REMOVE_TNC_SCREEN=false
if [ "$REQUIRE_TNC_SCREEN" = "n" ] || [ "$REQUIRE_TNC_SCREEN" = "N" ]; then
REMOVE_TNC_SCREEN=true
pathOfTncFolder="$DESTINATION_PATH/$NEW_APP_NAME/Screens/TermsAndConditions"
echo "Removing folder: $pathOfTncFolder"
rm -rf "$pathOfTncFolder"
pathToRootCoordinator="$DESTINATION_PATH/$NEW_APP_NAME/Screens/Root/RootCoordinator.swift"
pathToRootViewModel="$DESTINATION_PATH/$NEW_APP_NAME/Screens/Root/RootViewModel.swift"
pathToOnBoardingScreen="$DESTINATION_PATH/$NEW_APP_NAME/Screens/Onboarding/OnboardingScreen.swift"
# Check and update permissions
if [ ! -r "$pathToRootCoordinator" ] || [ ! -r "$pathToRootViewModel" ] || [ ! -r "$pathToOnBoardingScreen" ]; then
# echo "Adding read permissions to $pathToMainCoordinator"
chmod +r "$pathToRootCoordinator"
chmod +r "$pathToRootViewModel"
chmod +r "$pathToOnBoardingScreen"
fi
#Removing from root coordinator
delete_lines "$pathToRootCoordinator" 15 41-42 45 54 82-84
#Removing from RootViewModel
delete_lines "$pathToRootViewModel" 17 35 46-51
#Removing from OnBoardingScreen
delete_lines "$pathToOnBoardingScreen" 30-33
elif [ "$REQUIRE_TNC_SCREEN" = "y" ] || [ "$REQUIRE_TNC_SCREEN" = "Y" ]; then
echo "Terms and conditions screen will be added."
else
echo "Incorrect input given."
fi
# Ask the user to include the onboarding screen or not
echo -e "\033[31mDo you require an onboarding screen? (Yn): \033[0m\c"
read REQUIRE_ONBOARDING_SCREEN
REMOVE_ONBOARDING_SCREEN=false
if [ "$REQUIRE_ONBOARDING_SCREEN" = "n" ] || [ "$REQUIRE_ONBOARDING_SCREEN" = "N" ]; then
REMOVE_ONBOARDING_SCREEN=true
pathOfOnboardingFolder="$DESTINATION_PATH/$NEW_APP_NAME/Screens/Onboarding"
echo "Removing folder: $pathOfOnboardingFolder"
rm -rf "$pathOfOnboardingFolder"
pathToRootCoordinator="$DESTINATION_PATH/$NEW_APP_NAME/Screens/Root/RootCoordinator.swift"
pathToRootViewModel="$DESTINATION_PATH/$NEW_APP_NAME/Screens/Root/RootViewModel.swift"
# Check and update permissions
if [ ! -r "$pathToRootCoordinator" ] || [ ! -r "$pathToRootViewModel" ]; then
# echo "Adding read permissions to $pathToMainCoordinator"
chmod +r "$pathToRootCoordinator"
chmod +r "$pathToRootViewModel"
fi
#Removing from rootCoordinator
if $REMOVE_TNC_SCREEN; then
delete_lines "$pathToRootCoordinator" 15 40-42 50 77-79
else
delete_lines "$pathToRootCoordinator" 16 43-46 55 85-87
fi
#Removing from RootViewModel
if $REMOVE_TNC_SCREEN; then
delete_lines "$pathToRootViewModel" 17 34 45-50
else
delete_lines "$pathToRootViewModel" 18 36 53-58
fi
elif [ "$REQUIRE_ONBOARDING_SCREEN" = "y" ] || [ "$REQUIRE_ONBOARDING_SCREEN" = "Y" ]; then
echo "Onboarding screen will be added."
else
echo "Incorrect input given."
fi
# Ask about localization support
echo -e "\033[32mApp has additional language support - French, Hindi, Spanish, Chinese, Arabic. \033[0m"
echo -e "\033[31mDo you want to disable additional language support? (Y/n): \033[0m\c"
read disable_localization
if [ "$disable_localization" = "Y" ] || [ "$disable_localization" = "y" ]; then
LOCALIZATION_DISABLED=true
else
LOCALIZATION_DISABLED=false
fi
# Function to disable localization
function disable_localization() {
local app_path="$1"
echo "Disabling additional language support..."
find "$app_path" -name "*.lproj" ! -name "en.lproj" -exec rm -rf {} \;
echo "Additional language support has been disabled."
pathToUserDetailsScreen="$DESTINATION_PATH/$NEW_APP_NAME/Screens/UserDetails/UserDetailsScreen.swift"
pathToEditUserDetailsScreen="$DESTINATION_PATH/$NEW_APP_NAME/Dummy-Use&Delete/EditUserDetailsScreen.swift"
pathToSettingsScreen="$DESTINATION_PATH/$NEW_APP_NAME/Dummy-Use&Delete/SettingsScreen.swift"
# Check and update permissions
if [ ! -r "$pathToUserDetailsScreen" ] || [ ! -r "$pathToEditUserDetailsScreen" ] || [ ! -r "$pathToSettingsScreen" ]; then
chmod +r "$pathToUserDetailsScreen"
chmod +r "$pathToEditUserDetailsScreen"
chmod +r "$pathToSettingsScreen"
fi
delete_lines "$pathToUserDetailsScreen" 42-46
delete_lines "$pathToEditUserDetailsScreen" 50-53
delete_lines "$pathToSettingsScreen" 61
}
if $LOCALIZATION_DISABLED; then
disable_localization "$DESTINATION_PATH"
fi
# Ask the user to include the Appearance dark/light feature in from settings
echo -e "\033[31mDo you want to enable the dark/light appearance feature in the settings screen? (Yn): \033[0m\c"
read REQUIRE_APPEARANCE_SCREEN
REMOVE_APPEARANCE_SCREEN=false
if [ "$REQUIRE_APPEARANCE_SCREEN" = "n" ] || [ "$REQUIRE_APPEARANCE_SCREEN" = "N" ]; then
REMOVE_APPEARANCE_SCREEN=true
pathToSettings="$DESTINATION_PATH/$NEW_APP_NAME/Dummy-Use&Delete/SettingsScreen.swift"
pathToLaunchApp="$DESTINATION_PATH/$NEW_APP_NAME/LaunchApp.swift"
pathToUserPreferences="$DESTINATION_PATH/$NEW_APP_NAME/Utils/UserPreferences.swift"
if [ ! -r "$pathToSettings" ] || [ ! -r "$pathToLaunchApp" ]; then
chmod +r "$pathToSettings"
chmod +r "$pathToLaunchApp"
fi
delete_lines "$pathToSettings" 16 31-32 121-139
delete_lines "$pathToLaunchApp" 17-19
delete_lines "$pathToUserPreferences" 24 87-94
elif [ "$REQUIRE_APPEARANCE_SCREEN" = "y" ] || [ "$REQUIRE_APPEARANCE_SCREEN" = "Y" ]; then
echo "Appearance screen will be added."
else
echo "Incorrect input given."
fi
# Execute Ruby script
ruby << RUBY_SCRIPT
require 'xcodeproj'
old_project_name = "$OLD_APP_NAME"
new_project_name = "$NEW_APP_NAME"
remove_side_menu = $REMOVE_SIDE_MENU
remove_tnc_screen = $REMOVE_TNC_SCREEN
remove_onboarding_screen = $REMOVE_ONBOARDING_SCREEN
remove_appearance_feature = $REMOVE_APPEARANCE_SCREEN
localization_disabled = $LOCALIZATION_DISABLED
num_tab = $NUM_TABS
project_path = "#{Dir.pwd}/#{new_project_name}.xcodeproj"
project = Xcodeproj::Project.open(project_path)
def rename_group(group, old_name, new_name)
group.children.each do |child|
if child.is_a?(Xcodeproj::Project::Object::PBXGroup) && child.path == old_name
puts "Renaming group from '#{old_name}' to '#{new_name}'"
child.path = new_name
break
end
end
end
def remove_folder(group, folder_name)
group.children.dup.each do |child|
if child.is_a?(Xcodeproj::Project::Object::PBXGroup)
if child.path == folder_name
child.remove_from_project
return true
else
removed = remove_folder(child, folder_name)
return true if removed
end
end
end
false
end
def remove_group(group, target, file_names = nil, group_name = nil, file_in_group = nil)
group.children.dup.each do |child|
if child.is_a?(Xcodeproj::Project::Object::PBXGroup)
if group_name && child.name == group_name
child.children.each do |inner_child|
if inner_child.is_a?(Xcodeproj::Project::Object::PBXFileReference) && (file_in_group.nil? || inner_child.path == file_in_group)
target.source_build_phase.remove_file_reference(inner_child)
inner_child.remove_from_project
end
end
group.remove_child(child) unless file_in_group
else
remove_group(child, target, file_names, group_name, file_in_group)
end
elsif child.is_a?(Xcodeproj::Project::Object::PBXFileReference) && file_names&.include?(File.basename(child.real_path.to_s))
target.source_build_phase.remove_file_reference(child)
child.remove_from_project
end
end
end
# Update target and product names
project.targets.each do |target|
puts "Old target name: #{target.name}"
target.name = new_project_name
puts "New target name: #{target.name}"
target.build_configurations.each do |config|
puts "Old product name: #{config.build_settings['PRODUCT_NAME']}"
config.build_settings['PRODUCT_NAME'] = new_project_name
puts "New product name: #{config.build_settings['PRODUCT_NAME']}"
# Update productName to new project name
if config.build_settings.key?('PRODUCT_NAME')
config.build_settings['PRODUCT_NAME'] = new_project_name
end
end
target.source_build_phase.files_references.each do |file_ref|
if file_ref.path == 'SideMenuView.swift' && remove_side_menu == true
target.source_build_phase.remove_file_reference(file_ref)
end
if file_ref.path == 'TermsAndConditionsScreen.swift' && remove_tnc_screen == true
target.source_build_phase.remove_file_reference(file_ref)
end
if file_ref.path == 'OnboardingScreen.swift' && remove_onboarding_screen == true
target.source_build_phase.remove_file_reference(file_ref)
end
if file_ref.path == 'AppearancePreference.swift' && remove_appearance_feature == true
target.source_build_phase.remove_file_reference(file_ref)
end
(5).downto(num_tab+1).each do |i|
if file_ref.path == "Tab#{i}Screen.swift"
target.source_build_phase.remove_file_reference(file_ref)
end
end
end
end
## TabScreen names that should be removed
file_names_to_remove = (num_tab+1..5).map { |i| "Tab#{i}Screen.swift" }
project.targets.each do |target|
project.main_group.children.each do |child|
if child.is_a?(Xcodeproj::Project::Object::PBXGroup)
remove_group(child, target, file_names_to_remove)
if remove_side_menu == true
remove_group(child, target, "SideMenuView.swift")
end
if remove_tnc_screen == true
remove_group(child, target, "TermsAndConditionsScreen.swift")
end
if remove_onboarding_screen == true
remove_group(child, target, "OnboardingScreen.swift")
end
if remove_appearance_feature == true
remove_group(child, target, "AppearancePreference.swift")
end
end
end
end
if remove_side_menu == true
remove_folder(project.main_group, "SideMenu")
end
if remove_tnc_screen == true
remove_folder(project.main_group, "TermsAndConditions")
end
if remove_onboarding_screen == true
remove_folder(project.main_group, "Onboarding")
end
if localization_disabled == true
locales_to_remove = ["ar", "zh-Hans", "es", "fr", "hi"]
locales_to_remove.each do |locale|
project.root_object.known_regions.reject! { |region| region == locale }
project.files.each do |file|
if file.path.match(/#{locale}.lproj/)
file.remove_from_project
end
end
end
end
# Rename a specific group (change 'SpecificGroupName' to the name of the group you want to rename)
rename_group(project.main_group, old_project_name, new_project_name)
# Update the file references inside the project
project.files.each do |file|
file.path = file.path.gsub(old_project_name, new_project_name) if file.path.include?(old_project_name)
end
# Fetch the new target
new_target = project.targets.find { |t| t.name == new_project_name }
unless new_target
puts "New target '#{new_project_name}' not found."
exit 1
end
# Update scheme names and their Buildable References
schemes_path = "#{project_path}/xcshareddata/xcschemes"
Dir.glob("#{schemes_path}/*.xcscheme").each do |scheme_path|
scheme = Xcodeproj::XCScheme.new(scheme_path)
# Update Buildable References for actions that have buildable_product_runnable
[scheme.launch_action, scheme.profile_action].each do |action|
if action && action.respond_to?(:buildable_product_runnable) && action.buildable_product_runnable
action.buildable_product_runnable.buildable_reference.set_reference_target(new_target, true, project)
end
end
# Handle TestAction separately if needed
if scheme.test_action
# Update TestAction buildable references here if necessary
end
# Save the updated scheme
scheme.save!
end
# Update scheme names
Dir.glob("#{schemes_path}/*.xcscheme").each do |scheme_path|
scheme_name = File.basename(scheme_path, ".xcscheme")
new_scheme_name = scheme_name.gsub(old_project_name, new_project_name)
File.rename(scheme_path, "#{schemes_path}/#{new_scheme_name}.xcscheme")
end
# Update productName in PBXNativeTarget section
project.native_targets.each do |native_target|
puts "native target -- '#{native_target}'"
if native_target.name == new_project_name
puts "Updating productName for target '#{new_project_name}'"
native_target.build_configuration_list.build_configurations.each do |config|
config.build_settings['PRODUCT_NAME'] = new_project_name
end
end
end
# Inspect the "new_project_name" target
target = project.targets.find { |t| t.name == new_project_name }
target.product_name = new_project_name
# Save the project before renaming the directory
project.save
puts "Project directory, scheme, and project updated."
RUBY_SCRIPT
# Remove xcodeproj, if installed
if [ "$XCODEPROJ_INSTALLED" = true ]; then
echo "Removing xcodeproj..."
gem uninstall xcodeproj -x
else
echo "xcodeproj gem was already installed, not removing."
fi
if [ -n "$newly_installed" ]; then
echo "Uninstalling newly installed gems..."
gem uninstall $newly_installed
echo "Uninstallation complete."
fi
# Remove the create_swift_app.sh script
rm -f "$DESTINATION_PATH/create_swift_app.sh"
echo -e "\033[32mProject $NEW_APP_NAME created successfully. \033[0m\n"