sjpush 0.0.3 → 0.0.4
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 +4 -4
- data/lib/sjProtocol.rb +49 -0
- data/lib/sjScript.rb +172 -0
- data/lib/sjpush.rb +20 -10
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 94ec344a14c510bd7d4fa0f90654feb187430c675ae4ae8916dff3cc26e50f28
|
|
4
|
+
data.tar.gz: cdf6c17b807d83ad493cfa7df1dd451d7626c9d789c75908508e2b365153fd9c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 780fb1326888dfce7a409e7bb4bffa6861b62aab930f8a5f1e32840f417d4f3912faa64414214e03313ccd64941b60ac1bdcbe77c2f509e87f5007b647a672b0
|
|
7
|
+
data.tar.gz: c853bae87653ae4acf3c88d0e56075730b3f878e0222bfc79ac26157fef8e4184277f3fb27a9ddaf9468adc55aaf4f48241d461a4c5484b1bbf064c243a4448e
|
data/lib/sjProtocol.rb
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
puts "请输入文件路径:"
|
|
2
|
+
input = gets
|
|
3
|
+
|
|
4
|
+
# chomp 删除尾部的换行
|
|
5
|
+
# strip 删除开头结尾的空格
|
|
6
|
+
filePath = input.chomp!.strip!
|
|
7
|
+
|
|
8
|
+
contents = String.new
|
|
9
|
+
obj_class = String.new
|
|
10
|
+
obj_delegate = String.new
|
|
11
|
+
|
|
12
|
+
File.new(filePath, "r").each_line do |line|
|
|
13
|
+
if ( /@interface/ =~ line ) then
|
|
14
|
+
obj_class = line.split[1]
|
|
15
|
+
puts "获取到类名: #{obj_class}"
|
|
16
|
+
# 准备生成代理
|
|
17
|
+
obj_delegate = obj_class + "Delegate"
|
|
18
|
+
contents << "@protocol #{obj_delegate};\n\n"
|
|
19
|
+
|
|
20
|
+
line = "#{line}\n@property (nonatomic, weak, readwrite, nullable) id<#{obj_delegate}> delegate;\n"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
contents << line
|
|
24
|
+
|
|
25
|
+
if ( /@end/ =~ line && !(obj_delegate.empty?) ) then
|
|
26
|
+
contents << "\n"
|
|
27
|
+
|
|
28
|
+
obj_method = ""
|
|
29
|
+
if ( /cell/i =~ obj_delegate )
|
|
30
|
+
obj_method = "- (void)tabCell:(#{obj_class} *)cell <#method#>"
|
|
31
|
+
else
|
|
32
|
+
obj_method = "- (void)<#method#>"
|
|
33
|
+
end
|
|
34
|
+
contents << (<<~"EOB")
|
|
35
|
+
@protocol #{obj_delegate} <NSObject>
|
|
36
|
+
|
|
37
|
+
@optional
|
|
38
|
+
#{obj_method}
|
|
39
|
+
|
|
40
|
+
@end
|
|
41
|
+
EOB
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
puts "生成完毕, 正在写入..."
|
|
46
|
+
file = File.new(filePath, "w")
|
|
47
|
+
file.syswrite(contents)
|
|
48
|
+
file.close
|
|
49
|
+
puts "写入完成"
|
data/lib/sjScript.rb
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
|
|
2
|
+
class Property
|
|
3
|
+
attr_accessor :type, :field
|
|
4
|
+
|
|
5
|
+
def initialize(type:, field:)
|
|
6
|
+
@type, @field = type, field
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def to_s
|
|
10
|
+
"type: #{type}, field: #{field}"
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class Recorder
|
|
17
|
+
attr_accessor :contents,
|
|
18
|
+
:trimPropertyFields,
|
|
19
|
+
:parseInterface,
|
|
20
|
+
:parseImplementation,
|
|
21
|
+
:parseImpPhaseOneFinished,
|
|
22
|
+
:parseImpPhaseTwoFinished
|
|
23
|
+
|
|
24
|
+
def initialize()
|
|
25
|
+
|
|
26
|
+
# 存放所有内容
|
|
27
|
+
@contents = String.new
|
|
28
|
+
|
|
29
|
+
# 存放变更的字段. (里面是 Property 对象)
|
|
30
|
+
@trimPropertyFields = Array.new
|
|
31
|
+
|
|
32
|
+
# 记录解析的阶段
|
|
33
|
+
@parseInterface = false
|
|
34
|
+
@parseImplementation = false
|
|
35
|
+
|
|
36
|
+
# 第一阶段解析完毕, 开头添加 @syn name = _name
|
|
37
|
+
@parseImpPhaseOneFinished = false
|
|
38
|
+
|
|
39
|
+
# 第二阶段解析完毕, 底部添加 - (type)filed {}
|
|
40
|
+
@parseImpPhaseTwoFinished = false
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def parsing(line:)
|
|
44
|
+
# 记录解析阶段
|
|
45
|
+
if /@interface/ =~ line then
|
|
46
|
+
self.parseInterface = true
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# imp
|
|
50
|
+
if /@implementation/ =~ line then
|
|
51
|
+
self.parseImplementation = true
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# end
|
|
55
|
+
if /@end/ =~ line then
|
|
56
|
+
if self.parseInterface then
|
|
57
|
+
self.parseInterface = false
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
if self.parseImplementation then
|
|
61
|
+
self.parseImplementation = false
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# 如果正在解析 interface
|
|
66
|
+
if self.parseInterface then
|
|
67
|
+
# [^readonly|readwrite] 匹配除 readonly|readwrite 以外的字符串
|
|
68
|
+
if /\(nonatomic.*[^readonly|readwrite]\)/ =~ line then
|
|
69
|
+
# 将此行添加 readonly
|
|
70
|
+
line.gsub!(/\)/, ", readonly)")
|
|
71
|
+
|
|
72
|
+
# 记录 属性, imp 生成时需要.
|
|
73
|
+
|
|
74
|
+
# 记录 type
|
|
75
|
+
arr = line.split
|
|
76
|
+
type = arr[-2] + " *"
|
|
77
|
+
|
|
78
|
+
# 记录 field
|
|
79
|
+
field = arr.last.gsub!(/\*|;/, "")
|
|
80
|
+
self.trimPropertyFields.push(Property.new(type:type, field:field))
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
|
|
84
|
+
# 如果正在解析 imp
|
|
85
|
+
if self.parseImplementation then
|
|
86
|
+
if !self.parseImpPhaseOneFinished then
|
|
87
|
+
self.parseImpPhaseOneFinished = true
|
|
88
|
+
self.trimPropertyFields.each do |property|
|
|
89
|
+
line << "@synthesize " + property.field + " = _" + property.field + ";\n";
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# 如果解析到了最后 imp
|
|
95
|
+
if /@end/ =~ line && !self.parseImplementation && self.parseImpPhaseOneFinished then
|
|
96
|
+
self.parseImpPhaseTwoFinished = true;
|
|
97
|
+
|
|
98
|
+
self.trimPropertyFields.each do |property|
|
|
99
|
+
# - (type *)name {\n
|
|
100
|
+
# \t if ( _name ) return _name; \n
|
|
101
|
+
# \t \n
|
|
102
|
+
# \t return _name; \n
|
|
103
|
+
# }
|
|
104
|
+
type = property.type
|
|
105
|
+
field = property.field
|
|
106
|
+
# self.contents << "\n- (#{type})#{field} {\n\tif ( _#{field} ) return _#{field};\n\t\n\treturn _#{field};\n}\n\n"
|
|
107
|
+
self.contents << (<<~"EOB")
|
|
108
|
+
- (#{type})#{field} {
|
|
109
|
+
if ( _#{field} ) return _#{field};
|
|
110
|
+
|
|
111
|
+
return _#{field};
|
|
112
|
+
}
|
|
113
|
+
EOB
|
|
114
|
+
end
|
|
115
|
+
puts "全部解析完毕"
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
self.contents += line;
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def parseInterface=(result)
|
|
123
|
+
@parseInterface = result
|
|
124
|
+
|
|
125
|
+
if result then
|
|
126
|
+
puts "开始解析 interface"
|
|
127
|
+
else
|
|
128
|
+
puts "解析完毕 interface"
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
def parseImplementation=(result)
|
|
133
|
+
@parseImplementation = result
|
|
134
|
+
|
|
135
|
+
if result then
|
|
136
|
+
puts "开始解析 implementation"
|
|
137
|
+
else
|
|
138
|
+
puts "解析完毕 implementation"
|
|
139
|
+
end
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
# -------------------
|
|
147
|
+
|
|
148
|
+
BEGIN {
|
|
149
|
+
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
puts "请输入文件路径:"
|
|
154
|
+
input = gets
|
|
155
|
+
|
|
156
|
+
# strip 删除字符串开头和末尾的空白字符
|
|
157
|
+
filePath = input.chomp!.strip!
|
|
158
|
+
recorder = Recorder.new
|
|
159
|
+
|
|
160
|
+
# generate
|
|
161
|
+
File.new(filePath, "r").each_line do |line|
|
|
162
|
+
recorder.parsing(line: line)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
# write
|
|
166
|
+
file = File.new(filePath, "w")
|
|
167
|
+
file.syswrite(recorder.contents)
|
|
168
|
+
file.close
|
|
169
|
+
|
|
170
|
+
END {
|
|
171
|
+
|
|
172
|
+
}
|
data/lib/sjpush.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#require "sjpush/version"
|
|
2
2
|
#!/usr/bin/env ruby
|
|
3
|
+
|
|
3
4
|
puts <<-DESC
|
|
4
5
|
===============================================
|
|
5
6
|
请输入操作序号:
|
|
@@ -9,6 +10,10 @@ puts <<-DESC
|
|
|
9
10
|
4. pod发布(pod repo push ..repo ..podspec)
|
|
10
11
|
5. 删除标签(git -d .., git push origin :..)
|
|
11
12
|
|
|
13
|
+
补全代码:
|
|
14
|
+
-1. 自动写协议
|
|
15
|
+
-2. 自动补全懒加载
|
|
16
|
+
|
|
12
17
|
输入`exit`退出脚本
|
|
13
18
|
===============================================
|
|
14
19
|
DESC
|
|
@@ -19,6 +24,9 @@ $seq_git_add_tag = 3
|
|
|
19
24
|
$seq_pod_release = 4
|
|
20
25
|
$seq_git_delete_tag = 5
|
|
21
26
|
|
|
27
|
+
$seq_lazy_protocol = -1
|
|
28
|
+
$seq_lazy_property = -2
|
|
29
|
+
|
|
22
30
|
seq = gets
|
|
23
31
|
|
|
24
32
|
exit if seq.casecmp('exit') == 1
|
|
@@ -126,14 +134,10 @@ def considerNextTask(beforeSeq, git)
|
|
|
126
134
|
whetherToPushMaster(git)
|
|
127
135
|
whetherAddNewTag(git)
|
|
128
136
|
whetherReleasePod(git)
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
if beforeSeq == $seq_git_push_master
|
|
137
|
+
elsif beforeSeq == $seq_git_push_master
|
|
132
138
|
whetherAddNewTag(git)
|
|
133
139
|
whetherReleasePod(git)
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if beforeSeq == $seq_git_add_tag
|
|
140
|
+
elsif beforeSeq == $seq_git_add_tag
|
|
137
141
|
whetherReleasePod(git)
|
|
138
142
|
end
|
|
139
143
|
end
|
|
@@ -144,14 +148,20 @@ def handleSeq(seq)
|
|
|
144
148
|
git = Git.new
|
|
145
149
|
if seq == $seq_git_commit
|
|
146
150
|
git.commit
|
|
147
|
-
|
|
151
|
+
elsif seq == $seq_git_push_master
|
|
148
152
|
git.pushMaster
|
|
149
|
-
|
|
153
|
+
elsif seq == $seq_git_add_tag
|
|
150
154
|
git.addNewTag
|
|
151
|
-
|
|
155
|
+
elsif seq == $seq_pod_release
|
|
152
156
|
git.podRelease
|
|
153
|
-
|
|
157
|
+
elsif seq == $seq_git_delete_tag
|
|
154
158
|
git.deleteTag
|
|
159
|
+
elsif seq == $seq_lazy_protocol
|
|
160
|
+
require 'sjProtocol'
|
|
161
|
+
exit
|
|
162
|
+
elsif seq == $seq_lazy_property
|
|
163
|
+
require 'sjScript'
|
|
164
|
+
exit
|
|
155
165
|
end
|
|
156
166
|
|
|
157
167
|
considerNextTask(seq, git)
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sjpush
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0.
|
|
4
|
+
version: 0.0.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- SanJiang
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2018-07-
|
|
11
|
+
date: 2018-07-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: 用于辅助git提交
|
|
14
14
|
email:
|
|
@@ -19,6 +19,8 @@ extensions: []
|
|
|
19
19
|
extra_rdoc_files: []
|
|
20
20
|
files:
|
|
21
21
|
- bin/sjpush
|
|
22
|
+
- lib/sjProtocol.rb
|
|
23
|
+
- lib/sjScript.rb
|
|
22
24
|
- lib/sjpush.rb
|
|
23
25
|
homepage: https://github.com/changsanjiang/sjpush
|
|
24
26
|
licenses:
|