gwtools 0.0.2 → 0.0.6

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: e30a16fee67b211db364b6405196e97cff2ad8267de76c51b2d2f738e2dc4d17
4
- data.tar.gz: 707f9f8edcf5215c8d170c9b9f35950e1953e2b2306fff15e4cfe5974ea06449
3
+ metadata.gz: 623dae2a8da9444e088fb0775b8490beb07a339d1b48e040b28be4c955fb30b1
4
+ data.tar.gz: 4488cddef5c3b1e72e992f263d38cd23e40951731cc5218aa95e1afb31fb2dd6
5
5
  SHA512:
6
- metadata.gz: bcc442197200a01b6166aa5f45c1debcc32f9858b5ab8aa7cf7e73dc226fb1bdd0b641bcf66367b990c351696b35130518376fdb9e3e322aba944641b1b55f8a
7
- data.tar.gz: da4f80305680631b2c3ccacdad38c4a8d42217ddc48fc1b5fa14309357c68df056d4d10351c5b9140887a4d0faaef4017218a8f4227c5551f0ceafa4c30265fb
6
+ metadata.gz: c52c6bffb2ff6816c726ab1c6d13fc7430e8d2e7b07c8005683a18b0da6dd7a1c3a9d8b49251234f4285067b7cb3aab92df6255e01297143ce6c942f253d2338
7
+ data.tar.gz: 46e363b7424217396fc8ca484850eea5a9b4a6a7cc7042adf8a812c4203f1943a13c843bfa16104c4931b8ce15fa579820efa2ee56b27540a9a965b3a5570b4c
@@ -32,8 +32,8 @@ module Gwtools
32
32
  # """
33
33
 
34
34
  makeDirAndFile(@url)
35
- # 生成对应Model文件
36
- Generate::Swift.createModelAndRequest(@target_path, @responseJson)
35
+ # # 生成对应Model文件
36
+ # Generate::Swift.createModelAndRequest(@target_path, @responseJson)
37
37
 
38
38
  end
39
39
 
@@ -57,7 +57,7 @@ module Gwtools
57
57
  end
58
58
 
59
59
  # create file
60
- Generate::Swift.createPathFile(dir_path, dir, dirs, index)
60
+ Generate::Swift.createPathFile(dir_path, dir, dirs, index, @httpMethod, @responseJson)
61
61
  end
62
62
  end
63
63
 
@@ -17,7 +17,7 @@ module Gwtools
17
17
  end
18
18
 
19
19
  def validate!
20
- # super TODO: 这里还没检查参数
20
+ help! 'file_path is required.' unless @file_path
21
21
  end
22
22
 
23
23
  def run
@@ -12,7 +12,16 @@ module Gwtools
12
12
  attr_accessor :api_name, :this_path
13
13
 
14
14
  def config_file
15
- ERB.new(File.read('lib/erb/path_url.swift.erb'), nil, '>').result(binding)
15
+ # ERB.new(File.read('../lib/erb/path_url.swift.erb'), nil, '>').result(binding)
16
+ template = <<-ERB
17
+ // 此文件由代码生成,不要任何修
18
+
19
+ extension <%="#{@api_name}"%> {
20
+ // <%="#{@this_path}\n"%>
21
+ public struct <%="#{@this_path}"%> { }
22
+ }
23
+ ERB
24
+ ERB.new(template, nil, '>').result(binding)
16
25
  end
17
26
 
18
27
  def initialize(file_path, api_name, this_path)
@@ -30,8 +39,49 @@ module Gwtools
30
39
  include(ERB::Util)
31
40
  attr_accessor :api_name, :httpmethod, :prefixPath, :modulePath, :detailPath, :model_name, :model_data
32
41
 
42
+ # 将 erb 文件的一个实例化,绑定到当前的一个对象的上下文
33
43
  def config_file
34
- ERB.new(File.read('lib/erb/model_req.swift.erb'), nil, '>').result(binding)
44
+ # ERB.new(File.read('restful_url.swift.erb'), nil, '>').result(binding)
45
+ template = <<-ERB
46
+ /// 此文件由代码生成,不要修改任何路径相关参数,仅可对 headerParms 和 parms 做处理
47
+
48
+ import RxSwift
49
+ import GWNetWork
50
+ import GWUserCenterBase
51
+ import SwiftyUserDefaults
52
+ import HandyJSON
53
+
54
+ public extension <%="#{@api_name}"%> {
55
+ <%="#{@model_data}\n"%>
56
+ }
57
+
58
+ public extension <%="#{@api_name}"%> {
59
+ static func <%="#{@httpmethod}"%>(/*custom_params,*/
60
+ isCache: Bool = false,
61
+ isLoading: Bool = false,
62
+ module: String? = nil,
63
+ des: String? = nil) -> Observable<Self.<%="#{@httpmethod}"%><%="#{@model_name}"%>> {
64
+ // ================= 逻辑处理 =================
65
+ let headerParms: [String : String] = [:]
66
+ let parms: [String : Any] = [:]
67
+ // ================= 逻辑处理 =================
68
+
69
+ return GWNetworkManager.request(requestType: .<%="#{@httpmethod}"%>,
70
+ prefixPath: "<%="#{@prefixPath}"%>",
71
+ modulePath: "<%="#{@modulePath}"%>",
72
+ detailPath: "<%="#{@detailPath}"%>",
73
+ parms: parms,
74
+ headerParms: headerParms,
75
+ isCache: isCache,
76
+ isLoading: isLoading,
77
+ module: module,
78
+ des: des)
79
+ .mapHandyJSON(Self.<%="#{@model_name}"%>.self)
80
+
81
+ }
82
+ }
83
+ ERB
84
+ ERB.new(template, nil, '>').result(binding)
35
85
  end
36
86
 
37
87
  def initialize(file_path, api_name, httpmethod, prefixPath, modulePath, detailPath, model_name, model_data)
@@ -49,15 +99,36 @@ module Gwtools
49
99
  end
50
100
  end
51
101
 
52
- def self.createPathFile(dir_path, dir, dirs, index)
102
+ def self.createPathFile(dir_path, dir, dirs, index, http_method, response_json)
53
103
  if index <= 0
54
104
  return
55
105
  end
56
- PathGenerateConfig.new(
57
- "#{dir_path}.swift",
58
- "AppAPI.#{dirs[0..index-1].join('.')}",
59
- dir
60
- )
106
+ if dir == 'restful'
107
+ puts dir_path
108
+ puts dir
109
+ puts dirs.join('/')
110
+ puts dirs[0..index-1].join('.')
111
+ swift_model = generate_model("Model", response_json)
112
+ ModelReqGenerateConfig.new(
113
+ "#{dir_path}.swift",
114
+ "AppAPI.#{dirs[0..index-1].join('.')}",
115
+ http_method.capitalize,
116
+ 'app-api/api/v1.0',
117
+ 'content',
118
+ '/route/getContentInfo',
119
+ 'GetModel',
120
+ swift_model
121
+ )
122
+
123
+ `swiftformat --swiftversion 5.0 #{dir_path}.swift`
124
+ else
125
+ PathGenerateConfig.new(
126
+ "#{dir_path}.swift",
127
+ "AppAPI.#{dirs[0..index-1].join('.')}",
128
+ dir
129
+ )
130
+ end
131
+
61
132
  end
62
133
 
63
134
  def self.generate_model(name, json_data)
@@ -92,10 +163,10 @@ module Gwtools
92
163
  swift_model + "}\n"
93
164
  end
94
165
 
95
- def self.createModelAndRequest(target_path, responseJson)
96
- swift_model = generate_model("Model", responseJson)
97
- File.write(target_path + 'Model.swift', swift_model)
98
- end
166
+ # def self.createModelAndRequest(target_path, responseJson)
167
+ # swift_model = generate_model("Model", responseJson)
168
+ # File.write(target_path + 'Model.swift', swift_model)
169
+ # end
99
170
 
100
171
  # 生成 Swift 模型
101
172
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gwtools
4
- VERSION = "0.0.2"
4
+ VERSION = "0.0.6"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gwtools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - chenglq