Skip to content

Commit d14da05

Browse files
author
BANYAN
committed
rename
1 parent 0376b53 commit d14da05

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

rename/Gemfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
gem 'highline'
4+
gem 'colorize'

rename/rename

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#! /usr/bin/ruby
2+
3+
require "highline/import"
4+
require "colorize"
5+
6+
7+
def do_you_need_this(full_name_of_directory, proj_name)
8+
if full_name_of_directory == proj_name
9+
puts "Your project name and resources name are the same."
10+
exit()
11+
end
12+
end
13+
14+
def sync(new_name, proj_name)
15+
search_and_replace = "sed 's/#{new_name}/#{proj_name}/g' #{proj_name}.xcodeproj/project.pbxproj > #{proj_name}.xcodeproj/project2.pbxproj
16+
"
17+
system(search_and_replace)
18+
19+
save_file_to_old = "mv #{proj_name}.xcodeproj/project.pbxproj #{proj_name}.xcodeproj/project.pbxproj.old"
20+
system(save_file_to_old)
21+
22+
make_new_project_pbxproj = "mv #{proj_name}.xcodeproj/project2.pbxproj #{proj_name}.xcodeproj/project.pbxproj"
23+
system(make_new_project_pbxproj)
24+
25+
rename_source_directory = "mv #{new_name} #{proj_name}"
26+
rename_test_directory = "mv #{new_name}Tests #{proj_name}Tests"
27+
rename_test_file = "mv #{proj_name}Tests/#{new_name}Tests.m #{proj_name}Tests/#{proj_name}Tests.m "
28+
29+
system(rename_source_directory)
30+
system(rename_test_directory)
31+
system(rename_test_file)
32+
33+
rename_main_directory = "mv ../#{new_name} ../#{proj_name}"
34+
system(rename_main_directory)
35+
36+
puts "Done. Project name synchronised."
37+
puts "You might want to change the project's scheme too. Go to Manage Scheme."
38+
end
39+
40+
#sound off if something is wrong
41+
def soundoff(xcodeproj_file_arr,tests_dir_array)
42+
if tests_dir_array.count > 1
43+
puts "ERROR: there's more than one tests directory"
44+
exit()
45+
elsif tests_dir_array.count == 0
46+
puts "ERROR: cannot find test directory"
47+
exit()
48+
end
49+
50+
if xcodeproj_file_arr.count > 1
51+
puts "ERROR: there's more than one .xcodeproj file."
52+
exit()
53+
elsif xcodeproj_file_arr.count == 0
54+
puts "ERROR: cannot find xcodeproj file"
55+
exit()
56+
end
57+
end
58+
59+
def start()
60+
xcodeproj_file_arr = Dir.glob('*.xcodeproj')
61+
tests_dir_array = Dir.glob('*Tests')
62+
63+
name_of_directory= ""
64+
proj_name = ""
65+
new_name = ""
66+
67+
soundoff(xcodeproj_file_arr,tests_dir_array)
68+
69+
#DETECT
70+
full_name_of_directory = tests_dir_array[0]
71+
name_of_directory = full_name_of_directory[0,full_name_of_directory.length-5]
72+
proj_name = xcodeproj_file_arr[0].split(".")[0]
73+
74+
#CHECK
75+
do_you_need_this(name_of_directory, proj_name)
76+
77+
78+
79+
puts "WARNING: Close your Xcode before proceeding.".red
80+
#ASK
81+
puts ""
82+
new_name = ask "Press enter to replace: " + "#{name_of_directory}".red + " with " +"#{proj_name}".blue + " (Type q to quit)"
83+
84+
if new_name.strip == "q"
85+
puts "Exit."
86+
exit()
87+
elsif new_name.strip == ""
88+
sync(name_of_directory, proj_name)
89+
else
90+
data = ask "Change " + "#{proj_name}".blue + " to " + "#{new_name}".blue + " ? (Enter to confirm, q to cancel)"
91+
if data == ""
92+
sync(new_name, proj_name)
93+
else
94+
puts "Cancel."
95+
exit()
96+
end
97+
98+
end
99+
end
100+
101+
102+
start()

0 commit comments

Comments
 (0)