lhj-tools 0.1.7 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/lhj/command/config/info.rb +22 -2
- data/lib/lhj/command/init.rb +38 -14
- data/lib/lhj/command/sync_pod_repo.rb +37 -22
- data/lib/lhj/command/yapi/formatters/base.rb +15 -0
- data/lib/lhj/command/yapi/formatters/command_context.rb +23 -0
- data/lib/lhj/command/yapi/formatters/service.rb +23 -0
- data/lib/lhj/command/yapi/formatters/template/model.erb +10 -0
- data/lib/lhj/command/yapi/formatters/template/yapi.erb +28 -0
- data/lib/lhj/command/yapi.rb +127 -90
- data/lib/lhj/command.rb +7 -3
- data/lib/lhj/tools/version.rb +1 -1
- metadata +11 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e51282e5a210a73525c73ce6c187cb89c7e1974383ab85d3f819a2d879b04ba1
|
4
|
+
data.tar.gz: b9e415c288460cfa16735e64feae9202d347a54070caf581ae4a3c7099de6f6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a9a85100ae545826bd9cc332bd592e1f45e5958f58a4e24527b162da5f446d95d56a54cfa067a05aa05ef20254519f23cb2d15e287f5bc7a63e80792f52b8ed
|
7
|
+
data.tar.gz: 5ed2fb7fbc378ac89c21ac61588d5372c8006a39428a4aa09ed46c2284ab4bd61d72d5589f5f674279629e2d0d75effc2931850ed17398a1ff236c08715f0231
|
@@ -27,9 +27,29 @@ module Lhj
|
|
27
27
|
|
28
28
|
def show_yaml(file)
|
29
29
|
table_rows = []
|
30
|
-
|
31
|
-
|
30
|
+
content = YAML.load_file(file)
|
31
|
+
|
32
|
+
case content
|
33
|
+
when Array
|
34
|
+
content.each do |row|
|
35
|
+
next unless row.is_a?(Hash)
|
36
|
+
|
37
|
+
row.each do |key, value|
|
38
|
+
table_rows << [key, value]
|
39
|
+
end
|
40
|
+
table_rows << :separator
|
41
|
+
end
|
42
|
+
when Hash
|
43
|
+
content.each do |key, value|
|
44
|
+
table_rows << [key, value]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
32
48
|
title = File.basename(file).to_s
|
49
|
+
print_table(title, table_rows) if table_rows.count.positive?
|
50
|
+
end
|
51
|
+
|
52
|
+
def print_table(title, table_rows)
|
33
53
|
table = Terminal::Table.new title: title, headings: %w[键 值], rows: table_rows
|
34
54
|
puts table
|
35
55
|
end
|
data/lib/lhj/command/init.rb
CHANGED
@@ -9,18 +9,34 @@ module Lhj
|
|
9
9
|
# sync config
|
10
10
|
class Init < Command
|
11
11
|
self.summary = '初始化控件'
|
12
|
-
self.description = '使用工具前先执行`lhj init`'
|
12
|
+
self.description = '使用工具前先执行`lhj init --url=http://xxx`'
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
self.arguments = [
|
15
|
+
CLAide::Argument.new('url', true)
|
16
|
+
]
|
17
|
+
|
18
|
+
def self.options
|
19
|
+
[
|
20
|
+
%w[--url 配置文件的url]
|
21
|
+
]
|
17
22
|
end
|
18
23
|
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
+
def validate!
|
25
|
+
super
|
26
|
+
help! '配置url必须输入' unless @url
|
27
|
+
end
|
28
|
+
|
29
|
+
def initialize(argv)
|
30
|
+
@url = argv.option('url')
|
31
|
+
super
|
32
|
+
end
|
33
|
+
|
34
|
+
def handle
|
35
|
+
FileUtils.mkdir_p(target_folder) unless File.exist?(target_folder)
|
36
|
+
file_path = file_name_from_url(@url)
|
37
|
+
save_url_to_file(@url, file_path)
|
38
|
+
content = YAML.load_file(file_path)
|
39
|
+
download_file(content) if content.is_a?(Array)
|
24
40
|
end
|
25
41
|
|
26
42
|
def target_folder
|
@@ -39,14 +55,22 @@ module Lhj
|
|
39
55
|
url.scan(%r{/([^/]+)}).flatten.last
|
40
56
|
end
|
41
57
|
|
42
|
-
def download_file
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
save_file(url, file_path) unless File.exist?(file_path)
|
58
|
+
def download_file(urls)
|
59
|
+
urls.each do |url|
|
60
|
+
file_path = file_name_from_url(url)
|
61
|
+
save_url_to_file(url, file_path)
|
47
62
|
end
|
48
63
|
puts "工具初始化完成 \n"
|
49
64
|
end
|
65
|
+
|
66
|
+
def save_url_to_file(url, file_path)
|
67
|
+
save_file(url, file_path) unless File.exist?(file_path)
|
68
|
+
end
|
69
|
+
|
70
|
+
def file_name_from_url(url)
|
71
|
+
file_name = file_name_with_url(url)
|
72
|
+
File.join(target_folder, file_name)
|
73
|
+
end
|
50
74
|
end
|
51
75
|
end
|
52
76
|
end
|
@@ -12,6 +12,10 @@ module Lhj
|
|
12
12
|
super
|
13
13
|
end
|
14
14
|
|
15
|
+
def begin_title
|
16
|
+
'读取映射文件~/.lhj/pod_config.yml'
|
17
|
+
end
|
18
|
+
|
15
19
|
def handle
|
16
20
|
sync
|
17
21
|
end
|
@@ -29,20 +33,20 @@ module Lhj
|
|
29
33
|
|
30
34
|
ma = nil
|
31
35
|
Dir.chdir(dest) do
|
32
|
-
Dir.glob(
|
36
|
+
Dir.glob('*.podspec').each do |p|
|
33
37
|
update_podspec_version(p)
|
34
38
|
version_line = IO.readlines(p).find{ |line| (/\.version/ =~ line) && (version_regex =~ line) }
|
35
39
|
ma = version_line.match(version_regex)
|
36
40
|
end
|
37
41
|
puts '2.更新版本号成功'.green
|
38
42
|
|
39
|
-
Actions.sh(
|
43
|
+
Actions.sh('git add .')
|
40
44
|
puts '3.git add成功'.green
|
41
45
|
|
42
|
-
Actions.sh("git commit -m '
|
46
|
+
Actions.sh("git commit -m '使用工具同步主工程代码'")
|
43
47
|
puts '4.git 提交成功'.green
|
44
48
|
|
45
|
-
Actions.sh(
|
49
|
+
Actions.sh('git push')
|
46
50
|
puts '5.git 推送成功'.green
|
47
51
|
|
48
52
|
add_tag(ma[0]) if ma
|
@@ -56,15 +60,27 @@ module Lhj
|
|
56
60
|
|
57
61
|
end
|
58
62
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
+
# find src root dir
|
64
|
+
src_root_dir = find_src_root_dir(src)
|
65
|
+
Dir.chdir(src_root_dir) do
|
66
|
+
if ma
|
67
|
+
pod_version = ma[0]
|
68
|
+
update_all_pod_dependency(pod_name, pod_version)
|
69
|
+
puts '9.更新主工程引用pod版本号成功'.green
|
70
|
+
end
|
63
71
|
end
|
64
72
|
|
65
73
|
puts '10.手动执行`pod update --verbose --no-repo-update`更新pod'.green
|
66
74
|
end
|
67
75
|
|
76
|
+
def find_src_root_dir(src)
|
77
|
+
ps = []
|
78
|
+
src.scan(%r{(/[^/]*)}).flatten.each do |path|
|
79
|
+
path =~ /Code/ ? break : ps << path
|
80
|
+
end
|
81
|
+
File.join(ps)
|
82
|
+
end
|
83
|
+
|
68
84
|
def version_regex
|
69
85
|
/\d+\.\d+\.(\d+)/
|
70
86
|
end
|
@@ -88,13 +104,11 @@ module Lhj
|
|
88
104
|
cmd = ['git tag']
|
89
105
|
cmd << '--force'
|
90
106
|
cmd << tag
|
91
|
-
UI.message("Adding git tag '#{tag}' 🎯.")
|
92
107
|
Actions.sh(cmd.join(' '))
|
93
108
|
end
|
94
109
|
|
95
110
|
def push_tag
|
96
111
|
cmd = ['git push --tags']
|
97
|
-
UI.message("git push --tags 🎯.")
|
98
112
|
Actions.sh(cmd.join(' '))
|
99
113
|
end
|
100
114
|
|
@@ -103,27 +117,28 @@ module Lhj
|
|
103
117
|
cmd = ['pod repo push']
|
104
118
|
pod_repo_name = 'miguatech-aomi_ios-mlspecs'
|
105
119
|
cmd << pod_repo_name
|
106
|
-
cmd <<
|
120
|
+
cmd << '*.podspec'
|
107
121
|
cmd << "--sources=#{pod_repo_name},aliyun,trunk"
|
108
|
-
cmd <<
|
109
|
-
cmd <<
|
110
|
-
cmd <<
|
122
|
+
cmd << '--allow-warnings'
|
123
|
+
cmd << '--use-libraries'
|
124
|
+
cmd << '--verbose'
|
111
125
|
Actions.sh(cmd.join(' '), log: true, error_callback: nil)
|
112
126
|
end
|
113
127
|
|
114
128
|
def update_all_pod_dependency(pod_name, pod_version)
|
115
|
-
Dir.glob([
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
end
|
129
|
+
Dir.glob(%w[./**/*.podspec ./**/Podfile]).each do |p|
|
130
|
+
next if /Example/ =~ p || /temp/ =~ p
|
131
|
+
|
132
|
+
update_main_version(p, pod_name, pod_version)
|
120
133
|
end
|
121
134
|
end
|
122
135
|
|
123
|
-
def
|
136
|
+
def update_main_version(file, pod_name, pod_version)
|
124
137
|
cont = ''
|
125
|
-
File.readlines(
|
138
|
+
File.readlines(file).each do |l|
|
126
139
|
if (/#{pod_name}/ =~ l) && (/\d+\.\d+\.\d+/ =~ l)
|
140
|
+
path = File.absolute_path(file)
|
141
|
+
puts "更新文件:#{path}".magenta
|
127
142
|
l.scan(/\d+\.\d+\.\d+/).each do |key|
|
128
143
|
cont += l.gsub(key, pod_version)
|
129
144
|
end
|
@@ -131,7 +146,7 @@ module Lhj
|
|
131
146
|
cont += l.dup
|
132
147
|
end
|
133
148
|
end
|
134
|
-
File.write(
|
149
|
+
File.write(file, cont)
|
135
150
|
end
|
136
151
|
end
|
137
152
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Lhj
|
4
|
+
module ErbFormatter
|
5
|
+
# context
|
6
|
+
class Context
|
7
|
+
def initialize(target)
|
8
|
+
@target = target
|
9
|
+
end
|
10
|
+
|
11
|
+
def fetch_binding
|
12
|
+
@target.instance_eval { binding }.tap do |bind|
|
13
|
+
decorate_binding(bind)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# 空方法
|
18
|
+
def decorate_binding(bind)
|
19
|
+
bind.eval('save = 1')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require_relative 'base'
|
3
|
+
require_relative 'command_context'
|
4
|
+
|
5
|
+
module Lhj
|
6
|
+
module ErbFormatter
|
7
|
+
# service
|
8
|
+
class Service < Base
|
9
|
+
# @param [String] name
|
10
|
+
def render(name = 'yapi')
|
11
|
+
template(name).result(Context.new(@runner).fetch_binding)
|
12
|
+
end
|
13
|
+
|
14
|
+
def template(name)
|
15
|
+
if RUBY_VERSION < '2.6'
|
16
|
+
ERB.new(File.read(File.join(File.dirname(__FILE__), 'template', "#{name}.erb")), nil, '-')
|
17
|
+
else
|
18
|
+
ERB.new(File.read(File.join(File.dirname(__FILE__), 'template', "#{name}.erb")), trim_mode: '-')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<% if @result_model_name %>
|
2
|
+
if (responseMessage.resultCode == 0 && responseMessage.error == nil) {
|
3
|
+
if ([responseMessage.detailMsg isKindOfClass:[NSDictionary class]]) {
|
4
|
+
<%= @result_model_name %> *info = <%= @result_model_name %> yy_modelWithDictionary:responseMessage.detailMsg];
|
5
|
+
callback(info,responseMessage);
|
6
|
+
}
|
7
|
+
} else {
|
8
|
+
callback(nil,responseMessage);
|
9
|
+
}
|
10
|
+
<% end %>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
/**
|
2
|
+
* <%= @title %> -- <%= @username %>
|
3
|
+
* <%= @desc %>
|
4
|
+
*/
|
5
|
+
static NSString * const <%= @path_key %> = @"<%= @path %>";
|
6
|
+
|
7
|
+
<% if @method == 'GET' -%>
|
8
|
+
+(void)get<%= @path_name %>:(<%= @param_model_name %> *)param callback:(void (^)(<%= @result_model_name %> *model, MLResponseMessage *response))callback
|
9
|
+
{
|
10
|
+
[MLNetworkingManager getWithUrl:<%= @path_key %> params:params response:^(MLResponseMessage *responseMessage) {
|
11
|
+
<%= @model_template %>
|
12
|
+
}];
|
13
|
+
}
|
14
|
+
<% elsif @method == 'JSON' -%>
|
15
|
+
+(void)postJson<%= @path_name %>:(<%= @param_model_name %> *)param callback:(void (^)(<%= @result_model_name %> *model, MLResponseMessage *response))callback
|
16
|
+
{
|
17
|
+
[MLNetworkingManager requestJsonWithUrl:<%= @path_key %> httpMedth:kRequestMethodPOST params:param response:^(MLResponseMessage *responseMessage) {
|
18
|
+
<%= @model_template %>
|
19
|
+
}];
|
20
|
+
}
|
21
|
+
<% else -%>
|
22
|
+
+(void)postJson<%= @path_name %>:(<%= @param_model_name %> *)param callback:(void (^)(<%= @result_model_name %> *model, MLResponseMessage *response))callback
|
23
|
+
{
|
24
|
+
[MLNetworkingManager postWithUrl:<%= @path_key %> params:params response:^(MLResponseMessage *response) {
|
25
|
+
<%= @model_template %>
|
26
|
+
}];
|
27
|
+
}
|
28
|
+
<% end -%>
|
data/lib/lhj/command/yapi.rb
CHANGED
@@ -2,6 +2,7 @@ require 'net/https'
|
|
2
2
|
require 'uri'
|
3
3
|
require 'json'
|
4
4
|
require 'yaml'
|
5
|
+
require 'lhj/command/yapi/formatters/service'
|
5
6
|
|
6
7
|
module Lhj
|
7
8
|
class Command
|
@@ -22,23 +23,53 @@ module Lhj
|
|
22
23
|
@id = argv.option('id')
|
23
24
|
@model_pre_name = argv.option('model-pre')
|
24
25
|
@save = argv.flag?('save', false)
|
26
|
+
@debug = argv.flag?('debug', false)
|
25
27
|
@http_url = ''
|
26
28
|
@http_headers = []
|
27
|
-
@data_json = {}
|
28
|
-
@models = []
|
29
29
|
@config_id = ''
|
30
30
|
@config_model_pre = 'ML'
|
31
31
|
@model_default_suffix = 'Model'
|
32
32
|
@type_trans = {}
|
33
33
|
@config_model_names = []
|
34
34
|
@model_names = []
|
35
|
+
# <<<===== model for template
|
36
|
+
@result_model_name = ''
|
37
|
+
@param_model_name = ''
|
38
|
+
@model_template = ''
|
39
|
+
@desc = ''
|
40
|
+
@path = ''
|
41
|
+
@path_name = ''
|
42
|
+
@path_key = ''
|
43
|
+
@method = 'GET'
|
44
|
+
@title = ''
|
45
|
+
@username = ''
|
46
|
+
@req_body_is_json_schema = false
|
47
|
+
# =====>>>
|
35
48
|
super
|
36
49
|
end
|
37
50
|
|
51
|
+
def begin_title
|
52
|
+
'读取配置文件~/.lhj/yapi.yml'
|
53
|
+
end
|
54
|
+
|
38
55
|
def handle
|
39
|
-
|
40
|
-
|
41
|
-
|
56
|
+
process(yml_file) if File.exist?(yml_file)
|
57
|
+
end
|
58
|
+
|
59
|
+
def process(config_file)
|
60
|
+
load_config(config_file)
|
61
|
+
res_body = req_api_model
|
62
|
+
return unless res_body && res_body['errcode'].to_i.zero? && !res_body.empty?
|
63
|
+
|
64
|
+
# 1.print request result
|
65
|
+
print_res_body_model(res_body)
|
66
|
+
# 2.print request json body
|
67
|
+
print_req_body_model(res_body)
|
68
|
+
# 3.print request param
|
69
|
+
print_req_query(res_body['data'])
|
70
|
+
# 4.print request method
|
71
|
+
print_http_method(res_body['data'])
|
72
|
+
# 5.save to file
|
42
73
|
save_to_file if @save
|
43
74
|
end
|
44
75
|
|
@@ -55,6 +86,12 @@ module Lhj
|
|
55
86
|
@h_file_array << str
|
56
87
|
end
|
57
88
|
|
89
|
+
def puts_h_red(str)
|
90
|
+
puts str.red
|
91
|
+
@h_file_array ||= []
|
92
|
+
@h_file_array << str
|
93
|
+
end
|
94
|
+
|
58
95
|
def puts_m(str)
|
59
96
|
puts str.blue
|
60
97
|
@m_file_array ||= []
|
@@ -75,9 +112,12 @@ module Lhj
|
|
75
112
|
"#{@http_url}#{api_id}"
|
76
113
|
end
|
77
114
|
|
78
|
-
def
|
79
|
-
|
80
|
-
|
115
|
+
def yml_file
|
116
|
+
File.join(Lhj::Config.instance.home_dir, 'yapi.yml')
|
117
|
+
end
|
118
|
+
|
119
|
+
def load_config(file)
|
120
|
+
config = YAML.load_file(file)
|
81
121
|
config.each do |k, v|
|
82
122
|
@http_headers << "#{k}=#{v}" if k.eql?('__wpkreporterwid_') || k.eql?('_yapi_token') || k.eql?('_yapi_uid')
|
83
123
|
end
|
@@ -101,79 +141,81 @@ module Lhj
|
|
101
141
|
@config_model_suffix || @model_default_suffix
|
102
142
|
end
|
103
143
|
|
104
|
-
def
|
144
|
+
def req_api_model
|
105
145
|
uri = URI.parse(url_str)
|
106
146
|
req = Net::HTTP::Get.new(uri)
|
107
147
|
req['Cookie'] = @http_headers.join('; ')
|
108
148
|
res = Net::HTTP.start(uri.hostname, uri.port) do |http|
|
109
149
|
http.request(req)
|
110
150
|
end
|
111
|
-
|
112
|
-
|
151
|
+
res_json = JSON.parse(res.body)
|
152
|
+
puts res.body unless res_json['errcode'].to_i.zero?
|
153
|
+
puts res.body if @debug
|
154
|
+
res_json
|
113
155
|
end
|
114
156
|
|
115
|
-
def
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
157
|
+
def print_res_body_model(res_json)
|
158
|
+
res_body = fetch_res_boy(res_json)
|
159
|
+
return unless res_body
|
160
|
+
|
161
|
+
puts "\n<===============打印返回数据模型-Begin=====================>\n".green
|
162
|
+
models = []
|
163
|
+
handle_model(res_body) do |model|
|
164
|
+
models << model
|
123
165
|
end
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
166
|
+
print_models(models)
|
167
|
+
print_models_impl(models)
|
168
|
+
@result_model_name = models.last[:name]
|
169
|
+
puts "\n<===============打印返回数据模型-End=====================>\n".green
|
170
|
+
end
|
171
|
+
|
172
|
+
def print_req_body_model(res_json)
|
173
|
+
req_body = fetch_req_body(res_json)
|
174
|
+
return unless req_body
|
175
|
+
|
176
|
+
puts "\n<===============打印请求模型-Begin=====================>\n".green
|
177
|
+
models = []
|
178
|
+
handle_model(req_body) do |model|
|
179
|
+
models << model
|
132
180
|
end
|
181
|
+
print_models(models)
|
182
|
+
print_models_impl(models)
|
183
|
+
@param_model_name = models.last[:name]
|
184
|
+
puts "\n<===============打印请求模型-End=====================>\n".green
|
133
185
|
end
|
134
186
|
|
135
187
|
def fetch_res_boy(res_json)
|
136
|
-
if res_json
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
end
|
147
|
-
end
|
148
|
-
end
|
188
|
+
return if !res_json || !res_json['data'] || !res_json['data']['res_body']
|
189
|
+
|
190
|
+
res_body = JSON.parse(res_json['data']['res_body'])
|
191
|
+
return if !res_body['properties'] || !res_body['properties']['detailMsg']
|
192
|
+
|
193
|
+
result = res_body['properties']['detailMsg']
|
194
|
+
return unless result['type'] == 'object' || result['type'] == 'array'
|
195
|
+
|
196
|
+
result['name'] = gen_model_name('')
|
197
|
+
result
|
149
198
|
end
|
150
199
|
|
151
200
|
def fetch_req_body(res_json)
|
152
|
-
if res_json
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
res_body['name'] = gen_model_name('')
|
158
|
-
handle_model(res_body)
|
159
|
-
rescue => ex
|
160
|
-
puts ex
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
201
|
+
return if !res_json || !res_json['data'] || !res_json['data']['req_body_other']
|
202
|
+
|
203
|
+
result = JSON.parse(res_json['data']['req_body_other'])
|
204
|
+
result['name'] = gen_model_name('')
|
205
|
+
result
|
164
206
|
end
|
165
207
|
|
166
208
|
def gen_model_name(name)
|
167
209
|
n = name.gsub(/vo|model|list/i, '').gsub(/(.*)s$/, '\1').gsub(/^\w/) { $&.upcase }
|
168
210
|
if n.length <= 0
|
169
|
-
n = @config_model_names.detect { |c|
|
211
|
+
n = @config_model_names.detect { |c| @model_names.none? { |na| na.gsub(/#{model_pre}(.*)Model/, '\1').eql?(c) } }
|
170
212
|
end
|
171
213
|
model_name = "#{model_pre}#{n}#{model_suffix}"
|
172
214
|
@model_names << model_name
|
173
215
|
model_name
|
174
216
|
end
|
175
217
|
|
176
|
-
def handle_model(model)
|
218
|
+
def handle_model(model, &block)
|
177
219
|
p_type = model['type']
|
178
220
|
p_name = model['name']
|
179
221
|
p_properties = model['properties']
|
@@ -192,22 +234,22 @@ module Lhj
|
|
192
234
|
c_model[:type_name] = 'NSString'
|
193
235
|
else
|
194
236
|
c_model[:type_name] = o['name']
|
195
|
-
handle_model(o)
|
237
|
+
handle_model(o, &block)
|
196
238
|
end
|
197
239
|
end
|
198
240
|
properties << c_model
|
199
241
|
end
|
200
242
|
p_model[:properties] = properties
|
201
|
-
|
243
|
+
block[p_model] if block_given?
|
202
244
|
when 'array'
|
203
245
|
t = model['items']
|
204
246
|
t['name'] = p_name
|
205
|
-
handle_model(t)
|
247
|
+
handle_model(t, &block)
|
206
248
|
end
|
207
249
|
end
|
208
250
|
|
209
|
-
def print_models
|
210
|
-
|
251
|
+
def print_models(models)
|
252
|
+
models.each do |model|
|
211
253
|
model_name = model[:name] || ''
|
212
254
|
model_properties = model[:properties]
|
213
255
|
puts_h "@interface #{model_name} : NSObject"
|
@@ -218,8 +260,8 @@ module Lhj
|
|
218
260
|
end
|
219
261
|
end
|
220
262
|
|
221
|
-
def
|
222
|
-
|
263
|
+
def print_models_impl(models)
|
264
|
+
models.each do |model|
|
223
265
|
puts_m "@implementation #{model[:name]}"
|
224
266
|
str = model[:properties].filter { |p| p[:type].eql?('array') && !p[:type_name].eql?('NSString') }.map { |p| "@\"#{p[:key]}\": #{p[:type_name]}.class" }.join(', ')
|
225
267
|
if str && str.length.positive?
|
@@ -243,9 +285,9 @@ module Lhj
|
|
243
285
|
case type
|
244
286
|
when 'integer'
|
245
287
|
puts_h "@property (nonatomic, assign) NSInteger #{key};"
|
246
|
-
if des.include?('分')
|
247
|
-
|
248
|
-
|
288
|
+
if des.include?('分') || des.include?('0.01')
|
289
|
+
puts_h_red '/////////==========删掉其中一个属性'
|
290
|
+
puts_h_red "@property (nonatomic, strong) MLCentNumber *#{key};"
|
249
291
|
end
|
250
292
|
when 'cent'
|
251
293
|
puts_h "@property (nonatomic, strong) MLCentNumber *#{key};"
|
@@ -268,39 +310,34 @@ module Lhj
|
|
268
310
|
end
|
269
311
|
end
|
270
312
|
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
puts_m ' */'
|
276
|
-
key_str = @data_json['path'].split('/').map { |s| s.gsub(/[^A-Za-z0-9]/, '').gsub(/^\w/) { $&.upcase } }.join('')
|
277
|
-
key = "k#{key_str}URL"
|
278
|
-
puts_m "static NSString * const #{key} = @\"#{@data_json['path']}\";"
|
279
|
-
puts_m "\n\n"
|
313
|
+
# @param [Object] data
|
314
|
+
def print_req_query(data)
|
315
|
+
return unless data && data['req_query']
|
316
|
+
|
280
317
|
puts_h '@interface MLParamModel : NSObject'
|
281
|
-
|
318
|
+
data['req_query'].each do |h|
|
282
319
|
des = h['desc']
|
283
320
|
puts_h "///#{des} #{h['example']}"
|
284
321
|
puts_h "@property (nonatomic, copy) NSString *#{h['name']};"
|
285
322
|
end
|
286
323
|
puts_h '@end'
|
287
324
|
puts "\n\n"
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
325
|
+
end
|
326
|
+
|
327
|
+
def print_http_method(data)
|
328
|
+
return unless data
|
329
|
+
|
330
|
+
@path = data['path']
|
331
|
+
@method = data['method']
|
332
|
+
@title = data['title']
|
333
|
+
@username = data['username']
|
334
|
+
@desc = data['desc']
|
335
|
+
@method = 'JSON' if data['req_body_is_json_schema']
|
336
|
+
@path_name = @path.split('/').map { |s| s.gsub(/[^A-Za-z0-9]/, '').gsub(/^\w/) { $&.upcase } }.join('') if @path
|
337
|
+
@path_key = "k#{@path_name}URL"
|
338
|
+
puts "\n<===============方法调用=====================>\n".green
|
339
|
+
@model_template = Lhj::ErbFormatter::Service.new(self).render('model')
|
340
|
+
puts Lhj::ErbFormatter::Service.new(self).render('yapi').blue
|
304
341
|
end
|
305
342
|
end
|
306
343
|
end
|
data/lib/lhj/command.rb
CHANGED
@@ -30,19 +30,23 @@ module Lhj
|
|
30
30
|
self.abstract_command = true
|
31
31
|
self.command = 'lhj'
|
32
32
|
|
33
|
+
def begin_title
|
34
|
+
'开始处理...'
|
35
|
+
end
|
36
|
+
|
33
37
|
def auto_spin
|
34
|
-
|
38
|
+
puts begin_title.green
|
35
39
|
# @spinner.auto_spin
|
36
40
|
end
|
37
41
|
|
38
42
|
def stop
|
39
|
-
|
43
|
+
puts '处理完成'.green
|
40
44
|
# @spinner.success('Done!')
|
41
45
|
end
|
42
46
|
|
43
47
|
def initialize(argv)
|
44
48
|
super(argv)
|
45
|
-
@spinner = TTY::Spinner.new('...', output: $stdout, format: :dots, clear: true)
|
49
|
+
@spinner = TTY::Spinner.new('[:spinner]...', output: $stdout, format: :dots, clear: true)
|
46
50
|
end
|
47
51
|
|
48
52
|
def run
|
data/lib/lhj/tools/version.rb
CHANGED
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.
|
4
|
+
version: 0.1.11
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lihaijian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
11
|
+
date: 2022-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: claide
|
@@ -142,16 +142,16 @@ dependencies:
|
|
142
142
|
name: colored
|
143
143
|
requirement: !ruby/object:Gem::Requirement
|
144
144
|
requirements:
|
145
|
-
- -
|
145
|
+
- - '='
|
146
146
|
- !ruby/object:Gem::Version
|
147
|
-
version: '
|
147
|
+
version: '1.2'
|
148
148
|
type: :runtime
|
149
149
|
prerelease: false
|
150
150
|
version_requirements: !ruby/object:Gem::Requirement
|
151
151
|
requirements:
|
152
|
-
- -
|
152
|
+
- - '='
|
153
153
|
- !ruby/object:Gem::Version
|
154
|
-
version: '
|
154
|
+
version: '1.2'
|
155
155
|
- !ruby/object:Gem::Dependency
|
156
156
|
name: excon
|
157
157
|
requirement: !ruby/object:Gem::Requirement
|
@@ -297,6 +297,11 @@ files:
|
|
297
297
|
- lib/lhj/command/trans.rb
|
298
298
|
- lib/lhj/command/view.rb
|
299
299
|
- lib/lhj/command/yapi.rb
|
300
|
+
- lib/lhj/command/yapi/formatters/base.rb
|
301
|
+
- lib/lhj/command/yapi/formatters/command_context.rb
|
302
|
+
- lib/lhj/command/yapi/formatters/service.rb
|
303
|
+
- lib/lhj/command/yapi/formatters/template/model.erb
|
304
|
+
- lib/lhj/command/yapi/formatters/template/yapi.erb
|
300
305
|
- lib/lhj/config.rb
|
301
306
|
- lib/lhj/helper/local_config.rb
|
302
307
|
- lib/lhj/helper/oss_config.rb
|