gwtools 0.0.16 → 0.0.18

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: 815b48333cc7b62c19b09a7b974d11f4da0a06af2223242df93d41e1f94a45dd
4
- data.tar.gz: d05b35e6e038c5ed00a44b167936550fede33a58bdc14d4fe9d75b080e62ad33
3
+ metadata.gz: 2d38d7819049120197657aaada9c96d48c0aec7519c35939e5fa5626a1835159
4
+ data.tar.gz: bc0c358a7491f712175631dd210aca21cc55fb3385428df4e6064d22297b74ba
5
5
  SHA512:
6
- metadata.gz: d4c9a8f1ba05cf7a3003f4c6c00d599a978f761953350423baab24b364b0e5c82ab9902fe37297b1a65a0f7983267d6195702b3413917e176758d22c47d4a823
7
- data.tar.gz: b519de2f870e800d5a33444e0579bc2a40bfe29536fcdc4bee4b68b41c5c9a86d61e568e6743dcb169ff675d576ba5f581057adbc621bf5f3d0c061ea97e38cf
6
+ metadata.gz: be161ff8c7e2f6e7912fd128894b238f396fe89e405889bb043bf316bc4831be2d99d5caa367f875d23bef8f2a31413a3e94ed3e1895a71f003bc65a655045ac
7
+ data.tar.gz: '069e6744aff50f322c59396abeacb7425938f7e2d80dfdf1bdc339c52570bc83f6b5d23381dd59052d57e7e072201dc7300e4daf84d3ce04917db1a6b3efe04e'
@@ -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,27 +62,8 @@ module Gwtools
63
62
  @body,
64
63
  @responseJson
65
64
  )
66
- # end
67
65
  end
68
66
 
69
- # def createSwiftFile(dir_path)
70
- # File.open("#{dir_path}.swift", "w") do |file|
71
- # # write swift file content
72
- # if index == 0
73
- # file.write("extension AppAPI { \n")
74
- # else
75
- # file.write("extension AppAPI.#{dirs[0..index-1].join('.')} { \n")
76
- # end
77
- # file.write(" public struct #{dir} { } \n")
78
- # file.write("}")
79
- # end
80
- #
81
- #
82
- # # File.open("#{dir_path}.swift", "w") do |file|
83
- # #
84
- # # end
85
- # end
86
-
87
67
  def getURL
88
68
  match = /^URL = (.*)$/.match(@data_str)
89
69
  if match
@@ -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")
@@ -96,7 +114,7 @@ module Gwtools
96
114
 
97
115
  def self.extract_enum_name(content)
98
116
  # return content.scan(/^\w+\s+extension\s+(\w+)\s+\{/).flatten + content.scan(/^\w+\s+enum\s+(\w+)\s+\{/).flatten
99
- return (content.scan(/enum\s+(\w+)\s+\{/).flatten + content.scan(/extension\s+(\w+)\s+\{/).flatten).first
117
+ return (content.scan(/enum\s+([\w.]+)\s+\{/).flatten + content.scan(/extension\s+([\w.]+)\s+\{/).flatten).first
100
118
  end
101
119
 
102
120
  # 根据括号匹配enums内容
@@ -127,6 +145,7 @@ module Gwtools
127
145
  end
128
146
 
129
147
  def self.extract_enum(content, parent_enum = nil)
148
+ content.gsub!('`','')
130
149
  level = parent_enum.nil? ? 0 : parent_enum.level
131
150
  pre_name = parent_enum.nil? ? '' : "#{parent_enum.path}."
132
151
  enum_codes = extract_enums_content(content)
@@ -200,7 +219,7 @@ module Gwtools
200
219
  content_str += value.to_swift()
201
220
  end
202
221
  content_str += "}\n"
203
- return content_str
222
+ return Parser.output_content(content_str)
204
223
  end
205
224
 
206
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
@@ -64,6 +64,8 @@ public extension <%="#{@api_name}"%> {
64
64
  <% end %>
65
65
  }
66
66
  }
67
+
68
+
67
69
  ERB
68
70
  ERB.new(template, nil, '>').result(binding)
69
71
  end
@@ -81,8 +83,17 @@ public extension <%="#{@api_name}"%> {
81
83
  @readme = readme
82
84
  puts "write to ==> #{file_path}"
83
85
  File.open(file_path, 'w+') do |f|
86
+ # f.puts(Parser.output_content(config_file))
84
87
  f.puts(config_file)
85
88
  end
89
+
90
+ # 格式化
91
+ `swiftformat --swiftversion 5.0 #{file_path}`
92
+ # 替换内容,重新写入
93
+ replaced_content = File.read(file_path)
94
+ File.open(file_path, "w") do |new_file|
95
+ new_file.puts(Parser.output_content(replaced_content))
96
+ end
86
97
  end
87
98
  end
88
99
 
@@ -100,7 +111,7 @@ public extension <%="#{@api_name}"%> {
100
111
  end
101
112
 
102
113
  def self.getModulePath(dir_path, prefixPath)
103
- modulePaths = %w[content community]
114
+ modulePaths = %w[content community complaintsComments technician]
104
115
  dir_path = dir_path.gsub(/\A#{prefixPath}/, "").gsub(/^\/|\/$/, "")
105
116
 
106
117
  modulePaths.each do |modulePath|
@@ -204,6 +215,8 @@ extension <##SomeViewModel##> {
204
215
  .catchErrorJustReturn([])
205
216
  }
206
217
  }
218
+
219
+ public extension app_api.api.v1_0.complaintsComments.protocol.getProtocols {}
207
220
  """
208
221
 
209
222
  ModelReqGenerateConfig.new(
@@ -218,11 +231,6 @@ extension <##SomeViewModel##> {
218
231
  responseJson[root_path].is_a?(Array),
219
232
  readme
220
233
  )
221
-
222
- `swiftformat --swiftversion 5.0 "#{target_path + '/' + app_name}.swift",`
223
-
224
- # puts target_swift_file = "#{target_path}/#{app_name}.swift"
225
-
226
234
  end
227
235
 
228
236
  def self.capitalize_first_letter(str)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gwtools
4
- VERSION = "0.0.16"
4
+ VERSION = "0.0.18"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gwtools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.16
4
+ version: 0.0.18
5
5
  platform: ruby
6
6
  authors:
7
7
  - chenglq
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-07 00:00:00.000000000 Z
11
+ date: 2023-02-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Write a longer description or delete this line.
14
14
  email: