xaddgroup 0.6.2
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 +7 -0
- data/bin/xaddgroup +6 -0
- data/lib/xaddgroup.rb +187 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: dd1a0fb5082246b2c872a6de60b15deea301e7b9
|
4
|
+
data.tar.gz: f508a01ce5c2d1c5778c99605666004891bb6fc0
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: b265b998a3a96252d463502d13d7ceeb0bda1a43160d3ec80323d31c278e889ac211bbe751e380df3d2343419c6620d41367d043604dd9f3adc142f6da65b0ae
|
7
|
+
data.tar.gz: 6a9aa1ca5bbc6a71abcc4effcdb5d827dafd2662ebbd798e1d388518a97a7b23a066c73f03890263d8fd15972fc589d4ca7be7690cd4d8e78ed4a24a50ebed19
|
data/bin/xaddgroup
ADDED
data/lib/xaddgroup.rb
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
require "xcodeproj"
|
2
|
+
require 'fileutils'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
class XAddGroup
|
6
|
+
|
7
|
+
def self.createRealFinder (newgroup)
|
8
|
+
groupPath = newgroup.real_path
|
9
|
+
begin
|
10
|
+
FileUtils::mkdir_p groupPath unless File.exists?(groupPath)
|
11
|
+
puts [groupPath,'.......created'].join()
|
12
|
+
rescue Exception => e
|
13
|
+
raise "无法创建实体文件夹:" + e
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.addToGroupFile (newgroup,fileName)
|
18
|
+
new_file_refs = Array.new(2)
|
19
|
+
file_h_path = [File.join(newgroup.real_path,fileName),'h'].join('.').to_s
|
20
|
+
file_m_path = [File.join(newgroup.real_path,fileName),'m'].join('.').to_s
|
21
|
+
|
22
|
+
new_file_refs[0] = newgroup.new_reference(file_h_path)
|
23
|
+
new_file_refs[1] = newgroup.new_reference(file_m_path)
|
24
|
+
#创建源文件
|
25
|
+
begin
|
26
|
+
for file_ref in new_file_refs
|
27
|
+
File.new(file_ref.real_path,'w') unless File.exists?(file_ref.real_path)
|
28
|
+
end
|
29
|
+
rescue Exception => e
|
30
|
+
raise e
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def self.run(arg)
|
36
|
+
|
37
|
+
cmp = ''
|
38
|
+
arg_dir_new = ''
|
39
|
+
#检查参数。。
|
40
|
+
if arg.count == 0
|
41
|
+
puts "[!] Miss option paramter"
|
42
|
+
puts ""
|
43
|
+
puts "\t Did you mean: --help?"
|
44
|
+
exit
|
45
|
+
elsif arg.count == 1
|
46
|
+
if arg[0] == "--help"
|
47
|
+
puts "Usage:"
|
48
|
+
puts "\t $ xaddgroup COMMAND"
|
49
|
+
puts "\t Batch Add Group To Xcodeproj,And map Entity Directory ."
|
50
|
+
puts "Commands:"
|
51
|
+
puts "\t xaddgroup <group-path> - 在当前项目根目录 查找<group-path>,如果没对应目录则默认创建"
|
52
|
+
puts "\t xaddgroup -b <group-path> - 在<group-path>目录下 批量生成子目录:'Model','View','ViewModel','ViewController','Request'"
|
53
|
+
exit
|
54
|
+
elsif arg[0] != '-b' && arg[0].to_s.include?('-')
|
55
|
+
puts "[!] Unknown option: '#{arg[0]}'"
|
56
|
+
puts ""
|
57
|
+
puts "\t Did you mean: --help?"
|
58
|
+
exit
|
59
|
+
elsif arg[0] == '-b'
|
60
|
+
puts "[!] Miss Target dir_path"
|
61
|
+
puts ""
|
62
|
+
puts "\t Did you mean: --help?"
|
63
|
+
exit
|
64
|
+
elsif
|
65
|
+
arg_dir_new = arg[0]
|
66
|
+
end
|
67
|
+
|
68
|
+
elsif arg.count == 2
|
69
|
+
|
70
|
+
if arg[0].to_s != "--help" && arg[0].to_s != "-b"
|
71
|
+
puts "[!] Unknown option: '#{arg[0]}'"
|
72
|
+
puts ""
|
73
|
+
puts "\t Did you mean: --help?"
|
74
|
+
exit
|
75
|
+
end
|
76
|
+
|
77
|
+
cmp = arg[0]
|
78
|
+
arg_dir_new = arg[1]
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
#find xcodeproj
|
83
|
+
xprojs = Dir.glob('*.xcodeproj').select {|item| 'Pods.xcodeproj' != item }
|
84
|
+
exit unless xprojs.count == 1
|
85
|
+
xprojName = xprojs[0]
|
86
|
+
|
87
|
+
#自定义子目录
|
88
|
+
|
89
|
+
yml_content = <<-DESC
|
90
|
+
|
91
|
+
#
|
92
|
+
# 在指定目录下,添加如下子目录
|
93
|
+
#
|
94
|
+
|
95
|
+
---
|
96
|
+
- Model
|
97
|
+
- View
|
98
|
+
- ViewModel
|
99
|
+
- ViewController
|
100
|
+
- Request
|
101
|
+
|
102
|
+
DESC
|
103
|
+
|
104
|
+
yml_path = File.join(Dir.home,'.xaddgroup.yml')
|
105
|
+
|
106
|
+
if !File.exists?(yml_path)
|
107
|
+
yml_file = File.new(yml_path,'w+')
|
108
|
+
yml_file.syswrite(yml_content)
|
109
|
+
yml_file.close
|
110
|
+
end
|
111
|
+
|
112
|
+
custom_mvvm_dirs = YAML::load(File.open(yml_path))
|
113
|
+
if custom_mvvm_dirs.class.to_s != 'Array'
|
114
|
+
puts '[!] 配置文件格式错误'
|
115
|
+
puts yml_content
|
116
|
+
exit
|
117
|
+
end
|
118
|
+
|
119
|
+
#创建Xcodeproj 对象
|
120
|
+
project = Xcodeproj::Project.open(xprojName)
|
121
|
+
|
122
|
+
#创建group
|
123
|
+
new_groups = Array.new(0)
|
124
|
+
|
125
|
+
if cmp == '-b'
|
126
|
+
custom_mvvm_dirs.each do |mvvm_dirName|
|
127
|
+
new_group_ref = project.main_group.find_subpath(File.join(arg_dir_new,mvvm_dirName),true)
|
128
|
+
new_groups.push(new_group_ref)
|
129
|
+
end
|
130
|
+
else
|
131
|
+
begin
|
132
|
+
group_ref = project.main_group.find_subpath(File.join(arg_dir_new),true)
|
133
|
+
new_groups.push(group_ref)
|
134
|
+
rescue Exception => e
|
135
|
+
raise e
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
# puts ["cmp",cmp].join("===>")
|
140
|
+
# puts ["arg_dir_new",arg_dir_new].join("===>")
|
141
|
+
# puts ["new_groups",new_groups].join("===>")
|
142
|
+
# puts ["new_groups[0].class",new_groups[0].class].join("===>")
|
143
|
+
# puts ["new_groups.class",new_groups.class].join("===>")
|
144
|
+
|
145
|
+
# 设置 group set_source_tree set_path
|
146
|
+
new_groups.each do |group|
|
147
|
+
#往上查找,并设置实际path
|
148
|
+
pre_path = ""
|
149
|
+
group.parents.each do |parentGroup|
|
150
|
+
# puts ["parentGroup.display_name",parentGroup.display_name].join("===>")
|
151
|
+
if parentGroup.display_name == 'Main Group'
|
152
|
+
next
|
153
|
+
end
|
154
|
+
if pre_path == ""
|
155
|
+
pre_path = parentGroup.display_name
|
156
|
+
else
|
157
|
+
pre_path = [pre_path,parentGroup.display_name].join('/')
|
158
|
+
end
|
159
|
+
#设置实际路径
|
160
|
+
parentGroup.set_source_tree('SOURCE_ROOT')
|
161
|
+
parentGroup.set_path(pre_path)
|
162
|
+
end
|
163
|
+
|
164
|
+
#设置实际路径
|
165
|
+
# puts ["group.display_name",group.display_name].join("===>")
|
166
|
+
if pre_path == ""
|
167
|
+
pre_path = group.display_name
|
168
|
+
else
|
169
|
+
pre_path = [pre_path,group.display_name].join('/')
|
170
|
+
end
|
171
|
+
# puts ["pre_path",pre_path].join("===>")
|
172
|
+
group.set_source_tree('SOURCE_ROOT')
|
173
|
+
group.set_path(pre_path)
|
174
|
+
|
175
|
+
#创建group实体
|
176
|
+
createRealFinder(group)
|
177
|
+
end
|
178
|
+
|
179
|
+
#添加文件到group
|
180
|
+
# new_file_refs = addToGroupFile(group,'Test')
|
181
|
+
|
182
|
+
#添加源文件引用到target
|
183
|
+
# project.targets.first.add_file_references(new_file_refs)
|
184
|
+
#保存并重新加载
|
185
|
+
project.save
|
186
|
+
end
|
187
|
+
end
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xaddgroup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.6.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- 唐斌
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-10-20 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Batch Add Group To Xcodeproj, And map Entity Directory .
|
14
|
+
email: tangbineml@gmail.com
|
15
|
+
executables:
|
16
|
+
- xaddgroup
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- bin/xaddgroup
|
21
|
+
- lib/xaddgroup.rb
|
22
|
+
homepage: http://rubygems.org/gems/xaddgroup
|
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.6.7
|
43
|
+
signing_key:
|
44
|
+
specification_version: 4
|
45
|
+
summary: xaddgroup , show more 'xaddgroup --help'
|
46
|
+
test_files: []
|