cocoapods-vipers 0.0.1
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/lib/cocoapods-vipers/command/vipers.rb +45 -0
- data/lib/cocoapods-vipers/command.rb +1 -0
- data/lib/cocoapods-vipers/gem_version.rb +3 -0
- data/lib/cocoapods-vipers/template/Vipers+Extension.swift +44 -0
- data/lib/cocoapods-vipers/vipers-sync.rb +182 -0
- data/lib/cocoapods-vipers.rb +1 -0
- data/lib/cocoapods_plugin.rb +34 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e62efc7b04bbda415047eb96be9ce771674cb7d377cc8461680533f4a5d661b9
|
4
|
+
data.tar.gz: a3a602c6509127e2be989c6c3a4e755d5802622f2379160d8502b3ea8b0fe3f3
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 82eefc076f1b37d8828ae1d1e5e3e0c4f584ede0fcd0814dc10d8e70a02a335ca97ed4673989cfbe57fef2ee7550708101d4ceb337d6fd7d72820e09ae18182a
|
7
|
+
data.tar.gz: 5adf1cf269783de67fcea45d5202d0f2df405e5dcc8c5d8f705b471f4d55bb871d5a3eb332e6f411402d6fbb0e42d0afdd14f4c3f795334d65392c5d4a0d31c8
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'cocoapods-vipers/vipers-sync'
|
2
|
+
require 'cocoapods'
|
3
|
+
include CocoapodsVipers
|
4
|
+
|
5
|
+
module Pod
|
6
|
+
class Command
|
7
|
+
# This is an example of a cocoapods plugin adding a top-level subcommand
|
8
|
+
# to the 'pod' command.
|
9
|
+
#
|
10
|
+
# You can also create subcommands of existing or new commands. Say you
|
11
|
+
# wanted to add a subcommand to `list` to show newly deprecated pods,
|
12
|
+
# (e.g. `pod list deprecated`), there are a few things that would need
|
13
|
+
# to change.
|
14
|
+
#
|
15
|
+
# - move this file to `lib/pod/command/list/deprecated.rb` and update
|
16
|
+
# the class to exist in the the Pod::Command::List namespace
|
17
|
+
# - change this class to extend from `List` instead of `Command`. This
|
18
|
+
# tells the plugin system that it is a subcommand of `list`.
|
19
|
+
# - edit `lib/cocoapods_plugins.rb` to require this file
|
20
|
+
#
|
21
|
+
# @todo Create a PR to add your plugin to CocoaPods/cocoapods.org
|
22
|
+
# in the `plugins.json` file, once your plugin is released.
|
23
|
+
#
|
24
|
+
class Vipers < Command
|
25
|
+
self.summary = 'Short description of cocoapods-vipers.'
|
26
|
+
|
27
|
+
self.description = <<-DESC
|
28
|
+
Longer description of cocoapods-vipers.
|
29
|
+
DESC
|
30
|
+
|
31
|
+
def initialize(argv)
|
32
|
+
super
|
33
|
+
end
|
34
|
+
|
35
|
+
def validate!
|
36
|
+
super
|
37
|
+
end
|
38
|
+
|
39
|
+
def run
|
40
|
+
Pod::UI.puts "Use 'pod install' or 'pod update' to do vipers generate"
|
41
|
+
# CocoapodsVipers::Vipers.new.sync()
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'cocoapods-vipers/command/vipers'
|
@@ -0,0 +1,44 @@
|
|
1
|
+
import Curry
|
2
|
+
|
3
|
+
//脚本里的模板
|
4
|
+
|
5
|
+
extension VIPERBinderHelper {
|
6
|
+
static func initAllBinder() {
|
7
|
+
/** Injection VIPERBinderHelper autoCreateBinder **/
|
8
|
+
}
|
9
|
+
}
|
10
|
+
|
11
|
+
|
12
|
+
extension VIPERParams {
|
13
|
+
|
14
|
+
/** Injection VIPERParams class **/
|
15
|
+
|
16
|
+
}
|
17
|
+
|
18
|
+
extension VIPERs {
|
19
|
+
|
20
|
+
/** Injection VIPERs extension **/
|
21
|
+
|
22
|
+
/// 第三方账号绑定 1
|
23
|
+
// func thirdPartyBind() -> Self {
|
24
|
+
// return .thirdPartyBind
|
25
|
+
// }
|
26
|
+
|
27
|
+
/// 第三方账号绑定参数 参数列表 2
|
28
|
+
/// - Parameters:
|
29
|
+
/// - id: 页面id
|
30
|
+
/// - path: 路径
|
31
|
+
/// - Returns: 参数返回值
|
32
|
+
// func thirdPartyBindParams(id: Int, path: String) -> VIPERParams.thirdPartyBind {
|
33
|
+
// return VIPERParams.thirdPartyBind(id: id, path: path)
|
34
|
+
// }
|
35
|
+
|
36
|
+
// /// 第三方账号绑定参数 柯里化 3
|
37
|
+
// var thirdPartyBindCurry: (Int) -> (String) -> VIPERParams.thirdPartyBind {
|
38
|
+
// return curry(thirdPartyBindParams)
|
39
|
+
// }
|
40
|
+
}
|
41
|
+
|
42
|
+
// Useage:
|
43
|
+
//VIPERs.function.thirdPartyBindParams(id: 1, path: "2")
|
44
|
+
//VIPERs.function.thirdPartyBindCurry(1)("2")
|
@@ -0,0 +1,182 @@
|
|
1
|
+
require 'cocoapods'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'yaml'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
def handleClsAndMethod(viper, vipers_params_class, vipers_ext_func)
|
7
|
+
|
8
|
+
if !viper["params"] || viper["params"].empty?
|
9
|
+
return
|
10
|
+
end
|
11
|
+
|
12
|
+
var_lines = []
|
13
|
+
assign_lines = []
|
14
|
+
init_params = [] #id: Int, path: String = "/", ids: Array<Int>
|
15
|
+
return_types = []
|
16
|
+
parmas_desc = []
|
17
|
+
return_args = []
|
18
|
+
|
19
|
+
viper["params"].each do |key, value|
|
20
|
+
defaultValue = ''
|
21
|
+
ketType = value["type"]
|
22
|
+
if value["default"] != nil
|
23
|
+
if ketType == 'String' || ketType == 'NSString'
|
24
|
+
defaultValue = " = \"#{value["default"]}\""
|
25
|
+
else
|
26
|
+
defaultValue = " = #{value["default"]}"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
return_types.push("(#{ketType})")
|
30
|
+
parmas_desc.push(" /// - #{key}: #{value["description"]}")
|
31
|
+
init_params.push("#{key}: #{ketType}#{defaultValue}")
|
32
|
+
var_lines.push(" public var #{key}: #{ketType}#{defaultValue}")
|
33
|
+
assign_lines.push(" self.#{key} = #{key}")
|
34
|
+
return_args.push("#{key}: #{key}")
|
35
|
+
end
|
36
|
+
|
37
|
+
var_lines_text = var_lines.join("\n")
|
38
|
+
assign_lines_text = assign_lines.join("\n")
|
39
|
+
init_params_text = init_params.join(", ")
|
40
|
+
init_params_text_line = " public required init(#{init_params_text}) {"
|
41
|
+
|
42
|
+
class_text = <<-RUBY
|
43
|
+
// MARK: - VIPERParams.#{viper["viper"]}
|
44
|
+
public class #{viper["viper"]}: Base {
|
45
|
+
#{var_lines_text}
|
46
|
+
#{init_params_text_line}
|
47
|
+
#{assign_lines_text}
|
48
|
+
}
|
49
|
+
required public init() {
|
50
|
+
fatalError("init() has not been implemented")
|
51
|
+
}
|
52
|
+
}
|
53
|
+
RUBY
|
54
|
+
init_params_text_method = " public func #{viper["viper"]}Params(#{init_params_text}) -> VIPERParams.#{viper["viper"]} {"
|
55
|
+
curry_return = " return curry(#{viper["viper"]}Params)"
|
56
|
+
curry_return_type = ": #{return_types.join(' -> ')} -> VIPERParams.#{viper["viper"]} {"
|
57
|
+
method_text = <<-RUBY
|
58
|
+
// MARK: - Methods of #{viper["viper"]}
|
59
|
+
/// #{viper["description"]}
|
60
|
+
public func #{viper["viper"]}() -> Self {
|
61
|
+
return .#{viper["viper"]}
|
62
|
+
}
|
63
|
+
|
64
|
+
/// #{viper["description"]}页面参数列表
|
65
|
+
/// - Parameters:
|
66
|
+
#{parmas_desc.join("\n")}
|
67
|
+
/// - Returns: 页面参数对象
|
68
|
+
#{init_params_text_method}
|
69
|
+
return VIPERParams.#{viper["viper"]}(#{return_args.join(", ")})
|
70
|
+
}
|
71
|
+
|
72
|
+
/// #{viper["description"]}页面参数 柯里化
|
73
|
+
public var #{viper["viper"]}Curry#{curry_return_type}
|
74
|
+
#{curry_return}
|
75
|
+
}
|
76
|
+
RUBY
|
77
|
+
|
78
|
+
vipers_params_class.push(class_text)
|
79
|
+
vipers_ext_func.push(method_text)
|
80
|
+
end
|
81
|
+
|
82
|
+
module CocoapodsVipers
|
83
|
+
class Vipers
|
84
|
+
def sync(paths)
|
85
|
+
Pod::UI.puts "Synchronizing Vipers yml"
|
86
|
+
|
87
|
+
if !File.exists?("vipers_config.yml")
|
88
|
+
Pod::UI.puts "vipers_config.yml not found"
|
89
|
+
return
|
90
|
+
end
|
91
|
+
|
92
|
+
json = YAML.load(File.open("vipers_config.yml"))
|
93
|
+
ext_path = json['hycan_service_injects_extension_path']
|
94
|
+
vipers_json_path = json['podspec_project_vipers_json_path']
|
95
|
+
main_project_vipers_json_path = json['main_project_vipers_json_path']
|
96
|
+
extension_template_path = json['extension_template_path']
|
97
|
+
# Pod::UI.puts "json: #{json}"
|
98
|
+
# Pod::UI.puts "ext_path: #{ext_path}"
|
99
|
+
# Pod::UI.puts "pod_paths: #{paths}"
|
100
|
+
|
101
|
+
# vipers_case = []
|
102
|
+
vipers_create_binder = []
|
103
|
+
vipers_params_class = []
|
104
|
+
vipers_ext_func = []
|
105
|
+
|
106
|
+
if !paths
|
107
|
+
Pod::UI.puts "没有找到对应的业务组件,以Hycan开头的"
|
108
|
+
return
|
109
|
+
end
|
110
|
+
|
111
|
+
paths.insert(0, { 'spec_path' => '', 'spec_name' => main_project_vipers_json_path})
|
112
|
+
|
113
|
+
paths.each do |spec|
|
114
|
+
# puts "spec: #{spec}"
|
115
|
+
spec_path = spec['spec_path']
|
116
|
+
json_path = ''
|
117
|
+
spec_json_path = ''
|
118
|
+
|
119
|
+
if spec['spec_name'] == main_project_vipers_json_path
|
120
|
+
json_path = spec['spec_name']
|
121
|
+
else
|
122
|
+
spec_json_path = "#{vipers_json_path}"
|
123
|
+
spec_json_path.gsub!("SPECNAME", spec['spec_name'])
|
124
|
+
json_path = spec_path + "/" + spec_json_path
|
125
|
+
end
|
126
|
+
|
127
|
+
if !File.exists?(json_path)
|
128
|
+
Pod::UI.puts "没有找到对应#{json_path}下的路由json"
|
129
|
+
else
|
130
|
+
|
131
|
+
file = File.read(json_path)
|
132
|
+
data_hash = JSON.parse(file)
|
133
|
+
vipers = data_hash["vipers"]
|
134
|
+
|
135
|
+
# vipers_case.push("// MARK: - #{data_hash["moduleName"]} #{data_hash["description"]}")
|
136
|
+
vipers_create_binder.push(" // MARK: - #{data_hash["moduleName"]} Create Binder")
|
137
|
+
vipers_params_class.push(" // MARK: - #{data_hash["moduleName"]} Params Class\n")
|
138
|
+
vipers_ext_func.push(" // MARK: - #{data_hash["moduleName"]} Extension Func\n")
|
139
|
+
|
140
|
+
vipers.each do |viper|
|
141
|
+
# vipers_case.push(" case #{viper["viper"]}")
|
142
|
+
handleClsAndMethod(viper, vipers_params_class, vipers_ext_func)
|
143
|
+
if spec['spec_name'] == main_project_vipers_json_path
|
144
|
+
vipers_create_binder.push(" //#{viper["description"]}\n VIPERBinder.addUnity(className: \"#{viper["class"]}\", identifier: VIPERs.#{viper["viper"]}.identifier)")
|
145
|
+
else
|
146
|
+
vipers_create_binder.push(" //#{viper["description"]}\n VIPERBinder.addUnity(projectClassName: \"#{data_hash["moduleName"]}.#{viper["class"]}\", identifier: VIPERs.#{viper["viper"]}.identifier)")
|
147
|
+
end
|
148
|
+
end
|
149
|
+
vipers_create_binder.push("\n")
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
# injection_vipers_case = vipers_case.join("\n")
|
154
|
+
injection_vipers_params_class = vipers_params_class.join("\n")
|
155
|
+
injection_vipers_ext_func = vipers_ext_func.join("\n")
|
156
|
+
injection_vipers_create_binder = vipers_create_binder.join("\n")
|
157
|
+
|
158
|
+
template_file = ''
|
159
|
+
|
160
|
+
if extension_template_path
|
161
|
+
template_file = extension_template_path
|
162
|
+
else
|
163
|
+
template_file = File.dirname(__FILE__) + '/template/Vipers+Extension.swift' # 脚本所在目录 寻找模板文件
|
164
|
+
end
|
165
|
+
|
166
|
+
template = File.read(template_file)
|
167
|
+
|
168
|
+
# 替换 /** Injection VIPERS case **/ (暂不执行)
|
169
|
+
template.gsub!("/** Injection VIPERBinderHelper autoCreateBinder **/", injection_vipers_create_binder)
|
170
|
+
template.gsub!("/** Injection VIPERs extension **/", injection_vipers_ext_func)
|
171
|
+
template.gsub!("/** Injection VIPERParams class **/", injection_vipers_params_class)
|
172
|
+
|
173
|
+
File.open(ext_path, "w") { |file| file.puts template }
|
174
|
+
|
175
|
+
# 1 校验没有重复的 枚举值 enum
|
176
|
+
# 2 读取模板的swift文件
|
177
|
+
# 3 遍历读取模块里的json ps: 主工程 + 业务工程
|
178
|
+
# 4 主工程的目标文件(HycanService下的) 注入各个模块绑定语句以及参数方法
|
179
|
+
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'cocoapods-vipers/gem_version'
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'cocoapods-vipers/vipers-sync'
|
2
|
+
require 'cocoapods'
|
3
|
+
|
4
|
+
module CocoapodsVipers
|
5
|
+
|
6
|
+
Pod::HooksManager.register('cocoapods-vipers', :pre_install) do |_context, _|
|
7
|
+
paths = []
|
8
|
+
puts 'vipers hook pre_install'
|
9
|
+
dependencies = _context.podfile.dependencies
|
10
|
+
dependencies.each do |d|
|
11
|
+
# puts d
|
12
|
+
ins_vars = d.instance_variables.map{|v|v.to_s[1..-1]}
|
13
|
+
methods = d.methods.map &:to_s
|
14
|
+
attribute = ins_vars & methods #attribute
|
15
|
+
# puts attribute
|
16
|
+
if d.name.match(/^Hycan/) && d.external_source
|
17
|
+
# puts d.external_source[:path]
|
18
|
+
paths.push({ 'spec_path' => d.external_source[:path], 'spec_name' => d.name })
|
19
|
+
end
|
20
|
+
end
|
21
|
+
CocoapodsVipers::Vipers.new.sync(paths)
|
22
|
+
end
|
23
|
+
|
24
|
+
Pod::HooksManager.register('cocoapods-vipers', :post_install) do |context|
|
25
|
+
# CocoapodsVipers::Vipers.new.sync()
|
26
|
+
puts 'vipers hook post_install'
|
27
|
+
end
|
28
|
+
|
29
|
+
Pod::HooksManager.register('cocoapods-vipers', :post_update) do |context|
|
30
|
+
puts 'vipers hook post_update'
|
31
|
+
# CocoapodsVipers::Vipers.new.sync()
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cocoapods-vipers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- fengjx
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-10-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.3'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: tool to generate VIPER enum and medthod for Router
|
42
|
+
email:
|
43
|
+
- 1026366384@qq.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- lib/cocoapods-vipers.rb
|
49
|
+
- lib/cocoapods-vipers/command.rb
|
50
|
+
- lib/cocoapods-vipers/command/vipers.rb
|
51
|
+
- lib/cocoapods-vipers/gem_version.rb
|
52
|
+
- lib/cocoapods-vipers/template/Vipers+Extension.swift
|
53
|
+
- lib/cocoapods-vipers/vipers-sync.rb
|
54
|
+
- lib/cocoapods_plugin.rb
|
55
|
+
homepage: https://github.com/EXAMPLE/cocoapods-vipers
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata: {}
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubygems_version: 3.1.4
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: cocoapods-vipers generate VIPER enum and medthod for Router which is in HycanServices
|
78
|
+
test_files: []
|