gwtools 0.0.14 → 0.0.15
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/gwtools/analysis/file_handler.rb +12 -20
- data/lib/gwtools/generate/swift.rb +78 -113
- data/lib/gwtools/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d9008f2c63bf9819bb028d56605f9f971c9f75e27865a54faae2115d8b1c384f
|
4
|
+
data.tar.gz: cd71025cf2a99576b58686ae67469de00086b571516ca574f3639f7485e5675a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a55cdc1621a3c012d7d40922078af8080ceff67b43f0f9007d08b6f21c4cd473247a071d3d776c0a45d9eafa4c9d9bf68e464734aac6135d3de0167ab00a4068
|
7
|
+
data.tar.gz: 68fd58663f5eecc0a587dcfb80cb62a287b31e51d81262fc8c210584a00aa23e05f237bc695ba1fcc4d5966877f15cfe0118ac0eea76a0c78cb21b3367a63ae1
|
@@ -37,13 +37,13 @@ module Gwtools
|
|
37
37
|
def makeDirAndFile(url)
|
38
38
|
uri = URI(url)
|
39
39
|
path = uri.path
|
40
|
-
file_name = 'restful'
|
40
|
+
# file_name = 'restful'
|
41
41
|
|
42
42
|
# remove leading '/'
|
43
43
|
path = path[1..-1] if path.start_with? '/'
|
44
44
|
|
45
45
|
# split path by '/' and create directories
|
46
|
-
dirs = path.split('/').map { |part| part.gsub(/[.-]/, "_") } + [file_name]
|
46
|
+
dirs = path.split('/').map { |part| part.gsub(/[.-]/, "_") }# + [file_name]
|
47
47
|
|
48
48
|
# puts @target_path
|
49
49
|
# puts Parser.enum_from_url(url).to_json
|
@@ -53,24 +53,16 @@ module Gwtools
|
|
53
53
|
#
|
54
54
|
FileUtils.mkdir_p(@target_path) unless File.directory?(@target_path)
|
55
55
|
Generate::Swift.createFile(@target_path, path)
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
# path,
|
67
|
-
# @url,
|
68
|
-
# @header,
|
69
|
-
# @httpMethod,
|
70
|
-
# @parameters,
|
71
|
-
# @body,
|
72
|
-
# @responseJson
|
73
|
-
# )
|
56
|
+
Generate::Swift.createPathFile(@target_path,
|
57
|
+
dirs,
|
58
|
+
@url,
|
59
|
+
path,
|
60
|
+
@header,
|
61
|
+
@httpMethod,
|
62
|
+
@parameters,
|
63
|
+
@body,
|
64
|
+
@responseJson
|
65
|
+
)
|
74
66
|
# end
|
75
67
|
end
|
76
68
|
|
@@ -7,35 +7,6 @@ require 'pp'
|
|
7
7
|
module Gwtools
|
8
8
|
class Generate
|
9
9
|
class Swift
|
10
|
-
|
11
|
-
class PathGenerateConfig
|
12
|
-
include(ERB::Util)
|
13
|
-
attr_accessor :api_name, :this_path
|
14
|
-
|
15
|
-
def config_file
|
16
|
-
# ERB.new(File.read('../lib/erb/path_url.swift.erb'), nil, '>').result(binding)
|
17
|
-
template = <<-ERB
|
18
|
-
// 此文件由代码生成,不要任何修
|
19
|
-
|
20
|
-
extension <%="#{@api_name}"%> {
|
21
|
-
// <%="#{@this_path}\n"%>
|
22
|
-
public struct <%="#{@this_path}"%> { }
|
23
|
-
}
|
24
|
-
ERB
|
25
|
-
ERB.new(template, nil, '>').result(binding)
|
26
|
-
end
|
27
|
-
|
28
|
-
def initialize(file_path, api_name, this_path)
|
29
|
-
@api_name = api_name
|
30
|
-
@this_path = this_path
|
31
|
-
|
32
|
-
File.open(file_path, 'w+') do |f|
|
33
|
-
f.puts(config_file)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
10
|
class ModelReqGenerateConfig
|
40
11
|
include(ERB::Util)
|
41
12
|
attr_accessor :api_name, :httpmethod, :prefixPath, :modulePath, :detailPath,
|
@@ -108,7 +79,7 @@ public extension <%="#{@api_name}"%> {
|
|
108
79
|
@model_data = model_data
|
109
80
|
@json_data_is_arr = json_data_is_arr
|
110
81
|
@readme = readme
|
111
|
-
|
82
|
+
puts "write to ==> #{file_path}"
|
112
83
|
File.open(file_path, 'w+') do |f|
|
113
84
|
f.puts(config_file)
|
114
85
|
end
|
@@ -143,11 +114,10 @@ public extension <%="#{@api_name}"%> {
|
|
143
114
|
|
144
115
|
def self.getDetailPath(dir_path, prefixPath, modulePath)
|
145
116
|
return dir_path.gsub(/^\/|\/$/, "").gsub(/\A#{prefixPath}/, "")
|
146
|
-
|
147
|
-
|
117
|
+
.gsub(/^\/|\/$/, "").gsub(/\A#{modulePath}/, "")
|
118
|
+
.gsub(/^\/|\/$/, "")
|
148
119
|
end
|
149
120
|
|
150
|
-
|
151
121
|
def self.createFile(target_path, url)
|
152
122
|
pre_name = 'pre_path'
|
153
123
|
target_swift_file = "#{target_path + "/#{pre_name}"}/#{url.split('/').first}.swift"
|
@@ -174,92 +144,87 @@ public extension <%="#{@api_name}"%> {
|
|
174
144
|
`swiftformat --swiftversion 5.0 #{target_swift_file}`
|
175
145
|
end
|
176
146
|
|
177
|
-
def self.createPathFile(
|
178
|
-
|
179
|
-
|
147
|
+
def self.createPathFile(target_path,
|
148
|
+
dirs,
|
149
|
+
full_url,
|
150
|
+
path,
|
180
151
|
header,
|
181
152
|
httpMethod,
|
182
153
|
parameters,
|
183
154
|
body,
|
184
155
|
responseJson)
|
185
|
-
app_name =
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
else
|
255
|
-
PathGenerateConfig.new(
|
256
|
-
"#{dir_path}.swift",
|
257
|
-
app_name,
|
258
|
-
dir
|
259
|
-
)
|
260
|
-
end
|
156
|
+
app_name = dirs.join('.')
|
157
|
+
|
158
|
+
swift_model = generate_model("#{httpMethod.capitalize.chomp}Model", responseJson, 'data')
|
159
|
+
prefixPath = getPrefixPath(path)
|
160
|
+
prefixPath = getPrefixPath(path)
|
161
|
+
|
162
|
+
return unless !prefixPath.empty?
|
163
|
+
|
164
|
+
modulePath = getModulePath(path, prefixPath)
|
165
|
+
detailPath = getDetailPath(path, prefixPath, modulePath)
|
166
|
+
|
167
|
+
readme = """
|
168
|
+
请求参数
|
169
|
+
URL = #{path.chomp}
|
170
|
+
HTTPMETHOD = #{httpMethod.chomp}
|
171
|
+
|
172
|
+
ViewModel
|
173
|
+
class <##SomeViewModel##> {
|
174
|
+
let disposeBag = DisposeBag()
|
175
|
+
|
176
|
+
public struct Input {
|
177
|
+
let <##AnyObservable##>: Observable<<##AnyObservableType##>>
|
178
|
+
}
|
179
|
+
|
180
|
+
public struct Output {
|
181
|
+
let data: BehaviorRelay<#{@json_data_is_arr ? "[" : ""}#{app_name}.#{httpMethod.capitalize.chomp}Model#{@json_data_is_arr ? "]" : ""}>
|
182
|
+
}
|
183
|
+
|
184
|
+
public func transform(input: Input) -> Output {
|
185
|
+
let outDatas = BehaviorRelay<#{@json_data_is_arr ? "[" : ""}#{app_name}.#{httpMethod.capitalize.chomp}Model#{@json_data_is_arr ? "]" : ""}>(value: [])
|
186
|
+
input.<##AnyObservable##>.flatMapLatest({ [weak self] () -> Observable<#{@json_data_is_arr ? "[" : ""}#{app_name}.#{httpMethod.capitalize.chomp}Model#{@json_data_is_arr ? "]" : ""}> in
|
187
|
+
guard let self = self else { return Observable.just([]) }
|
188
|
+
return self.reqData()
|
189
|
+
}).subscribe(onNext: { (items) in
|
190
|
+
outDatas.accept(outDatas.value + items)
|
191
|
+
}, onError: { error in
|
192
|
+
outDatas.accept([])
|
193
|
+
}).disposed(by: disposeBag)
|
194
|
+
|
195
|
+
return Output(data: outDatas)
|
196
|
+
}
|
197
|
+
}
|
198
|
+
|
199
|
+
extension <##SomeViewModel##> {
|
200
|
+
func reqData() -> Observable<#{@json_data_is_arr ? "[" : ""}#{app_name}.#{httpMethod.capitalize.chomp}Model#{@json_data_is_arr ? "]" : ""}> {
|
201
|
+
#{app_name}.#{httpMethod.capitalize.chomp}()
|
202
|
+
.compactMap { $0 } // 解析出需要的类型
|
203
|
+
.observeOn(MainScheduler.instance)
|
204
|
+
.catchErrorJustReturn([])
|
205
|
+
}
|
206
|
+
}
|
207
|
+
"""
|
208
|
+
|
209
|
+
ModelReqGenerateConfig.new(
|
210
|
+
"#{target_path + '/' + app_name}.swift",
|
211
|
+
app_name,
|
212
|
+
httpMethod.capitalize.chomp,
|
213
|
+
prefixPath,
|
214
|
+
modulePath,
|
215
|
+
detailPath,
|
216
|
+
"#{httpMethod.capitalize.chomp}Model",
|
217
|
+
swift_model,
|
218
|
+
false,
|
219
|
+
readme
|
220
|
+
)
|
221
|
+
|
222
|
+
`swiftformat --swiftversion 5.0 "#{target_path + '/' + app_name}.swift",`
|
223
|
+
|
224
|
+
# puts target_swift_file = "#{target_path}/#{app_name}.swift"
|
261
225
|
|
262
226
|
end
|
227
|
+
|
263
228
|
def self.capitalize_first_letter(str)
|
264
229
|
str[0].upcase + str[1..-1]
|
265
230
|
end
|
@@ -327,4 +292,4 @@ public extension <%="#{@api_name}"%> {
|
|
327
292
|
|
328
293
|
end
|
329
294
|
end
|
330
|
-
end
|
295
|
+
end
|
data/lib/gwtools/version.rb
CHANGED