gwtools 0.0.17 → 0.0.19
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: de144674a5f0d90f4e7748588a2dbcf7e23e72612c93b9e8d43a14747116ec5c
|
4
|
+
data.tar.gz: 7bb208e297924ae193e7ab0adb6e3a246f3bf5435e5d61157bfa84291a0a3114
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecd6321bc3a60f7189a69efd3e936e7c67e11042f20c6d9ce71535901657caa5468b6585604c4f6726a431961af220385e5765fcbc760772e026cdc9cb37e502
|
7
|
+
data.tar.gz: 11fa148bf79fbd0a0978385f9e7799d5d8d4f04fdfcbbff8c7de1c40ee553f47418dfe48ed3f93c4e19762897f83d00398d47ea8fea3a6ddb161197d1e249942
|
@@ -9,7 +9,6 @@ module Gwtools
|
|
9
9
|
def initialize(file_path, target_path = '')
|
10
10
|
@file_path = file_path || raise(ArgumentError, 'Missing required argument `file_path`')
|
11
11
|
@target_path = target_path
|
12
|
-
|
13
12
|
analyDataStr
|
14
13
|
end
|
15
14
|
|
@@ -63,7 +62,6 @@ module Gwtools
|
|
63
62
|
@body,
|
64
63
|
@responseJson
|
65
64
|
)
|
66
|
-
# end
|
67
65
|
end
|
68
66
|
|
69
67
|
def getURL
|
@@ -20,6 +20,24 @@ module Gwtools
|
|
20
20
|
# @ENUMS = enums
|
21
21
|
# end
|
22
22
|
|
23
|
+
def self.add_quotes(array1, array2)
|
24
|
+
array1.map do |element|
|
25
|
+
if array2.include?(element)
|
26
|
+
"`#{element}`"
|
27
|
+
else
|
28
|
+
element
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.output_content(config_file)
|
34
|
+
# 处理特殊字符
|
35
|
+
this_name = Parser.extract_enum_name(config_file)
|
36
|
+
array1 = this_name.split(".")
|
37
|
+
array2 = %w[enum struct class protocol extension self]
|
38
|
+
return config_file.gsub(this_name, add_quotes(array1, array2).join("."))
|
39
|
+
end
|
40
|
+
|
23
41
|
def self.read_file(file_path)
|
24
42
|
swift_file = File.open(file_path, "r")
|
25
43
|
file_content = swift_file.read.force_encoding("UTF-8")
|
@@ -195,31 +213,13 @@ module Gwtools
|
|
195
213
|
enum
|
196
214
|
end
|
197
215
|
|
198
|
-
def add_quotes(array1, array2)
|
199
|
-
array1.map do |element|
|
200
|
-
if array2.include?(element)
|
201
|
-
"#{element}_"
|
202
|
-
else
|
203
|
-
element
|
204
|
-
end
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
def output_content(config_file)
|
209
|
-
# 处理特殊字符
|
210
|
-
this_name = Parser.extract_enum_name(config_file)
|
211
|
-
array1 = this_name.split(".")
|
212
|
-
array2 = %w[enum struct class protocol extension self]
|
213
|
-
return config_file.gsub(this_name, add_quotes(array1, array2).join("."))
|
214
|
-
end
|
215
|
-
|
216
216
|
def to_swift()
|
217
217
|
content_str = "public enum #{@enum_name} {\n"
|
218
218
|
@sub_enums.each do |key, value|
|
219
219
|
content_str += value.to_swift()
|
220
220
|
end
|
221
221
|
content_str += "}\n"
|
222
|
-
return output_content(content_str)
|
222
|
+
return Parser.output_content(content_str)
|
223
223
|
end
|
224
224
|
|
225
225
|
def write_to_file(file_path)
|
@@ -21,7 +21,11 @@ module Gwtools
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def run
|
24
|
-
FileHandler.new(@file_path, @target_path)
|
24
|
+
fh = FileHandler.new(@file_path, @target_path)
|
25
|
+
|
26
|
+
# File.rename("#{target_path + '/' + app_name}.swift_", "#{target_path + '/' + app_name}.swift")
|
27
|
+
# `swiftformat --swiftversion 5.0 "#{target_path + '/' + app_name}.swift",`
|
28
|
+
|
25
29
|
end
|
26
30
|
|
27
31
|
end
|
@@ -16,7 +16,7 @@ module Gwtools
|
|
16
16
|
def config_file
|
17
17
|
# ERB.new(File.read('restful_url.swift.erb'), nil, '>').result(binding)
|
18
18
|
template = <<-ERB
|
19
|
-
///
|
19
|
+
/// 此文件由代码生成,不要修改任何内容
|
20
20
|
|
21
21
|
import RxSwift
|
22
22
|
import GWNetWork
|
@@ -33,7 +33,9 @@ public extension <%="#{@api_name}"%> {
|
|
33
33
|
}
|
34
34
|
|
35
35
|
public extension <%="#{@api_name}"%> {
|
36
|
-
static func <%="#{@httpmethod}"%>(
|
36
|
+
static func <%="#{@httpmethod}"%>(
|
37
|
+
headerParms: [String: String] = [:],
|
38
|
+
parms: [String: Any] = [:],
|
37
39
|
isCache: Bool = false,
|
38
40
|
isLoading: Bool = false,
|
39
41
|
module: String? = nil,
|
@@ -42,11 +44,6 @@ public extension <%="#{@api_name}"%> {
|
|
42
44
|
<% else %>
|
43
45
|
des: String? = nil) -> Observable<Self.<%="#{@model_name}"%>> {
|
44
46
|
<% end %>
|
45
|
-
// ================= 逻辑处理 =================
|
46
|
-
let headerParms: [String : String] = [:]
|
47
|
-
let parms: [String : Any] = [:]
|
48
|
-
// ================= 逻辑处理 =================
|
49
|
-
|
50
47
|
return GWNetworkManager.request(requestType: .<%="#{@httpmethod}"%>,
|
51
48
|
prefixPath: "<%="#{@prefixPath}"%>",
|
52
49
|
modulePath: "<%="#{@modulePath}"%>",
|
@@ -64,26 +61,10 @@ public extension <%="#{@api_name}"%> {
|
|
64
61
|
<% end %>
|
65
62
|
}
|
66
63
|
}
|
67
|
-
ERB
|
68
|
-
ERB.new(template, nil, '>').result(binding)
|
69
|
-
end
|
70
64
|
|
71
|
-
def add_quotes(array1, array2)
|
72
|
-
array1.map do |element|
|
73
|
-
if array2.include?(element)
|
74
|
-
"#{element}_"
|
75
|
-
else
|
76
|
-
element
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
65
|
|
81
|
-
|
82
|
-
|
83
|
-
this_name = Parser.extract_enum_name(config_file)
|
84
|
-
array1 = this_name.split(".")
|
85
|
-
array2 = %w[enum struct class protocol extension self]
|
86
|
-
return config_file.gsub(this_name, add_quotes(array1, array2).join("."))
|
66
|
+
ERB
|
67
|
+
ERB.new(template, nil, '>').result(binding)
|
87
68
|
end
|
88
69
|
|
89
70
|
def initialize(file_path, api_name, httpmethod, prefixPath, modulePath, detailPath,
|
@@ -99,8 +80,16 @@ public extension <%="#{@api_name}"%> {
|
|
99
80
|
@readme = readme
|
100
81
|
puts "write to ==> #{file_path}"
|
101
82
|
File.open(file_path, 'w+') do |f|
|
102
|
-
puts
|
103
|
-
f.puts(
|
83
|
+
# f.puts(Parser.output_content(config_file))
|
84
|
+
f.puts(config_file)
|
85
|
+
end
|
86
|
+
|
87
|
+
# 格式化
|
88
|
+
`swiftformat --swiftversion 5.0 #{file_path}`
|
89
|
+
# 替换内容,重新写入
|
90
|
+
replaced_content = File.read(file_path)
|
91
|
+
File.open(file_path, "w") do |new_file|
|
92
|
+
new_file.puts(Parser.output_content(replaced_content))
|
104
93
|
end
|
105
94
|
end
|
106
95
|
end
|
@@ -182,8 +171,9 @@ public extension <%="#{@api_name}"%> {
|
|
182
171
|
|
183
172
|
modulePath = getModulePath(path, prefixPath)
|
184
173
|
detailPath = getDetailPath(path, prefixPath, modulePath)
|
185
|
-
|
174
|
+
json_data_is_arr = responseJson[root_path].is_a?(Array)
|
186
175
|
readme = """
|
176
|
+
|
187
177
|
请求参数
|
188
178
|
URL = #{path.chomp}
|
189
179
|
HTTPMETHOD = #{httpMethod.chomp}
|
@@ -197,12 +187,12 @@ class <##SomeViewModel##> {
|
|
197
187
|
}
|
198
188
|
|
199
189
|
public struct Output {
|
200
|
-
let data: BehaviorRelay<#{
|
190
|
+
let data: BehaviorRelay<#{json_data_is_arr ? "[" : ""}#{app_name}.#{httpMethod.capitalize.chomp}Model#{json_data_is_arr ? "]" : ""}>
|
201
191
|
}
|
202
192
|
|
203
193
|
public func transform(input: Input) -> Output {
|
204
|
-
let outDatas = BehaviorRelay<#{
|
205
|
-
input.<##AnyObservable##>.flatMapLatest({ [weak self] () -> Observable<#{
|
194
|
+
let outDatas = BehaviorRelay<#{json_data_is_arr ? "[" : ""}#{app_name}.#{httpMethod.capitalize.chomp}Model#{json_data_is_arr ? "]" : ""}>(value: [])
|
195
|
+
input.<##AnyObservable##>.flatMapLatest({ [weak self] () -> Observable<#{json_data_is_arr ? "[" : ""}#{app_name}.#{httpMethod.capitalize.chomp}Model#{json_data_is_arr ? "]" : ""}> in
|
206
196
|
guard let self = self else { return Observable.just([]) }
|
207
197
|
return self.reqData()
|
208
198
|
}).subscribe(onNext: { (items) in
|
@@ -216,7 +206,7 @@ class <##SomeViewModel##> {
|
|
216
206
|
}
|
217
207
|
|
218
208
|
extension <##SomeViewModel##> {
|
219
|
-
func reqData() -> Observable<#{
|
209
|
+
func reqData() -> Observable<#{json_data_is_arr ? "[" : ""}#{app_name}.#{httpMethod.capitalize.chomp}Model#{json_data_is_arr ? "]" : ""}> {
|
220
210
|
#{app_name}.#{httpMethod.capitalize.chomp}()
|
221
211
|
.compactMap { $0 } // 解析出需要的类型
|
222
212
|
.observeOn(MainScheduler.instance)
|
@@ -237,11 +227,6 @@ extension <##SomeViewModel##> {
|
|
237
227
|
responseJson[root_path].is_a?(Array),
|
238
228
|
readme
|
239
229
|
)
|
240
|
-
|
241
|
-
`swiftformat --swiftversion 5.0 "#{target_path + '/' + app_name}.swift",`
|
242
|
-
|
243
|
-
# puts target_swift_file = "#{target_path}/#{app_name}.swift"
|
244
|
-
|
245
230
|
end
|
246
231
|
|
247
232
|
def self.capitalize_first_letter(str)
|
data/lib/gwtools/version.rb
CHANGED