-
Notifications
You must be signed in to change notification settings - Fork 3
/
rename
executable file
·109 lines (83 loc) · 4.29 KB
/
rename
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
#!/usr/bin/env ruby
require 'thor'
require 'active_support/all'
require 'fileutils'
class Rename < Thor
include Thor::Actions
def self.source_root
File.dirname(__FILE__)
end
desc 'project', 'replace references to HelloJavascript'
def project
begin
@original_project_name = "HelloJavascript"
@original_project_identifier = "org.cocos2dx.hellojavascript"
default_project_name = File.basename(destination_root).underscore.camelize
@project_name = ask("What is the new project name? (Camelcase, no spaces) [#{default_project_name}]")
@project_name = default_project_name if @project_name.blank?
default_project_identifier = "com.companyname.#{@project_name.downcase}"
@project_identifier = ask("What is the new project identifier? [#{default_project_identifier}]")
@project_identifier = default_project_identifier if @project_identifier.blank?
puts "Project Name: #{@project_name}"
puts "Project Identifier: #{@project_identifier}"
if yes?("Are these settings correct?")
fix_shared
fix_android
fix_ios
try_again = false
else
try_again = yes?("Try again?")
end
end while try_again
end
no_commands do
def fix_shared
orig_shared_dir = File.join "shared", @original_project_name
new_shared_dir = File.join "shared", @project_name
FileUtils.mv orig_shared_dir, new_shared_dir
orig_cocosbuilder_project = File.join new_shared_dir, "#{@original_project_name}.ccbproj"
new_cocosbuilder_project = File.join new_shared_dir, "#{@project_name}.ccbproj"
FileUtils.mv orig_cocosbuilder_project, new_cocosbuilder_project
end
def fix_android
original_project_directories = @original_project_identifier.split('.')
orig_android_source_dir = File.join ["proj.android", "src"] + original_project_directories
orig_android_jni_dir = File.join ["proj.android", "jni", original_project_directories.last]
new_directories = @project_identifier.split('.')
new_android_source_dir = File.join ["proj.android", "src"] + new_directories
new_android_jni_dir = File.join ["proj.android", "jni", new_directories.last]
directory orig_android_source_dir, new_android_source_dir
directory orig_android_jni_dir, new_android_jni_dir
orig_android_activity = File.join new_android_source_dir, "#{@original_project_name}.java"
new_android_activity = File.join new_android_source_dir, "#{@project_name}.java"
FileUtils.mv orig_android_activity, new_android_activity
remove_file orig_android_source_dir
remove_file orig_android_jni_dir
# proj.android/.project:3: <name>HelloJavascript</name>
# proj.android/AndroidManifest.xml:13: <activity android:name=".HelloJavascript"
# proj.android/build.xml:2:<project name="HelloJavascript" default="help">
# proj.android/build_native.sh:1:APPNAME="HelloJavascript"
# proj.android/res/values/strings.xml:3: <string name="app_name">HelloJavascript</string>
# proj.android/src/org/cocos2dx/hellojavascript/HelloJavascript.java:30:public class HelloJavascript extends Cocos2dxActivity{
[ File.join("proj.android", ".project"), File.join("proj.android", "AndroidManifest.xml"),
File.join("proj.android", "build.xml"), File.join("proj.android", "build_native.sh"),
File.join("proj.android", "res", "values", "strings.xml"), new_android_activity].each do |path|
gsub_file(path, @original_project_name, @project_name)
end
["proj.android/AndroidManifest.xml", new_android_activity].each do |path|
gsub_file path, @original_project_identifier, @project_identifier
end
gsub_file File.join("proj.android", "jni", "Android.mk"), original_project_directories.last, new_directories.last
end
def fix_ios
orig_xcode_proj = File.join "proj.ios", "#{@original_project_name}.xcodeproj"
new_xcode_proj = File.join "proj.ios", "#{@project_name}.xcodeproj"
FileUtils.mv orig_xcode_proj, new_xcode_proj
gsub_file File.join(new_xcode_proj, "project.pbxproj"), @original_project_name, @project_name
gsub_file File.join("proj.ios", "Prefix.pch"), @original_project_name, @project_name
gsub_file File.join("proj.ios", "Info.plist"), @original_project_identifier, @project_identifier
gsub_file File.join(new_xcode_proj, "project.xcworkspace", "contents.xcworkspacedata"), @original_project_name, @project_name
end
end
end
Rename.start(ARGV)