cocoapods-vipers 0.0.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e62efc7b04bbda415047eb96be9ce771674cb7d377cc8461680533f4a5d661b9
4
- data.tar.gz: a3a602c6509127e2be989c6c3a4e755d5802622f2379160d8502b3ea8b0fe3f3
3
+ metadata.gz: 955f762815a084b35b851037fc3b3a82be44f13ce49cef0f496cf70f32bde70d
4
+ data.tar.gz: 208b7100f16ac29a91797b282d7344c89931e60acd6202f0a17184b37818a7e2
5
5
  SHA512:
6
- metadata.gz: 82eefc076f1b37d8828ae1d1e5e3e0c4f584ede0fcd0814dc10d8e70a02a335ca97ed4673989cfbe57fef2ee7550708101d4ceb337d6fd7d72820e09ae18182a
7
- data.tar.gz: 5adf1cf269783de67fcea45d5202d0f2df405e5dcc8c5d8f705b471f4d55bb871d5a3eb332e6f411402d6fbb0e42d0afdd14f4c3f795334d65392c5d4a0d31c8
6
+ metadata.gz: 64e2b36364468a508cd87c9f7c9b711c66aa661acd7f9f6b509d92aeaa9a8d0f3d08a348621f518393d077143d3927a5020a9b682af2697c8cae22f87e558d3c
7
+ data.tar.gz: 904ca06ed03e28b425574535cccc87660fe05526505c8bf07996e4e75cb46adbe088ccdc2ac02b2dd152f9ea083426a81f30b1df2010ff6fc714bdf60b6b1c74
@@ -1,3 +1,3 @@
1
1
  module CocoapodsVipers
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.4"
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
 
@@ -47,7 +47,7 @@ def handleClsAndMethod(viper, vipers_params_class, vipers_ext_func)
47
47
  #{assign_lines_text}
48
48
  }
49
49
  required public init() {
50
- fatalError("init() has not been implemented")
50
+ print("default init")
51
51
  }
52
52
  }
53
53
  RUBY
@@ -79,9 +79,56 @@ 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
- def sync(paths)
131
+ def sync(paths, pods)
85
132
  Pod::UI.puts "Synchronizing Vipers yml"
86
133
 
87
134
  if !File.exists?("vipers_config.yml")
@@ -94,14 +141,46 @@ 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
+ pod_frameworks_all_path = json['pod_frameworks_all_path']
147
+
148
+ flag = check_duplicate_viper(paths, main_project_vipers_json_path, vipers_json_path)
149
+
150
+ if flag['result']
151
+ raise "viper脚本执行失败,出现重复定义的viper: #{flag['viper']}"
152
+ end
153
+
154
+ check_unused_pods = false
155
+
156
+ if json['check_unused_pods'] == 'true'
157
+ check_unused_pods = true
158
+ end
159
+
160
+ framework_array = pods
161
+
162
+ if pod_frameworks_all_path
163
+ if File.exists?(pod_frameworks_all_path)
164
+ fileData = File.read(pod_frameworks_all_path)
165
+ all_framework = JSON.parse(fileData)
166
+ framework_array = all_framework
167
+ end
168
+ end
169
+
170
+ should_check = false
171
+ if json['check_json'] == 'true'
172
+ should_check = true
173
+ end
174
+
97
175
  # Pod::UI.puts "json: #{json}"
98
176
  # Pod::UI.puts "ext_path: #{ext_path}"
99
177
  # Pod::UI.puts "pod_paths: #{paths}"
100
178
 
101
- # vipers_case = []
179
+ vipers_case = []
102
180
  vipers_create_binder = []
103
181
  vipers_params_class = []
104
182
  vipers_ext_func = []
183
+ vipers_call_binder = []
105
184
 
106
185
  if !paths
107
186
  Pod::UI.puts "没有找到对应的业务组件,以Hycan开头的"
@@ -132,28 +211,111 @@ module CocoapodsVipers
132
211
  data_hash = JSON.parse(file)
133
212
  vipers = data_hash["vipers"]
134
213
 
135
- # vipers_case.push("// MARK: - #{data_hash["moduleName"]} #{data_hash["description"]}")
214
+ vipers_case.push("// MARK: - #{data_hash["moduleName"]} #{data_hash["description"]}")
136
215
  vipers_create_binder.push(" // MARK: - #{data_hash["moduleName"]} Create Binder")
137
216
  vipers_params_class.push(" // MARK: - #{data_hash["moduleName"]} Params Class\n")
138
217
  vipers_ext_func.push(" // MARK: - #{data_hash["moduleName"]} Extension Func\n")
139
-
218
+ vipers_call_binder.push(" init#{data_hash["moduleName"]}Binder()")
219
+ vipers_create_binder.push(" public static func init#{data_hash["moduleName"]}Binder() {")
220
+ cls_array = []
140
221
  vipers.each do |viper|
141
- # vipers_case.push(" case #{viper["viper"]}")
222
+ if viper["description"] == ""
223
+ vipers_case.push(" case #{viper["viper"]}")
224
+ else
225
+ vipers_case.push(" //#{viper["description"]}\n case #{viper["viper"]}")
226
+ end
142
227
  handleClsAndMethod(viper, vipers_params_class, vipers_ext_func)
143
228
  if spec['spec_name'] == main_project_vipers_json_path
144
229
  vipers_create_binder.push(" //#{viper["description"]}\n VIPERBinder.addUnity(className: \"#{viper["class"]}\", identifier: VIPERs.#{viper["viper"]}.identifier)")
145
230
  else
146
231
  vipers_create_binder.push(" //#{viper["description"]}\n VIPERBinder.addUnity(projectClassName: \"#{data_hash["moduleName"]}.#{viper["class"]}\", identifier: VIPERs.#{viper["viper"]}.identifier)")
147
- end
232
+ end
233
+ cls_array.push(viper["class"])
148
234
  end
149
- vipers_create_binder.push("\n")
235
+ vipers_case.push("\n")
236
+ vipers_create_binder.push(" }\n")
237
+
238
+ # 检测模块内未使用的Pods-framework
239
+ if check_unused_pods
240
+ # Pod::UI.puts "检测模块内未使用的Pods-framework"
241
+ dir_path = spec_path + '/' + data_hash["moduleName"]
242
+ if spec['spec_name'] == main_project_vipers_json_path
243
+ dir_path = '.' + '/HycanCommunity/Swift'
244
+ end
245
+
246
+ traverse_dir(dir_path) { |f|
247
+ if f.to_s() =~ /\.swift$/ || f.to_s() =~ /\.h$/ || f.to_s() =~ /\.m$/
248
+ lineNumber = 0
249
+ IO.readlines(f).each { |line|
250
+ framework_array.each do |framew|
251
+ if line =~ /^[\/\/]/
252
+ else
253
+ if line.index("#import <#{framew}")
254
+ # Pod::UI.puts "in file: #{f} - line in #{data_hash["moduleName"]}"
255
+ # Pod::UI.puts line
256
+ framework_array.delete(framew)
257
+ break
258
+ end
259
+
260
+ if line.index("import #{framew}")
261
+ # Pod::UI.puts "in file: #{f} - line in #{data_hash["moduleName"]}"
262
+ # Pod::UI.puts line
263
+ framework_array.delete(framew)
264
+ break
265
+ end
266
+ end
267
+ end
268
+ if lineNumber > 200
269
+ break
270
+ end
271
+ lineNumber += 1
272
+ }
273
+ end
274
+ }
275
+ end
276
+
277
+ # 检测模块内是否有未定义的 class
278
+ if should_check
279
+ # Pod::UI.puts "检测模块内是否有未定义的 class"
280
+ dir_path = spec_path + '/' + data_hash["moduleName"]
281
+ if spec['spec_name'] == main_project_vipers_json_path
282
+ dir_path = '.' + '/HycanCommunity/Swift'
283
+ end
284
+ traverse_dir(dir_path) { |f|
285
+ if f.to_s() =~ /\.swift$/
286
+ lineNumber = 0
287
+ IO.readlines(f).each { |line|
288
+ cls_array.each do |cls|
289
+ if line.index("class #{cls}")
290
+ cls_array.delete(cls)
291
+ break
292
+ end
293
+ end
294
+ if lineNumber > 100
295
+ break
296
+ end
297
+ lineNumber += 1
298
+ }
299
+ end
300
+ }
301
+
302
+ Pod::UI.puts "以下 Class 在 #{data_hash["moduleName"]} 没找到定义"
303
+ Pod::UI.puts cls_array.to_s()
304
+ end
305
+
150
306
  end
151
307
  end
152
308
 
153
- # injection_vipers_case = vipers_case.join("\n")
309
+ if check_unused_pods
310
+ Pod::UI.puts "以下 Pod 的 Framework 在主工程+Pod工程都没找到定义"
311
+ Pod::UI.puts framework_array.to_s()
312
+ end
313
+
314
+ injection_vipers_case = vipers_case.join("\n")
154
315
  injection_vipers_params_class = vipers_params_class.join("\n")
155
316
  injection_vipers_ext_func = vipers_ext_func.join("\n")
156
317
  injection_vipers_create_binder = vipers_create_binder.join("\n")
318
+ injection_vipers_call_binder = vipers_call_binder.join("\n")
157
319
 
158
320
  template_file = ''
159
321
 
@@ -164,14 +326,25 @@ module CocoapodsVipers
164
326
  end
165
327
 
166
328
  template = File.read(template_file)
167
-
168
- # 替换 /** Injection VIPERS case **/ (暂不执行)
169
- template.gsub!("/** Injection VIPERBinderHelper autoCreateBinder **/", injection_vipers_create_binder)
329
+ template.gsub!("/** Injection VIPERBinderHelper autoCreateBinder init **/", injection_vipers_create_binder)
170
330
  template.gsub!("/** Injection VIPERs extension **/", injection_vipers_ext_func)
171
331
  template.gsub!("/** Injection VIPERParams class **/", injection_vipers_params_class)
172
332
 
173
333
  File.open(ext_path, "w") { |file| file.puts template }
174
334
 
335
+ prorocols_template_file = ''
336
+
337
+ if prorocols_template_path
338
+ prorocols_template_file = prorocols_template_path
339
+ else
340
+ prorocols_template_file = File.dirname(__FILE__) + '/template/Protocols.swift' # 脚本所在目录 寻找模板文件
341
+ end
342
+
343
+ prorocols_template = File.read(prorocols_template_file)
344
+ prorocols_template.gsub!("/** Injection VIPERS case **/", injection_vipers_case)
345
+ prorocols_template.gsub!("/** Injection VIPERBinderHelper call init function **/", injection_vipers_call_binder)
346
+ File.open(protocols_path, "w") { |file| file.puts prorocols_template }
347
+
175
348
  # 1 校验没有重复的 枚举值 enum
176
349
  # 2 读取模板的swift文件
177
350
  # 3 遍历读取模块里的json ps: 主工程 + 业务工程
@@ -5,6 +5,7 @@ module CocoapodsVipers
5
5
 
6
6
  Pod::HooksManager.register('cocoapods-vipers', :pre_install) do |_context, _|
7
7
  paths = []
8
+ pods = []
8
9
  puts 'vipers hook pre_install'
9
10
  dependencies = _context.podfile.dependencies
10
11
  dependencies.each do |d|
@@ -17,8 +18,9 @@ module CocoapodsVipers
17
18
  # puts d.external_source[:path]
18
19
  paths.push({ 'spec_path' => d.external_source[:path], 'spec_name' => d.name })
19
20
  end
21
+ pods.push(d.name)
20
22
  end
21
- CocoapodsVipers::Vipers.new.sync(paths)
23
+ CocoapodsVipers::Vipers.new.sync(paths, pods)
22
24
  end
23
25
 
24
26
  Pod::HooksManager.register('cocoapods-vipers', :post_install) do |context|
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.4
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: 2022-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -49,10 +49,11 @@ 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
55
- homepage: https://github.com/EXAMPLE/cocoapods-vipers
56
+ homepage: https://github.com/Cellphoness/cocoapods-vipers/
56
57
  licenses:
57
58
  - MIT
58
59
  metadata: {}
@@ -71,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
72
  - !ruby/object:Gem::Version
72
73
  version: '0'
73
74
  requirements: []
74
- rubygems_version: 3.1.4
75
+ rubygems_version: 3.3.11
75
76
  signing_key:
76
77
  specification_version: 4
77
78
  summary: cocoapods-vipers generate VIPER enum and medthod for Router which is in HycanServices