dtripper 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4228a47e5a5c39275b8f87a52f32d59b314dd3c7
4
+ data.tar.gz: 2dc653c8da026e0e641bf361f9b8ae53461c21f1
5
+ SHA512:
6
+ metadata.gz: 37a19b6659e7ea29c5f813255a30a152e8c826e8913d258d9051256def64bc2daeff1766e89dd825fb9491f9ae33b7f0214ab2715aae8bfb2c7cb6ef0ecab2f2
7
+ data.tar.gz: 67084e80a543b48a5b6886e794e336dbbb744e52ab8c64ab53b65045c06d4c41350bdc64719b6382e0d7a219c93cc9ba0cd6af179dc6a5dad3f504e354f95668
data/bin/dtripper ADDED
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'dtripper'
3
+
4
+ DTRipperProjectCreator::DTModuleGenerator.new(ARGV[0],ARGV[1],ARGV[2],ARGV[3]).create
@@ -0,0 +1,207 @@
1
+ #!/usr/bin/ruby
2
+ require 'pathname'
3
+ require 'open-uri'
4
+ require 'zip'
5
+ require 'xcodeproj'
6
+
7
+ module DTRipperProjectCreator
8
+ #main project part
9
+ TEMPLETE_MAIN_PROJECT_ZIP_FILE_NAME = "DTRipperMainTemplete-master.zip"
10
+ TEMPLETE_MAIN_PROJECT_DOWNLOAD_URL = "https://github.com/NicolasKim/DTRipperMainTemplete/archive/master.zip"
11
+ TEMPLETE_MAIN_PROJECT_ROOT_FOLDER = "DTRipperMainTemplete-master"
12
+ MAIN_PROJECT_REPLACEABLE_STRING_REX = /(\#{2}|_{2}|-{2})TempleteMainProject(\#{2}|_{2}|-{2})/
13
+
14
+ #module project part
15
+ TEMPLETE_MODULE_PROJECT_ZIP_FILE_NAME = "DTRipperModuleTemplete-master.zip"
16
+ TEMPLETE_MODULE_PROJECT_DOWNLOAD_URL = "https://github.com/NicolasKim/DTRipperModuleTemplete/archive/master.zip"
17
+ TEMPLETE_MODULE_PROJECT_ROOT_FOLDER = "DTRipperModuleTemplete-master"
18
+ REPLACEABLE_STRING_REX = /(\#{2}|_{2}|-{2})TempleteModule(\#{2}|_{2}|-{2})/
19
+
20
+ class ProjectReplacer
21
+ def initialize(proj_name,proj_dir,zip_file_name,down_load_url,proj_root_folder,replace_rex)
22
+ @proj_name = proj_name
23
+ @proj_dir = proj_dir
24
+ @zip_file_name = zip_file_name
25
+ @down_load_url = down_load_url
26
+ @proj_root_folder = proj_root_folder
27
+ @replace_rex = replace_rex
28
+ end
29
+ def replace
30
+ unzip_file_path = File.join(@proj_dir,@zip_file_name)
31
+ if File.exists?(unzip_file_path)
32
+ puts "templete project zip file is already exist"
33
+ else
34
+ puts "Downloading templete project...."
35
+ File.open(unzip_file_path, 'wb') {|f| f.write(open(@down_load_url) {|f1| f1.read})}
36
+ puts "Templete project download success!!"
37
+ end
38
+
39
+ puts "Start unzip templete project...."
40
+
41
+ unzip(unzip_file_path)
42
+
43
+ puts "Unzip templete project success!!"
44
+
45
+ File.delete(unzip_file_path)
46
+
47
+ puts "Delete templete project zip file success!!"
48
+
49
+
50
+ File.rename(File.join(@proj_dir,@proj_root_folder),File.join(@proj_dir,@proj_name))
51
+
52
+ replace_all_replacable_str File.join(@proj_dir,@proj_name)
53
+
54
+ puts "Replace finished!!"
55
+ end
56
+ def replace_all_replacable_str(path)
57
+ dir = Dir.new(path)
58
+ dir.each do |sub_dir|
59
+
60
+ if sub_dir == "." || sub_dir == ".."
61
+ next
62
+ end
63
+
64
+
65
+ if sub_dir.to_s.match(@replace_rex)
66
+ changed_path = File.join(path,sub_dir.to_s.gsub(@replace_rex,@proj_name))
67
+ File.rename(File.join(path,sub_dir.to_s),changed_path)
68
+ if File.ftype(changed_path) == "file"
69
+ file_content_replace changed_path
70
+ else
71
+ replace_all_replacable_str changed_path
72
+ end
73
+ else
74
+ orgin_path = File.join(path,sub_dir)
75
+ if File.ftype(orgin_path) == "file"
76
+ file_content_replace orgin_path
77
+ elsif
78
+ replace_all_replacable_str orgin_path
79
+ end
80
+
81
+ end
82
+
83
+
84
+
85
+
86
+ end
87
+ end
88
+ def file_content_replace(path)
89
+ File.open(path,"r:utf-8") do |fr|
90
+ buffer = fr.read.gsub(@replace_rex,@proj_name)
91
+ # puts buffer
92
+ File.open(path, "w:utf-8") { |fw| fw.write(buffer) }
93
+ end
94
+ end
95
+ def unzip(path)
96
+ full_path = File.expand_path(path)
97
+ entries = get_entries_name(path)
98
+ Zip::File.open(full_path) do |f|
99
+ entries.each do |entry|
100
+ f.extract(entry["entry"],entry["dest_path"]) {true}
101
+ #puts "unzip #{entry} succeed!"
102
+ end
103
+ end
104
+ rescue =>e
105
+ puts(e)
106
+ exit 3
107
+ end
108
+ def get_entries_name(path)
109
+ full_path = File.expand_path(path)
110
+ entries = []
111
+ Zip::InputStream::open(full_path) do |io|
112
+ while (entry = io.get_next_entry)
113
+ h = Hash["entry"=>entry.name , "dest_path"=>File.join(@proj_dir,entry.name)]
114
+ entries << h
115
+ end
116
+ end
117
+ entries
118
+ end
119
+ end
120
+
121
+ class DTMainProjectGenerator
122
+ def initialize(proj_name,proj_dir=File.dirname(__FILE__))
123
+ @proj_name = proj_name
124
+ @proj_dir = proj_dir
125
+ @replacer = ProjectReplacer.new(proj_name,proj_dir,
126
+ TEMPLETE_MAIN_PROJECT_ZIP_FILE_NAME,
127
+ TEMPLETE_MAIN_PROJECT_DOWNLOAD_URL,
128
+ TEMPLETE_MAIN_PROJECT_ROOT_FOLDER,
129
+ MAIN_PROJECT_REPLACEABLE_STRING_REX)
130
+ end
131
+
132
+ def create
133
+ @replacer.replace
134
+ end
135
+
136
+ def self.create_workspace(proj_dir,proj_name)
137
+ proj_path = File.join(proj_dir,proj_name,"#{proj_name}.xcodeproj")
138
+
139
+ proj_file_ref = Xcodeproj::Workspace::FileReference.new("#{proj_name}.xcodeproj")
140
+ workspace = nil
141
+ workspace_path = File.join(proj_dir,proj_name,"#{proj_name}.xcworkspace")
142
+ if File.exists? workspace_path
143
+ workspace = Xcodeproj::Workspace.new_from_xcworkspace(workspace_path)
144
+ else
145
+ workspace = Xcodeproj::Workspace.new(nil, proj_file_ref)
146
+ end
147
+ workspace
148
+ end
149
+
150
+
151
+
152
+ end
153
+
154
+ class DTModuleGenerator
155
+ def initialize(module_name,module_dir=File.dirname(__FILE__),main_proj_name="MainProject", main_proj_dir=File.dirname(__FILE__))
156
+ @module_dir = module_dir
157
+ @module_name = module_name
158
+ @main_proj_dir = main_proj_dir
159
+ @main_proj_name = main_proj_name
160
+
161
+ end
162
+
163
+ def config
164
+ workspace_file_dir = File.join(@main_proj_dir,@main_proj_name,"#{@main_proj_name}.xcworkspace")
165
+ main_proj_file_dir = File.join @main_proj_dir ,@main_proj_name , "#{@main_proj_name}.xcodeproj"
166
+ module_proj_file_dir = File.join(@module_dir,@module_name,"#{@module_name}.xcodeproj")
167
+ podfile_dir = File.join @main_proj_dir ,@main_proj_name , "Podfile"
168
+ File.open(podfile_dir,"r:utf-8") do |fr|
169
+ buffer = fr.read
170
+ if !buffer.include?("#{@module_name}")
171
+ endIndex = buffer.index("end")
172
+ puts endIndex
173
+ buffer.insert(endIndex," pod '#{@module_name}', :path => '#{File.join(@module_dir,@module_name)}' \n")
174
+ File.open(podfile_dir, "w:utf-8") { |fw|
175
+ fw.write(buffer)
176
+ }
177
+ end
178
+
179
+ end
180
+ workspace = DTMainProjectGenerator.create_workspace(@main_proj_dir,@main_proj_name)
181
+ workspace << module_proj_file_dir
182
+ workspace.save_as workspace_file_dir
183
+ exec "pod install --project-directory=#{File.join(@main_proj_dir,@main_proj_name)}"
184
+ end
185
+
186
+ def create
187
+ main_proj_file_dir = File.join @main_proj_dir ,@main_proj_name , "#{@main_proj_name}.xcodeproj"
188
+ if !File.exists? main_proj_file_dir
189
+ #create main project
190
+ DTMainProjectGenerator.new(@main_proj_name,@main_proj_dir).create
191
+ end
192
+
193
+ #create module project
194
+ ProjectReplacer.new(@module_name,@module_dir,
195
+ TEMPLETE_MODULE_PROJECT_ZIP_FILE_NAME,
196
+ TEMPLETE_MODULE_PROJECT_DOWNLOAD_URL,
197
+ TEMPLETE_MODULE_PROJECT_ROOT_FOLDER,
198
+ REPLACEABLE_STRING_REX).replace
199
+ config
200
+ end
201
+
202
+ end
203
+
204
+ end
205
+
206
+
207
+
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dtripper
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - DreamTracer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-22 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Command line tool for your xcode project based on DTRipper
14
+ email: jinqiucheng1006@live.cn
15
+ executables:
16
+ - dtripper
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - lib/DTRipperProjectCreator.rb
21
+ - bin/dtripper
22
+ homepage: http://rubygems.org/gems/dtripper
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '>='
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.0.14.1
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Ripper your xcode project!
46
+ test_files: []