cocoapods-vipers 0.0.1 → 0.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e62efc7b04bbda415047eb96be9ce771674cb7d377cc8461680533f4a5d661b9
4
- data.tar.gz: a3a602c6509127e2be989c6c3a4e755d5802622f2379160d8502b3ea8b0fe3f3
3
+ metadata.gz: 86b30e5d6e15ed51aaebf0a319486a94530134f1663c68feda794775bb729902
4
+ data.tar.gz: e63128f12a5d242607c43d5ca5b94f671cf17ab4ea62633d06da9b68bb66d9a7
5
5
  SHA512:
6
- metadata.gz: 82eefc076f1b37d8828ae1d1e5e3e0c4f584ede0fcd0814dc10d8e70a02a335ca97ed4673989cfbe57fef2ee7550708101d4ceb337d6fd7d72820e09ae18182a
7
- data.tar.gz: 5adf1cf269783de67fcea45d5202d0f2df405e5dcc8c5d8f705b471f4d55bb871d5a3eb332e6f411402d6fbb0e42d0afdd14f4c3f795334d65392c5d4a0d31c8
6
+ metadata.gz: a9a743d62ebebc9917ad3526a2293029d3c3d9b140fdd30f3c9bf8a91e32070193f537fa8842654d6c2f1a0c546fa0b17b30ebb218a4996c80952840364c5133
7
+ data.tar.gz: a9d221391e997d9cd4d4b007359b4098ae54b229b2e5e7b85853f5b8a8d03915d0905a18a4c6a2248ad0f0ee4fb425319b1f69df6952d2859beece030849a80d
@@ -1,3 +1,3 @@
1
1
  module CocoapodsVipers
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,20 @@
1
+ import UIKit
2
+
3
+ // MARK: VIPERs Enum
4
+ public enum VIPERs: String {
5
+ public typealias RawValue = String
6
+ /** Injection VIPERS case **/
7
+ }
8
+
9
+ public struct VIPERBinderHelper {
10
+
11
+ public static func initBinder(shouldObserveForAppLaunch: Bool = true) {
12
+
13
+ // initAllBinder
14
+ /** Injection VIPERBinderHelper call init function **/
15
+
16
+ if shouldObserveForAppLaunch {
17
+ Router.observeForAppLaunch()
18
+ }
19
+ }
20
+ }
@@ -3,9 +3,7 @@ import Curry
3
3
  //脚本里的模板
4
4
 
5
5
  extension VIPERBinderHelper {
6
- static func initAllBinder() {
7
- /** Injection VIPERBinderHelper autoCreateBinder **/
8
- }
6
+ /** Injection VIPERBinderHelper autoCreateBinder init **/
9
7
  }
10
8
 
11
9
 
@@ -79,6 +79,53 @@ RUBY
79
79
  vipers_ext_func.push(method_text)
80
80
  end
81
81
 
82
+ def traverse_dir(file_path)
83
+ if File.directory? file_path
84
+ Dir.foreach(file_path) do |file|
85
+ if file != "." && file != ".."
86
+ traverse_dir(file_path + "/" + file){|x| yield x}
87
+ end
88
+ end
89
+ else
90
+ yield file_path
91
+ end
92
+ end
93
+
94
+ # 返回 { Bool, String } 是否存在重复的viper
95
+ def check_duplicate_viper(paths, main_path, vipers_json_path)
96
+ arr = []
97
+ paths.each do |spec|
98
+ json_path = ''
99
+ if spec['spec_name'] == main_path
100
+ json_path = spec['spec_name']
101
+ else
102
+ spec_json_path = "#{vipers_json_path}"
103
+ spec_json_path.gsub!("SPECNAME", spec['spec_name'])
104
+ json_path = spec['spec_path'] + "/" + spec_json_path
105
+ end
106
+
107
+ if File.exists?(json_path)
108
+ file = File.read(json_path)
109
+ data_hash = JSON.parse(file)
110
+ vipers = data_hash["vipers"]
111
+
112
+ vipers.each do |viper|
113
+ arr.push(viper["viper"])
114
+ end
115
+
116
+ end
117
+ end
118
+
119
+ result = arr.detect {|e| arr.rindex(e) != arr.index(e) }
120
+
121
+ if result
122
+ return { 'result' => true, 'viper' => result }
123
+ else
124
+ return { 'result' => false }
125
+ end
126
+
127
+ end
128
+
82
129
  module CocoapodsVipers
83
130
  class Vipers
84
131
  def sync(paths)
@@ -94,14 +141,29 @@ module CocoapodsVipers
94
141
  vipers_json_path = json['podspec_project_vipers_json_path']
95
142
  main_project_vipers_json_path = json['main_project_vipers_json_path']
96
143
  extension_template_path = json['extension_template_path']
144
+ prorocols_template_path = json['prorocols_template_path']
145
+ protocols_path = json['hycan_service_injects_protocols_path']
146
+
147
+ flag = check_duplicate_viper(paths, main_project_vipers_json_path, vipers_json_path)
148
+
149
+ if flag['result']
150
+ raise "viper脚本执行失败,出现重复定义的viper: #{flag['viper']}"
151
+ end
152
+
153
+ should_check = false
154
+ if json['check_json'] == 'true'
155
+ should_check = true
156
+ end
157
+
97
158
  # Pod::UI.puts "json: #{json}"
98
159
  # Pod::UI.puts "ext_path: #{ext_path}"
99
160
  # Pod::UI.puts "pod_paths: #{paths}"
100
161
 
101
- # vipers_case = []
162
+ vipers_case = []
102
163
  vipers_create_binder = []
103
164
  vipers_params_class = []
104
165
  vipers_ext_func = []
166
+ vipers_call_binder = []
105
167
 
106
168
  if !paths
107
169
  Pod::UI.puts "没有找到对应的业务组件,以Hycan开头的"
@@ -132,28 +194,67 @@ module CocoapodsVipers
132
194
  data_hash = JSON.parse(file)
133
195
  vipers = data_hash["vipers"]
134
196
 
135
- # vipers_case.push("// MARK: - #{data_hash["moduleName"]} #{data_hash["description"]}")
197
+ vipers_case.push("// MARK: - #{data_hash["moduleName"]} #{data_hash["description"]}")
136
198
  vipers_create_binder.push(" // MARK: - #{data_hash["moduleName"]} Create Binder")
137
199
  vipers_params_class.push(" // MARK: - #{data_hash["moduleName"]} Params Class\n")
138
200
  vipers_ext_func.push(" // MARK: - #{data_hash["moduleName"]} Extension Func\n")
139
-
201
+ vipers_call_binder.push(" init#{data_hash["moduleName"]}Binder()")
202
+ vipers_create_binder.push(" public static func init#{data_hash["moduleName"]}Binder() {")
203
+ cls_array = []
140
204
  vipers.each do |viper|
141
- # vipers_case.push(" case #{viper["viper"]}")
205
+ if viper["description"] == ""
206
+ vipers_case.push(" case #{viper["viper"]}")
207
+ else
208
+ vipers_case.push(" //#{viper["description"]}\n case #{viper["viper"]}")
209
+ end
142
210
  handleClsAndMethod(viper, vipers_params_class, vipers_ext_func)
143
211
  if spec['spec_name'] == main_project_vipers_json_path
144
212
  vipers_create_binder.push(" //#{viper["description"]}\n VIPERBinder.addUnity(className: \"#{viper["class"]}\", identifier: VIPERs.#{viper["viper"]}.identifier)")
145
213
  else
146
214
  vipers_create_binder.push(" //#{viper["description"]}\n VIPERBinder.addUnity(projectClassName: \"#{data_hash["moduleName"]}.#{viper["class"]}\", identifier: VIPERs.#{viper["viper"]}.identifier)")
147
- end
215
+ end
216
+ cls_array.push(viper["class"])
217
+ end
218
+ vipers_case.push("\n")
219
+ vipers_create_binder.push(" }\n")
220
+
221
+ # 检测模块内是否有未定义的 class
222
+ if should_check
223
+ # --check
224
+ dir_path = spec_path + '/' + data_hash["moduleName"]
225
+ if spec['spec_name'] == main_project_vipers_json_path
226
+ dir_path = '.' + '/HycanCommunity/Swift'
227
+ end
228
+ traverse_dir(dir_path) { |f|
229
+ if f.to_s() =~ /\.swift$/
230
+ lineNumber = 0
231
+ IO.readlines(f).each { |line|
232
+ cls_array.each do |cls|
233
+ if line.index("class #{cls}")
234
+ cls_array.delete(cls)
235
+ break
236
+ end
237
+ end
238
+ if lineNumber > 100
239
+ break
240
+ end
241
+ lineNumber += 1
242
+ }
243
+ end
244
+ }
245
+
246
+ Pod::UI.puts "以下 Class 在 #{data_hash["moduleName"]} 没找到定义"
247
+ Pod::UI.puts cls_array.to_s()
148
248
  end
149
- vipers_create_binder.push("\n")
249
+
150
250
  end
151
251
  end
152
252
 
153
- # injection_vipers_case = vipers_case.join("\n")
253
+ injection_vipers_case = vipers_case.join("\n")
154
254
  injection_vipers_params_class = vipers_params_class.join("\n")
155
255
  injection_vipers_ext_func = vipers_ext_func.join("\n")
156
256
  injection_vipers_create_binder = vipers_create_binder.join("\n")
257
+ injection_vipers_call_binder = vipers_call_binder.join("\n")
157
258
 
158
259
  template_file = ''
159
260
 
@@ -164,14 +265,25 @@ module CocoapodsVipers
164
265
  end
165
266
 
166
267
  template = File.read(template_file)
167
-
168
- # 替换 /** Injection VIPERS case **/ (暂不执行)
169
- template.gsub!("/** Injection VIPERBinderHelper autoCreateBinder **/", injection_vipers_create_binder)
268
+ template.gsub!("/** Injection VIPERBinderHelper autoCreateBinder init **/", injection_vipers_create_binder)
170
269
  template.gsub!("/** Injection VIPERs extension **/", injection_vipers_ext_func)
171
270
  template.gsub!("/** Injection VIPERParams class **/", injection_vipers_params_class)
172
271
 
173
272
  File.open(ext_path, "w") { |file| file.puts template }
174
273
 
274
+ prorocols_template_file = ''
275
+
276
+ if prorocols_template_path
277
+ prorocols_template_file = prorocols_template_path
278
+ else
279
+ prorocols_template_file = File.dirname(__FILE__) + '/template/Protocols.swift' # 脚本所在目录 寻找模板文件
280
+ end
281
+
282
+ prorocols_template = File.read(prorocols_template_file)
283
+ prorocols_template.gsub!("/** Injection VIPERS case **/", injection_vipers_case)
284
+ prorocols_template.gsub!("/** Injection VIPERBinderHelper call init function **/", injection_vipers_call_binder)
285
+ File.open(protocols_path, "w") { |file| file.puts prorocols_template }
286
+
175
287
  # 1 校验没有重复的 枚举值 enum
176
288
  # 2 读取模板的swift文件
177
289
  # 3 遍历读取模块里的json ps: 主工程 + 业务工程
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-vipers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - fengjx
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-27 00:00:00.000000000 Z
11
+ date: 2021-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -49,6 +49,7 @@ files:
49
49
  - lib/cocoapods-vipers/command.rb
50
50
  - lib/cocoapods-vipers/command/vipers.rb
51
51
  - lib/cocoapods-vipers/gem_version.rb
52
+ - lib/cocoapods-vipers/template/Protocols.swift
52
53
  - lib/cocoapods-vipers/template/Vipers+Extension.swift
53
54
  - lib/cocoapods-vipers/vipers-sync.rb
54
55
  - lib/cocoapods_plugin.rb