3333
3434##### Rename #####
3535
36+ def ensure_project_was_renamed
37+ if File.exist?('../Template.xcodeproj')
38+ UI.error("Rename the project first: bundle exec fastlane rename new_name:YourAppName")
39+ raise "BLOCKED: Project still named 'Template'"
40+ end
41+ end
42+
3643def rename_project(oldName, newName)
44+ UI.header('Step: rename_project')
45+
46+ # Remove spaces from new name to avoid issues with file paths and bundle identifiers
47+ newName = newName.gsub(/\s+/, '')
48+ UI.message("Renaming project from '#{oldName}' to '#{newName}'")
49+
3750 # Rename folders and files
51+ # .github/workflows
52+ # sh("sed -i '' 's|#{oldName}|#{newName}|g' ../.github/workflows/build.yml")
53+ # sh("sed -i '' 's|#{oldName}|#{newName}|g' ../.github/workflows/releasing.yml")
54+
55+ # Fastlane
56+ sh("sed -i '' 's|#{oldName}|#{newName}|g' ../fastlane/.env")
57+ sh("sed -i '' 's|#{oldName.downcase}|#{newName.downcase}|g' ../fastlane/.env")
58+ sh("sed -i '' 's|#{oldName}|#{newName}|g' ../fastlane/.env.prd")
59+ sh("sed -i '' 's|#{oldName}|#{newName}|g' ../fastlane/.env.stg")
60+ sh("sed -i '' 's|#{oldName}/Assets|#{newName}/Assets|g' ../fastlane/Definitionsfile")
61+ # sh("sed -i '' 's|#{oldName.downcase}|#{newName.downcase}|g' ../fastlane/Deliverfile")
62+ sh("sed -i '' 's|#{oldName}|#{newName}|g' ../fastlane/Fastfile")
63+ # sh("sed -i '' 's|#{oldName.downcase}|#{newName.downcase}|g' ../fastlane/Matchfile")
64+ sh("sed -i '' 's|#{oldName}|#{newName}|g' ../fastlane/Setupfile")
65+
3866 # Project file
3967 sh("mv ../#{oldName}.xcodeproj/xcshareddata/xcschemes/#{oldName}.xcscheme ../#{oldName}.xcodeproj/xcshareddata/xcschemes/#{newName}.xcscheme")
4068 sh("mv ../#{oldName}.xcodeproj ../#{newName}.xcodeproj")
@@ -56,18 +84,32 @@ def rename_project(oldName, newName)
5684 sh("mv ../#{newName}UITests/#{oldName}UITestsLaunchTests.swift ../#{newName}UITests/#{newName}UITestsLaunchTests.swift")
5785 sh("rm -rf ../#{oldName}UITests")
5886
59- # Search and Replace occurences of <oldName>
60- sh("sed -i '' 's/#{oldName}.xcodeproj/#{newName}.xcodeproj/g' ../README.md")
61- sh("sed -i '' 's/#{oldName}/#{newName}/g' ../fastlane/Fastfile")
62- sh("sed -i '' 's/#{oldName}/#{newName}/g' ../fastlane/.env.stg")
63- sh("sed -i '' 's/#{oldName}/#{newName}/g' ../fastlane/.env.prd")
64- sh("sed -i '' 's/#{oldName}.xcodeproj/#{newName}.xcodeproj/g' ../hooks/pre-commit")
65- sh("sed -i '' 's/#{oldName}/#{newName}/g' ../scripts/generate-swiftlint-filelist.sh")
66- sh("sed -i '' 's/#{oldName}/#{newName}/g' ../#{newName}.xcodeproj/project.pbxproj")
67- sh("sed -i '' 's/#{oldName}/#{newName}/g' ../#{newName}.xcodeproj/xcshareddata/xcschemes/#{newName}.xcscheme")
87+ # Search and Replace occurrences of <oldName>
88+ sh("sed -i '' 's|#{oldName}.xcodeproj|#{newName}.xcodeproj|g' ../README.md")
89+ sh("sed -i '' 's|#{oldName}.xcodeproj|#{newName}.xcodeproj|g' ../hooks/pre-commit")
90+ sh("sed -i '' 's|#{oldName}|#{newName}|g' ../#{newName}/Info.plist")
91+ sh("sed -i '' 's|#{oldName}|#{newName}|g' ../scripts/generate-swiftlint-filelist.sh")
92+ sh("sed -i '' 's|#{oldName}|#{newName}|g' ../#{newName}.xcodeproj/project.pbxproj")
93+ sh("sed -i '' 's|#{oldName}|#{newName}|g' ../#{newName}.xcodeproj/xcshareddata/xcschemes/#{newName}.xcscheme")
6894
69- sh("find ../#{newName}* -name '*.swift' -print0 | xargs -0 sed -i '' 's/ #{oldName}/ #{newName}/ g'")
95+ sh("find ../#{newName}* -name '*.swift' -print0 | xargs -0 sed -i '' 's| #{oldName}| #{newName}| g'")
7096
7197 # Remove build phases results to prevent compile issues with SwiftLint file lists
7298 sh("rm -rf ../.build/build_phases")
73- end
99+ end
100+
101+ def update_marketing_version(new_name)
102+ UI.header('Step: update_marketing_version')
103+
104+ # Set the default version number to <year>.<week>.0 using ISO week number whenever the project is renamed.
105+ current_date = Time.new
106+ year = current_date.strftime("%G")
107+ week = current_date.strftime("%-V")
108+ patch = 0
109+ version_number = "#{year}.#{week}.#{patch}"
110+
111+ # Replace MARKETING_VERSION = 1.0; with the computed version in the project file
112+ project_file = File.expand_path("../#{new_name}.xcodeproj/project.pbxproj")
113+ UI.message("Setting MARKETING_VERSION to `#{version_number}` in `#{project_file}`")
114+ sh("sed -i '' -E 's/(MARKETING_VERSION = )1\\.0;/\\1#{version_number};/g' \"#{project_file}\"")
115+ end
0 commit comments