-
Notifications
You must be signed in to change notification settings - Fork 5
/
rename.rb
41 lines (34 loc) · 1.25 KB
/
rename.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
app_name = ARGV[0]
unless app_name
puts "Usage: ruby rename.rb new_app_name"
exit
end
# In case someone uses CamelCaseAppName
app_name = app_name.gsub(/(.)([A-Z])/,'\1_\2')
app_name.downcase!
underscore_project_name = app_name.gsub(/\W/, '_').squeeze('_')
camel_project_name = underscore_project_name.split('_').map {|w| w.capitalize }.join
hyphen_project_name = underscore_project_name.gsub('_', '-')
title_project_name = underscore_project_name.split('_').map {|w| w.capitalize }.join(' ')
lower_project_name = camel_project_name.downcase
replacements = [
['base_jumper', underscore_project_name],
['BaseJumper', camel_project_name],
['base-jumper', hyphen_project_name],
['Base Jumper', title_project_name],
['basejumper', lower_project_name],
]
files = Dir.glob("**/*.*")
#these files need to be manually added because they will not be picked up by the glob
files << ".ruby-gemset"
files << "Rakefile"
files.each do |filename|
next if filename == "rename.rb" || File.directory?(filename)
puts filename
replacements.each do |orig_name, new_name|
puts " Replacing #{orig_name} with #{new_name}"
content = File.binread(filename)
content.gsub!(orig_name, new_name)
File.open(filename, 'wb') { |file| file.write(content) }
end
end