lhj-tools 0.1.75 → 0.1.76

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: 7dc72ca4edb2bdcb5abd9ced2b89e97843bbd4393527e28be7b0c750d3f00be7
4
- data.tar.gz: 88b0b3444ba3c78ce03bb2bdcb32eef0fa77ea23eec27f41225ea1a7df9a6aa1
3
+ metadata.gz: 3573173cffbb9453ae8e205034e2c28e9d7f4bde8600574cb42787f671716f91
4
+ data.tar.gz: ec7333d4b1078c07846ea533fade87a44ae18cfcbeab5311a078671af14d9904
5
5
  SHA512:
6
- metadata.gz: 27eb16b78e42d2ea284b68cf6678949367a489a15e9fb6961b8b0d3debe74e30daa76f96079416a7f00530c72c183b1ef842882e04bfb4ecbe4a1a974ba1e37a
7
- data.tar.gz: 6426a55e2043d21cfcd35d49b05400db2485e6433982d98348db95ef98f3d6bbce210a020d509cc9a1efe1a7fdf843be857279bc0dc72f0e8eaba490a9772304
6
+ metadata.gz: 387b4adaaad5aa277799f85de8a2de6d898adaafee296c33e406b4c6818ef2a14651a4c191eadff85839880357a7a83b6b95cbb7c9827d38d392782303743209
7
+ data.tar.gz: 0aae4e701adb0b50446bad22b80bb23cc4eb7b55a920514d0f53b7f9a618de781b95fd61b7669d245a88337f3ba18298e72740e0a1b81c924686ef651c663f96
@@ -21,7 +21,9 @@ module Lhj
21
21
  %w[--id api的id],
22
22
  %w[--model-pre 模型的前缀],
23
23
  %w[--model-name 模型的名称],
24
- %w[--save 保存生成文件]
24
+ %w[--save 保存生成文件],
25
+ %w[--sync 同步到github],
26
+ %w[--notify 通知到钉钉]
25
27
  ]
26
28
  end
27
29
 
@@ -40,9 +42,8 @@ module Lhj
40
42
  @config_id = ''
41
43
  @config_model_pre = 'ML'
42
44
  @config_model_name = 'Result'
43
- @model_default_suffix = 'Model'
45
+ @config_base_url = 'http://yapi.xx.com'
44
46
  @type_trans = {}
45
- @base_url = 'http://yapi.xx.com'
46
47
  super
47
48
  end
48
49
 
@@ -63,13 +64,13 @@ module Lhj
63
64
  project_id = res_body['data']['project_id']
64
65
  project_info = get_project_info(project_id)
65
66
  # 1.print request result
66
- result_model_name = print_res_body_model(res_body)
67
+ print_res_body_model(res_body)
67
68
  # 2.print request json body
68
- param_model_name = print_req_body_model(res_body)
69
+ print_req_body_model(res_body) if res_body['data']['req_body_is_json_schema']
69
70
  # 3.print request param
70
- print_req_query(res_body['data'])
71
+ print_req_query(res_body['data']) unless res_body['data']['req_body_is_json_schema']
71
72
  # 4.print request method
72
- service_code = print_http_method(res_body['data'], project_info, result_model_name, param_model_name)
73
+ service_code = print_http_method(res_body['data'], project_info)
73
74
  # 5.save to file
74
75
  file_map = save_to_file(service_code) if @save
75
76
  # 6.push to git
@@ -107,17 +108,19 @@ module Lhj
107
108
  def save_to_file(service_code)
108
109
  name = model_name
109
110
  file_name = gen_model_name
110
- unless File.exist?(File.expand_path(sub_folder_name, '.'))
111
- FileUtils.mkdir_p(File.expand_path(sub_folder_name, '.'))
112
- end
111
+ FileUtils.mkdir_p(File.expand_path(sub_folder_name, '.')) unless File.exist?(File.expand_path(sub_folder_name, '.'))
113
112
  h_file = File.join('.', sub_folder_name, "#{file_name}.h")
114
113
  m_file = File.join('.', sub_folder_name, "#{file_name}.m")
115
114
  service_file = File.join('.', sub_folder_name, "#{model_pre}#{name}Service.m")
116
115
  File.write(h_file, @h_file_array.join("\n")) if @h_file_array.count.positive?
117
116
  File.write(m_file, @m_file_array.join("\n")) if @m_file_array.count.positive?
118
117
  File.write(service_file, service_code) if service_code
119
- puts "\n\n生成文件成功!所在路径:\n#{File.expand_path(h_file)} \n#{File.expand_path(m_file)}".green
120
- { h_file: h_file, m_file: m_file, s_file: service_file }
118
+ puts "\n\n生成文件成功!所在路径:\n#{File.expand_path(h_file)} \n#{File.expand_path(m_file)}".green if @save && !@notify
119
+ {
120
+ h_file: "#{sub_folder_name}/#{file_name}.h",
121
+ m_file: "#{sub_folder_name}/#{file_name}.m",
122
+ s_file: "#{sub_folder_name}/#{model_pre}#{name}Service.m"
123
+ }
121
124
  end
122
125
 
123
126
  def push_to_git
@@ -127,23 +130,27 @@ module Lhj
127
130
  Actions.sh('git push')
128
131
  end
129
132
 
130
- def notify_robot(file_info, interface_info, project_info)
131
- temp_vars = file_info.merge({
132
- api_id: api_id,
133
- interface_url: "#{project_info['data']['basepath']}#{interface_info['data']['path']}"
134
- })
135
- robot_url = 'https://oapi.dingtalk.com/robot/send?access_token=fe879fd3e7a3b5e59d5719b2384845b7884901919be5a78fe443cbf777869807'
133
+ def notify_robot(upload_info, interface_info, project_info)
134
+ i_url = "#{project_info['data']['basepath']}#{interface_info['data']['path']}"
135
+ username = interface_info['data']['username']
136
+ title = interface_info['data']['title']
137
+ temp_vars = upload_info.merge({
138
+ api_id: api_id,
139
+ title: title,
140
+ username: username,
141
+ interface_url: i_url
142
+ })
136
143
  template = Lhj::ErbTemplateHelper.load('oc_code_notify')
137
144
  output = Lhj::ErbTemplateHelper.render(template, temp_vars, '-')
138
- Lhj::Dingtalk.post_message_robot(robot_url, '生成代码', output)
145
+ Lhj::Dingtalk.post_message_robot(robot_url, 'yapi generate', output)
139
146
  end
140
147
 
141
148
  def interface_url_str
142
- "#{@base_url}/#{API_INTERFACE_URL}#{api_id}"
149
+ "#{@config_base_url}/#{API_INTERFACE_URL}#{api_id}"
143
150
  end
144
151
 
145
152
  def project_url_str(project_id)
146
- "#{@base_url}/#{API_PROJECT_URL}#{project_id}"
153
+ "#{@config_base_url}/#{API_PROJECT_URL}#{project_id}"
147
154
  end
148
155
 
149
156
  def yml_file
@@ -155,11 +162,12 @@ module Lhj
155
162
  config.each do |k, v|
156
163
  @http_headers << "#{k}=#{v}" if k.eql?('__wpkreporterwid_') || k.eql?('_yapi_token') || k.eql?('_yapi_uid')
157
164
  end
158
- @base_url = config['base_url']
165
+ @config_base_url = config['base_url']
159
166
  @config_id = config['id']
160
167
  @config_model_pre = config['model_pre']
161
168
  @config_model_suffix = config['model_suffix']
162
169
  @config_model_name = config['model_name']
170
+ @config_robot_url = config['dingtalk']
163
171
  @type_trans = config['type_trans']
164
172
  end
165
173
 
@@ -176,11 +184,15 @@ module Lhj
176
184
  end
177
185
 
178
186
  def req_model_name
179
- 'Param'
187
+ 'RequestParam'
180
188
  end
181
189
 
182
190
  def model_suffix
183
- @config_model_suffix || @model_default_suffix
191
+ @config_model_suffix || 'Model'
192
+ end
193
+
194
+ def robot_url
195
+ @config_robot_url || 'https://oapi.dingtalk.com/robot/send?access_token=fe879fd3e7a3b5e59d5719b2384845b7884901919be5a78fe443cbf777869807'
184
196
  end
185
197
 
186
198
  def get_interface_api_model
@@ -224,7 +236,6 @@ module Lhj
224
236
  print_models_for_java(models)
225
237
  end
226
238
  puts "\n<===============打印返回数据模型-End=====================>\n".green
227
- models.last[:name]
228
239
  end
229
240
 
230
241
  def print_req_body_model(res_json)
@@ -244,16 +255,16 @@ module Lhj
244
255
  print_models_for_java(models)
245
256
  end
246
257
  puts "\n<===============打印请求模型-End=====================>\n".green
247
- models.last[:name]
248
258
  end
249
259
 
250
260
  def fetch_res_boy(res_json)
251
261
  return if !res_json || !res_json['data'] || !res_json['data']['res_body']
252
262
 
253
263
  res_body = JSON.parse(res_json['data']['res_body'])
254
- return if !res_body['properties'] || !res_body['properties']['detailMsg']
255
264
 
256
- result = res_body['properties']['detailMsg']
265
+ result = res_body
266
+ result = res_body['properties']['detailMsg'] if res_body['properties'] && res_body['properties']['detailMsg']
267
+
257
268
  return unless result['type'] == 'object' || result['type'] == 'array'
258
269
 
259
270
  result['name'] = gen_model_name
@@ -270,12 +281,15 @@ module Lhj
270
281
 
271
282
  def gen_model_name(property_name = nil, type = :res)
272
283
  name = model_name
273
- name = req_model_name if type == :req
274
284
  unless property_name.nil?
275
285
  name = property_name.gsub(/vo|model|list/i, '').gsub(/(.*)s$/, '\1').gsub(/^\w/) { Regexp.last_match(0).upcase }
276
286
  name = property_name.gsub(/^\w/) { Regexp.last_match(0).upcase } if name.length <= 0
277
287
  end
278
- "#{model_pre}#{name}#{model_suffix}"
288
+ if type == :req
289
+ "#{model_pre}#{name}#{req_model_name}"
290
+ else
291
+ "#{model_pre}#{name}#{model_suffix}"
292
+ end
279
293
  end
280
294
 
281
295
  def handle_model(model, &block)
@@ -414,7 +428,8 @@ module Lhj
414
428
 
415
429
  case @language
416
430
  when 'oc'
417
- puts_h '@interface MLParamModel : NSObject'
431
+ param_model_name = gen_model_name(nil, :req)
432
+ puts_h "@interface #{param_model_name} : NSObject"
418
433
  data['req_query'].each do |h|
419
434
  des = h['desc']
420
435
  puts_h "///#{des} #{h['example']}"
@@ -426,14 +441,23 @@ module Lhj
426
441
  end
427
442
  end
428
443
 
429
- def print_http_method(data, project_info, result_model_name, param_model_name)
444
+ def print_http_method(data, project_info)
430
445
  return unless data
431
446
 
432
447
  path = data['path']
433
448
  if path
434
- path_name = path.split('/').map { |s| s.gsub(/[^A-Za-z0-9]/, '').gsub(/^\w/) { Regexp.last_match(0).upcase } }.join('')
449
+ arr = path.split('/').map do |s|
450
+ re = s.gsub(/[^A-Za-z0-9](.)/) { Regexp.last_match(0).upcase }
451
+ re = re.gsub(/[^A-Za-z0-9]/, '')
452
+ re.gsub(/^\w/) { Regexp.last_match(0).upcase }
453
+ end
454
+ path_name = arr.join('')
435
455
  end
436
456
  path_key = "k#{path_name}URL"
457
+ display_path = "#{project_info['data']['basepath']}#{path}"
458
+ display_path = display_path[1..-1] if display_path.index('/') == 0
459
+ result_model_name = gen_model_name
460
+ param_model_name = gen_model_name(nil, :req)
437
461
  mth = data['method']
438
462
  mth = 'JSON' if data['req_body_is_json_schema']
439
463
  case @language
@@ -446,11 +470,11 @@ module Lhj
446
470
  yapi_vars = { title: data['title'],
447
471
  desc: data['desc'],
448
472
  username: data['username'],
449
- path: "#{project_info['data']['basepath']}#{path}",
473
+ path: display_path,
450
474
  path_key: path_key,
451
475
  path_name: path_name,
452
476
  result_model_name: result_model_name,
453
- param_model_name: param_model_name || 'MLParamModel',
477
+ param_model_name: param_model_name,
454
478
  mth: mth,
455
479
  model_template: model_temp_result }
456
480
  yapi_temp_result = Lhj::ErbTemplateHelper.render(yapi_temp, yapi_vars, '-')
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lhj
4
4
  module Tools
5
- VERSION = "0.1.75"
5
+ VERSION = "0.1.76"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lhj-tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.75
4
+ version: 0.1.76
5
5
  platform: ruby
6
6
  authors:
7
7
  - lihaijian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-11 00:00:00.000000000 Z
11
+ date: 2022-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xcodeproj