lhj-tools 0.1.10 → 0.1.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a1d71c98366bbad8074af38f9c4381db08fb138457a61cd119ff3f3405ac9ba7
4
- data.tar.gz: 37d5b49a7403e202dea0c557bcbe17e35e4d3483b2e4a8fa4868d58527d5d545
3
+ metadata.gz: 17511d36f2ccbd99a885442c54373a7a032cc014552855a33b2c326dccf34688
4
+ data.tar.gz: ba65a5faa5f83e351935bdb7a7f0b221bd8ea405f1788acd2c29e85d2d0d6fe6
5
5
  SHA512:
6
- metadata.gz: 5a190d0b7d8adf62726401fac4c550acf6b70eb08c0a1775e18df2a724e2156b0c9b4a0b04bd009a8c9b2a3be2b44bb571344058ad5590115088203e13b4f417
7
- data.tar.gz: dc1ac168f906f8a0db1675ae3dc6ec93dbec6424a7edcfbabe80c3308031f969f4db91057e0783057e4d1e04922fbb70bf3aa326ceec210a75eab3fc23d1f9e1
6
+ metadata.gz: 4396cb85f10adeb732be7038d061b3188536e4a47113d5426ee9e2c02a35f4271562a2c6655c3c8773ec7633a976c9f51310a9640fca0a37b79848749cc9cf7a
7
+ data.tar.gz: b401b9f5e196b7ed835bce7bb363876203b3f987b6314517b5f168b15d20d25cf64082b7b18ab3c2c1c10bffd12fa45100678234975a07f4160c1b5bbd476ed3
@@ -3,29 +3,44 @@ require 'lhj/config'
3
3
 
4
4
  module Lhj
5
5
  class Command
6
+ # config
6
7
  class Config < Command
8
+ def initialize(argv)
9
+ @cli = HighLine.new
10
+ super
11
+ end
12
+
13
+ def show_config
14
+ config_arr = Dir.glob("#{config_dir}/**/*.yml")
15
+ config_arr.each_index { |i| puts "#{i}.#{File.basename(config_arr[i])}".yellow }
16
+ idx = ask_which_one
17
+ config_file = config_arr[idx]
18
+ handle_yaml(config_file)
19
+ end
20
+
21
+ def handle_yaml(file)
22
+ '子类实现'
23
+ end
24
+
25
+ def handle
26
+ show_config
27
+ end
28
+
29
+ def config_dir
30
+ Lhj::Config.instance.home_dir
31
+ end
32
+
33
+ def print_table(title, table_rows)
34
+ table = Terminal::Table.new title: title, headings: %w[键 值], rows: table_rows
35
+ puts table
36
+ end
37
+
7
38
  # show config info
8
39
  class Info < Config
9
40
  self.summary = '查看配置信息'
10
41
 
11
- def initialize(argv)
12
- @cli = HighLine.new
13
- super
14
- end
15
-
16
- def handle
17
- show_config
18
- end
19
-
20
- def show_config
21
- config_arr = Dir.glob("#{config_dir}/**/*.yml")
22
- config_arr.each_index { |i| puts "#{i}.#{File.basename(config_arr[i])}".yellow }
23
- idx = ask_which_one
24
- config_file = config_arr[idx]
25
- show_yaml(config_file)
26
- end
27
42
 
28
- def show_yaml(file)
43
+ def handle_yaml(file)
29
44
  table_rows = []
30
45
  content = YAML.load_file(file)
31
46
 
@@ -49,17 +64,33 @@ module Lhj
49
64
  print_table(title, table_rows) if table_rows.count.positive?
50
65
  end
51
66
 
52
- def print_table(title, table_rows)
53
- table = Terminal::Table.new title: title, headings: %w[键 值], rows: table_rows
54
- puts table
67
+ def ask_which_one
68
+ @cli.ask('查看哪个配置: '.green).strip.to_i
55
69
  end
70
+ end
71
+
72
+ class Update < Config
56
73
 
57
74
  def ask_which_one
58
- @cli.ask('查看哪个配置: '.green).strip.to_i
75
+ @cli.ask('更新哪个配置: '.green).strip.to_i
59
76
  end
60
77
 
61
- def config_dir
62
- Lhj::Config.instance.home_dir
78
+ def handle_yaml(file)
79
+ table_rows = []
80
+ content = YAML.load_file(file)
81
+
82
+ if content.is_a?(Hash)
83
+ content.each do |key, value|
84
+ table_rows << [key, value]
85
+ end
86
+ end
87
+
88
+ title = File.basename(file).to_s
89
+ print_table(title, table_rows) if table_rows.count.positive?
90
+
91
+ cmd = ['open']
92
+ cmd << file
93
+ Actions.sh(cmd.join(' '))
63
94
  end
64
95
  end
65
96
  end
@@ -1,3 +1,4 @@
1
+ # frozen_string_literal: true
1
2
  require 'faraday'
2
3
  require 'faraday_middleware'
3
4
  require 'net/http'
@@ -23,7 +24,10 @@ module Lhj
23
24
 
24
25
  def validate!
25
26
  super
26
- help! '配置url必须输入' unless @url
27
+ unless @url
28
+ path = File.join(target_folder, 'config_file.yml')
29
+ help! '配置url必须输入' unless File.exist?(path)
30
+ end
27
31
  end
28
32
 
29
33
  def initialize(argv)
@@ -33,8 +37,13 @@ module Lhj
33
37
 
34
38
  def handle
35
39
  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)
40
+ if @url
41
+ file_path = file_name_from_url(@url)
42
+ File.delete(file_path) if File.exist?(file_path)
43
+ save_url_to_file(@url, file_path)
44
+ else
45
+ file_path = File.join(target_folder, 'config_file.yml')
46
+ end
38
47
  content = YAML.load_file(file_path)
39
48
  download_file(content) if content.is_a?(Array)
40
49
  end
@@ -0,0 +1,20 @@
1
+ require 'lhj/helper/pgyer_helper'
2
+ require 'lhj/helper/dingtalk_config'
3
+ require 'lhj/helper/pgyer_config'
4
+ require 'lhj/helper/tb_config'
5
+
6
+
7
+ module Lhj
8
+ class Command
9
+ class Pgyer < Command
10
+
11
+ def handle
12
+ client = Lhj::Pgyer.new
13
+ file = File.expand_path('/Users/lihaijian/**/*.ipa')
14
+ client.upload_file(file, 'test....')
15
+ output = client.render_template
16
+ puts output.blue
17
+ end
18
+ end
19
+ end
20
+ end
@@ -47,102 +47,118 @@ module Lhj
47
47
  print_value
48
48
  end
49
49
 
50
+ def puts_d(str)
51
+ puts str.blue
52
+ end
53
+
54
+ def puts_i(str)
55
+ puts str.blue
56
+ end
57
+
58
+ def puts_l(str)
59
+ puts str.blue
60
+ end
61
+
62
+ def puts_v(str)
63
+ puts str.blue
64
+ end
65
+
50
66
  def print_declare
51
67
  names.each do |name|
52
- puts '///'
53
- puts "@property (nonatomic, strong) #{type} *#{name};"
68
+ puts_d '///'
69
+ puts_d "@property (nonatomic, strong) #{type} *#{name};"
54
70
  end
55
71
  end
56
72
 
57
73
  def print_instance
58
74
  names.each do |name|
59
- puts "-(#{type} *)#{name}"
60
- puts '{'
61
- puts " if(!_#{name}){"
75
+ puts_i "-(#{type} *)#{name}"
76
+ puts_i '{'
77
+ puts_i " if(!_#{name}){"
62
78
  print_alloc(name)
63
- puts " _#{name}.translatesAutoresizingMaskIntoConstraints = NO;"
79
+ puts_i " _#{name}.translatesAutoresizingMaskIntoConstraints = NO;"
64
80
  print_property(name)
65
- puts ' }'
66
- puts " return _#{name};"
67
- puts '}'
68
- puts "\n"
81
+ puts_i ' }'
82
+ puts_i " return _#{name};"
83
+ puts_i '}'
84
+ puts_i "\n"
69
85
  end
70
86
  end
71
87
 
72
88
  def print_alloc(name)
73
89
  case type
74
90
  when 'UIImageView'
75
- puts " _#{name} = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@\"xxxx\"]];"
91
+ puts_i " _#{name} = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@\"xxxx\"]];"
76
92
  when 'UIButton'
77
- puts " _#{name} = [UIButton buttonWithType:UIButtonTypeCustom];"
93
+ puts_i " _#{name} = [UIButton buttonWithType:UIButtonTypeCustom];"
78
94
  when 'UITableView'
79
- puts " _#{name} = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];"
95
+ puts_i " _#{name} = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStyleGrouped];"
80
96
  else
81
- puts " _#{name} = [[#{type} alloc] init];"
97
+ puts_i " _#{name} = [[#{type} alloc] init];"
82
98
  end
83
99
  end
84
100
 
85
101
  def print_property(name)
86
102
  case type
87
103
  when 'UILabel'
88
- puts " _#{name}.textColor = kSetCOLOR(0x333333);"
89
- puts " _#{name}.text = @\"xxxxxxxx\";"
90
- puts " _#{name}.font = [UIFont systemFontOfSize:12.0 weight:UIFontWeightRegular];"
91
- puts " _#{name}.textAlignment = NSTextAlignmentCenter;"
104
+ puts_i " _#{name}.textColor = kSetCOLOR(0x333333);"
105
+ puts_i " _#{name}.text = @\"xxxxxxxx\";"
106
+ puts_i " _#{name}.font = [UIFont systemFontOfSize:12.0 weight:UIFontWeightRegular];"
107
+ puts_i " _#{name}.textAlignment = NSTextAlignmentCenter;"
92
108
  when 'UIImageView'
93
- puts " _#{name}.backgroundColor = kBackgroundColor;"
94
- puts " _#{name}.contentMode = UIViewContentModeScaleAspectFit;"
95
- puts " _#{name}.clipsToBounds = YES;"
96
- puts " _#{name}.layer.cornerRadius = 6.0f;"
97
- puts " _#{name}.layer.borderColor = kLineColor.CGColor;"
98
- puts " _#{name}.layer.borderWidth = 0.5;"
109
+ puts_i " _#{name}.backgroundColor = kBackgroundColor;"
110
+ puts_i " _#{name}.contentMode = UIViewContentModeScaleAspectFit;"
111
+ puts_i " _#{name}.clipsToBounds = YES;"
112
+ puts_i " _#{name}.layer.cornerRadius = 6.0f;"
113
+ puts_i " _#{name}.layer.borderColor = kLineColor.CGColor;"
114
+ puts_i " _#{name}.layer.borderWidth = 0.5;"
99
115
  when 'UITextField'
100
- puts " _#{name}.textColor = kSetCOLOR(0x333333);"
101
- puts " _#{name}.font = [UIFont systemFontOfSize:12.0 weight:UIFontWeightRegular];"
116
+ puts_i " _#{name}.textColor = kSetCOLOR(0x333333);"
117
+ puts_i " _#{name}.font = [UIFont systemFontOfSize:12.0 weight:UIFontWeightRegular];"
102
118
  when 'UIView'
103
- puts " _#{name}.backgroundColor = kBackgroundColor;"
119
+ puts_i " _#{name}.backgroundColor = kBackgroundColor;"
104
120
  when 'UIStackView'
105
- puts " _#{name}.axis = UILayoutConstraintAxisHorizontal;"
106
- puts " _#{name}.distribution = UIStackViewDistributionFillEqually;"
121
+ puts_i " _#{name}.axis = UILayoutConstraintAxisHorizontal;"
122
+ puts_i " _#{name}.distribution = UIStackViewDistributionFillEqually;"
107
123
  when 'UITableView'
108
- puts " _#{name}.backgroundColor = kBackgroundColor;"
109
- puts " _#{name}.delegate = self;"
110
- puts " _#{name}.delegate = self;"
111
- puts " _#{name}.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];"
112
- puts " _#{name}.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];"
113
- puts " _#{name}.separatorStyle = UITableViewCellSeparatorStyleNone;"
124
+ puts_i " _#{name}.backgroundColor = kBackgroundColor;"
125
+ puts_i " _#{name}.delegate = self;"
126
+ puts_i " _#{name}.delegate = self;"
127
+ puts_i " _#{name}.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];"
128
+ puts_i " _#{name}.tableFooterView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, CGFLOAT_MIN)];"
129
+ puts_i " _#{name}.separatorStyle = UITableViewCellSeparatorStyleNone;"
114
130
  when 'UIButton'
115
- puts " _#{name}.backgroundColor = kBackgroundColor;"
116
- puts " [_#{name} setTitle:@\"xxx\" forState:UIControlStateNormal];"
117
- puts " [_#{name} setTitleColor:kSetCOLOR(0x999999) forState:UIControlStateNormal];"
118
- puts " _#{name}.titleLabel.font = [UIFont systemFontOfSize:14.0 weight:UIFontWeightRegular];"
119
- puts " [_#{name} setImage:[UIImage imageNamed:@\"xx\"] forState:UIControlStateNormal];"
120
- puts " [_#{name} setImage:[UIImage imageNamed:@\"xx\"] forState:UIControlStateSelected];"
121
- puts " [_#{name} addTarget:self action:@selector(actionHandler:) forControlEvents:UIControlEventTouchUpInside];"
131
+ puts_i " _#{name}.backgroundColor = kBackgroundColor;"
132
+ puts_i " [_#{name} setTitle:@\"xxx\" forState:UIControlStateNormal];"
133
+ puts_i " [_#{name} setTitleColor:kSetCOLOR(0x999999) forState:UIControlStateNormal];"
134
+ puts_i " _#{name}.titleLabel.font = [UIFont systemFontOfSize:14.0 weight:UIFontWeightRegular];"
135
+ puts_i " [_#{name} setImage:[UIImage imageNamed:@\"xx\"] forState:UIControlStateNormal];"
136
+ puts_i " [_#{name} setImage:[UIImage imageNamed:@\"xx\"] forState:UIControlStateSelected];"
137
+ puts_i " [_#{name} addTarget:self action:@selector(actionHandler:) forControlEvents:UIControlEventTouchUpInside];"
122
138
  end
123
139
  end
124
140
 
125
141
  def print_layout
126
142
  names.each do |name|
127
- puts "[contentView addSubview:self.#{name}];"
128
- puts "[self.#{name}.leadingAnchor constraintEqualToAnchor:contentView.leadingAnchor constant:0].active = YES;"
129
- puts "[self.#{name}.trailingAnchor constraintEqualToAnchor:contentView.trailingAnchor constant:0].active = YES;"
130
- puts "[self.#{name}.topAnchor constraintEqualToAnchor:contentView.topAnchor].active = YES;"
131
- puts "[self.#{name}.bottomAnchor constraintEqualToAnchor:contentView.bottomAnchor].active = YES;"
132
- puts "[self.#{name}.widthAnchor constraintEqualToConstant:80].active = YES;"
133
- puts "[self.#{name}.heightAnchor constraintEqualToConstant:80].active = YES;"
143
+ puts_l "[contentView addSubview:self.#{name}];"
144
+ puts_l "[self.#{name}.leadingAnchor constraintEqualToAnchor:contentView.leadingAnchor constant:0].active = YES;"
145
+ puts_l "[self.#{name}.trailingAnchor constraintEqualToAnchor:contentView.trailingAnchor constant:0].active = YES;"
146
+ puts_l "[self.#{name}.topAnchor constraintEqualToAnchor:contentView.topAnchor].active = YES;"
147
+ puts_l "[self.#{name}.bottomAnchor constraintEqualToAnchor:contentView.bottomAnchor].active = YES;"
148
+ puts_l "[self.#{name}.widthAnchor constraintEqualToConstant:80].active = YES;"
149
+ puts_l "[self.#{name}.heightAnchor constraintEqualToConstant:80].active = YES;"
134
150
  if type.eql?('UILabel')
135
- puts "[self.#{name} setContentHuggingPriority:300 forAxis:UILayoutConstraintAxisHorizontal];"
136
- puts "[self.#{name} setContentCompressionResistancePriority:300 forAxis:UILayoutConstraintAxisHorizontal];"
151
+ puts_l "[self.#{name} setContentHuggingPriority:300 forAxis:UILayoutConstraintAxisHorizontal];"
152
+ puts_l "[self.#{name} setContentCompressionResistancePriority:300 forAxis:UILayoutConstraintAxisHorizontal];"
137
153
  end
138
- puts "\n\n"
154
+ puts_l "\n\n"
139
155
  end
140
156
  end
141
157
 
142
158
  def print_value
143
159
  names.each do |name|
144
160
  if type.eql?('UILabel')
145
- puts "self.#{name}.text = @\"xxxxx\";"
161
+ puts_v "self.#{name}.text = @\"xxxxx\";"
146
162
  end
147
163
  end
148
164
  end
@@ -8,14 +8,23 @@ module Lhj
8
8
  class Service < Base
9
9
  # @param [String] name
10
10
  def render(name = 'yapi')
11
- template(name).result(Context.new(@runner).fetch_binding)
11
+ temp_str = template_str(name)
12
+ render_template(temp_str)
12
13
  end
13
14
 
14
- def template(name)
15
+ def render_template(temp_str)
16
+ template(temp_str).result(Context.new(@runner).fetch_binding)
17
+ end
18
+
19
+ def template_str(name)
20
+ File.read(File.join(File.dirname(__FILE__), 'template', "#{name}.erb"))
21
+ end
22
+
23
+ def template(template_str)
15
24
  if RUBY_VERSION < '2.6'
16
- ERB.new(File.read(File.join(File.dirname(__FILE__), 'template', "#{name}.erb")), nil, '-')
25
+ ERB.new(template_str, nil, '-')
17
26
  else
18
- ERB.new(File.read(File.join(File.dirname(__FILE__), 'template', "#{name}.erb")), trim_mode: '-')
27
+ ERB.new(template_str, trim_mode: '-')
19
28
  end
20
29
  end
21
30
  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,6 @@
1
+ #### 应用名称:<%= @result['data']['appName'] %>
2
+ #### 版本信息:<%= @result['data']['appVersion'] %>(Build <%= @result['data']['appBuildVersion'] %>)
3
+ #### 更新时间:<%= @result['data']['appCreated'] %>
4
+ #### 更新内容:<%= @result['data']['appUpdateDescription'] %>
5
+ > ![screenshot](<%= @result['data']['appQRCodeURL'] %>)
6
+ > [下载](https://www.pgyer.com/<%= @result['data']['appShortcutUrl'] %>)
@@ -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 (^)(<% unless @result_model_name.empty? -%><%= @result_model_name %> *model, <% end -%>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 (^)(<% unless @result_model_name.empty? -%><%= @result_model_name %> *model, <% end -%>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)post<%= @path_name %>:(<%= @param_model_name %> *)param callback:(void (^)(<% unless @result_model_name.empty? -%><%= @result_model_name %> *model, <% end -%>MLResponseMessage *response))callback
23
+ {
24
+ [MLNetworkingManager postWithUrl:<%= @path_key %> params:params response:^(MLResponseMessage *response) {
25
+ <%= @model_template %>
26
+ }];
27
+ }
28
+ <% end -%>
@@ -24,6 +24,7 @@ module Lhj
24
24
  @model_pre_name = argv.option('model-pre')
25
25
  @save = argv.flag?('save', false)
26
26
  @debug = argv.flag?('debug', false)
27
+ @language = argv.option('lan', 'oc')
27
28
  @http_url = ''
28
29
  @http_headers = []
29
30
  @config_id = ''
@@ -59,7 +60,11 @@ module Lhj
59
60
  def process(config_file)
60
61
  load_config(config_file)
61
62
  res_body = req_api_model
62
- return unless res_body && res_body['errcode'].to_i.zero? && !res_body.empty?
63
+ unless res_body['errcode'].to_i.zero?
64
+ puts '请修改 ~/.lhj/yapi.yml文件的对应的__wpkreporterwid_,_yapi_token,_yapi_uid这三个值'.red
65
+ return
66
+ end
67
+ return unless res_body && !res_body.empty?
63
68
 
64
69
  # 1.print request result
65
70
  print_res_body_model(res_body)
@@ -163,8 +168,13 @@ module Lhj
163
168
  handle_model(res_body) do |model|
164
169
  models << model
165
170
  end
166
- print_models(models)
167
- print_models_impl(models)
171
+ case @language
172
+ when 'oc'
173
+ print_models(models)
174
+ print_models_impl(models)
175
+ when 'java'
176
+ print_models_for_java(models)
177
+ end
168
178
  @result_model_name = models.last[:name]
169
179
  puts "\n<===============打印返回数据模型-End=====================>\n".green
170
180
  end
@@ -178,8 +188,13 @@ module Lhj
178
188
  handle_model(req_body) do |model|
179
189
  models << model
180
190
  end
181
- print_models(models)
182
- print_models_impl(models)
191
+ case @language
192
+ when 'oc'
193
+ print_models(models)
194
+ print_models_impl(models)
195
+ when 'java'
196
+ print_models_for_java(models)
197
+ end
183
198
  @param_model_name = models.last[:name]
184
199
  puts "\n<===============打印请求模型-End=====================>\n".green
185
200
  end
@@ -260,11 +275,23 @@ module Lhj
260
275
  end
261
276
  end
262
277
 
278
+ def print_models_for_java(models)
279
+ models.each do |model|
280
+ model_name = model[:name] || ''
281
+ model_properties = model[:properties]
282
+ puts_h "public class #{model_name} extends BaseModel implements BusinessEvent.ProductDataCollect {"
283
+ model_properties.each do |m|
284
+ print_model_for_java(m)
285
+ end
286
+ puts_h "}\n\n\n"
287
+ end
288
+ end
289
+
263
290
  def print_models_impl(models)
264
291
  models.each do |model|
265
292
  puts_m "@implementation #{model[:name]}"
266
293
  str = model[:properties].filter { |p| p[:type].eql?('array') && !p[:type_name].eql?('NSString') }.map { |p| "@\"#{p[:key]}\": #{p[:type_name]}.class" }.join(', ')
267
- if str && str.length.positive?
294
+ if str&.length&.positive?
268
295
  puts_m '+(NSDictionary *)modelContainerPropertyGenericClass {'
269
296
  puts_m " return @{#{str}};"
270
297
  puts_m '}'
@@ -310,18 +337,54 @@ module Lhj
310
337
  end
311
338
  end
312
339
 
340
+ def print_model_for_java(m)
341
+ key = m[:key]
342
+ type_name = m[:type_name]
343
+ type = m[:type]
344
+ des = m[:description] || ''
345
+ des.gsub!(/\n/, ' ')
346
+ default = m[:default]
347
+ case type
348
+ when 'integer'
349
+ puts_h "int #{key};//#{des} #{default}"
350
+ when 'cent'
351
+ puts_h "int #{key};//#{des} #{default}"
352
+ when 'string'
353
+ puts_h "String #{key};//#{des} #{default}"
354
+ when 'number'
355
+ puts_h "double #{key};//#{des} #{default}"
356
+ when 'float'
357
+ puts_h "double #{key};//#{des} #{default}"
358
+ when 'double'
359
+ puts_h "double #{key};//#{des} #{default}"
360
+ when 'boolean'
361
+ puts_h "boolean #{key};//#{des} #{default}"
362
+ when 'object'
363
+ puts_h "#{type_name} #{key};//#{des} #{default}"
364
+ when 'array'
365
+ puts_h "#{type_name}[] #{key};//#{des} #{default}"
366
+ else
367
+ puts_h "String #{key};//#{des} #{default}"
368
+ end
369
+ end
370
+
313
371
  # @param [Object] data
314
372
  def print_req_query(data)
315
373
  return unless data && data['req_query']
316
374
 
317
- puts_h '@interface MLParamModel : NSObject'
318
- data['req_query'].each do |h|
319
- des = h['desc']
320
- puts_h "///#{des} #{h['example']}"
321
- puts_h "@property (nonatomic, copy) NSString *#{h['name']};"
375
+ case @language
376
+ when 'oc'
377
+ puts_h '@interface MLParamModel : NSObject'
378
+ data['req_query'].each do |h|
379
+ des = h['desc']
380
+ puts_h "///#{des} #{h['example']}"
381
+ puts_h "@property (nonatomic, copy) NSString *#{h['name']};"
382
+ end
383
+ puts_h '@end'
384
+ puts "\n\n"
385
+ when 'java'
322
386
  end
323
- puts_h '@end'
324
- puts "\n\n"
387
+ @param_model_name = 'MLParamModel' if @param_model_name.empty?
325
388
  end
326
389
 
327
390
  def print_http_method(data)
@@ -335,9 +398,13 @@ module Lhj
335
398
  @method = 'JSON' if data['req_body_is_json_schema']
336
399
  @path_name = @path.split('/').map { |s| s.gsub(/[^A-Za-z0-9]/, '').gsub(/^\w/) { $&.upcase } }.join('') if @path
337
400
  @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
401
+ case @language
402
+ when 'oc'
403
+ puts "\n<===============方法调用=====================>\n".green
404
+ @model_template = Lhj::ErbFormatter::Service.new(self).render('model')
405
+ puts Lhj::ErbFormatter::Service.new(self).render('yapi').blue
406
+ when 'java'
407
+ end
341
408
  end
342
409
  end
343
410
  end
data/lib/lhj/command.rb CHANGED
@@ -26,6 +26,7 @@ module Lhj
26
26
  require 'lhj/command/file_path'
27
27
  require 'lhj/command/http'
28
28
  require 'lhj/command/sync_pod_repo'
29
+ require 'lhj/command/pgyer_upload'
29
30
 
30
31
  self.abstract_command = true
31
32
  self.command = 'lhj'
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+ require 'yaml'
3
+ require 'lhj/config'
4
+
5
+ module Lhj
6
+ # Ding Talk Config
7
+ class DingTalkConfig
8
+
9
+ CONFIG_NAME = 'dingtalk_config.yml'
10
+
11
+ def self.config_file
12
+ File.join(Lhj::Config.instance.home_dir, CONFIG_NAME)
13
+ end
14
+
15
+ def self.config
16
+ @yaml ||= YAML.load_file(config_file)
17
+ end
18
+
19
+ def self.dingtalk_robot
20
+ config['dingtalk_robot']
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,14 @@
1
+ require 'lhj/helper/dingtalk_config'
2
+ require 'json'
3
+
4
+ module Lhj
5
+ # pgyer upload
6
+ class Dingtalk
7
+
8
+ def self.post_message(title, message)
9
+ robot_url = Lhj::DingTalkConfig.dingtalk_robot
10
+ http_body = { 'msgtype' => 'markdown', 'markdown' => { 'title' => title, 'text' => message } }.to_json
11
+ Net::HTTP.post(URI(robot_url), http_body, 'Content-Type' => 'application/json')
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+ require 'yaml'
3
+ require 'lhj/config'
4
+
5
+ module Lhj
6
+ # pgyer config
7
+ class PgyerConfig
8
+
9
+ CONFIG_NAME = 'pgyer_config.yml'
10
+
11
+ def self.config_file
12
+ File.join(Lhj::Config.instance.home_dir, CONFIG_NAME)
13
+ end
14
+
15
+ def self.config
16
+ @yaml ||= YAML.load_file(config_file)
17
+ end
18
+
19
+ def self.api_key
20
+ config['api_key']
21
+ end
22
+
23
+ def self.user_key
24
+ config['user_key']
25
+ end
26
+
27
+ def self.password
28
+ config['password']
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,62 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+ require 'lhj/helper/pgyer_config'
4
+ require 'lhj/command/yapi/formatters/service'
5
+ require 'lhj/config'
6
+
7
+ module Lhj
8
+ # pgyer upload
9
+ class Pgyer
10
+
11
+ API_HOST = 'https://upload.pgyer.com/apiv1/app/upload'.freeze
12
+
13
+ attr_reader :api_key, :user_key, :password, :result
14
+
15
+ def initialize
16
+ @api_key = Lhj::PgyerConfig.api_key
17
+ @user_key = Lhj::PgyerConfig.user_key
18
+ @password = Lhj::PgyerConfig.password
19
+ @result = { 'data' => {} }
20
+ end
21
+
22
+ # @return [Faraday::Connection]
23
+ def http_client
24
+ conn_options = {
25
+ request: {
26
+ timeout: 1000,
27
+ open_timeout: 300
28
+ }
29
+ }
30
+ Faraday.new(nil, conn_options) do |builder|
31
+ builder.request :multipart
32
+ builder.request :url_encoded
33
+ builder.response :json, content_type: /\bjson$/
34
+ builder.adapter :net_http
35
+ end
36
+ end
37
+
38
+ def upload_file(file, des)
39
+ params = {
40
+ '_api_key' => @api_key,
41
+ 'uKey' => @user_key,
42
+ 'password' => @password,
43
+ 'updateDescription' => des,
44
+ 'installType' => 2,
45
+ 'file' => Faraday::UploadIO.new(file, 'application/octet-stream')
46
+ }
47
+ begin
48
+ puts 'begin upload'
49
+ response = http_client.post API_HOST, params
50
+ @result = response.body
51
+ puts ''
52
+ rescue Faraday::TimeoutError
53
+ puts 'upload fail'
54
+ end
55
+ end
56
+
57
+ def render_template
58
+ temp_str = File.read(File.join(Lhj::Config.instance.home_dir, 'pgyer.erb'))
59
+ Lhj::ErbFormatter::Service.new(self).render_template(temp_str)
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+ require 'yaml'
3
+ require 'lhj/config'
4
+
5
+ module Lhj
6
+ # tb config
7
+ class TBConfig
8
+
9
+ CONFIG_NAME = 'tb_config.yml'
10
+
11
+ def self.config_file
12
+ File.join(Lhj::Config.instance.home_dir, CONFIG_NAME)
13
+ end
14
+
15
+ def self.config
16
+ @yaml ||= YAML.load_file(config_file)
17
+ end
18
+
19
+ def self.tb_app_id
20
+ config['tb_app_id']
21
+ end
22
+
23
+ def self.tb_app_key
24
+ config['tb_app_key']
25
+ end
26
+
27
+ def self.tb_tenant_id
28
+ config['tb_tenant_id']
29
+ end
30
+
31
+ def self.projectId
32
+ config['projectId']
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,7 @@
1
+ require 'lhj/helper/tb_config'
2
+
3
+ module Lhj
4
+ # pgyer upload
5
+ class Tb
6
+ end
7
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Lhj
4
4
  module Tools
5
- VERSION = "0.1.10"
5
+ VERSION = "0.1.16"
6
6
  end
7
7
  end
data/lib/lhj/tools.rb CHANGED
@@ -4,6 +4,9 @@ require 'colored'
4
4
 
5
5
  module Lhj
6
6
  require 'lhj/config'
7
+ require 'lhj/helper/pgyer_helper'
8
+ require 'lhj/helper/dingtalk_helper'
9
+
7
10
  class Error < StandardError; end
8
11
 
9
12
  autoload :Command, 'lhj/command'
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.10
4
+ version: 0.1.16
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-28 00:00:00.000000000 Z
11
+ date: 2022-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: claide
@@ -289,6 +289,7 @@ files:
289
289
  - lib/lhj/command/oss/del.rb
290
290
  - lib/lhj/command/oss/list.rb
291
291
  - lib/lhj/command/oss/upload.rb
292
+ - lib/lhj/command/pgyer_upload.rb
292
293
  - lib/lhj/command/refactor_rename.rb
293
294
  - lib/lhj/command/rename_image.rb
294
295
  - lib/lhj/command/reverse_import.rb
@@ -300,10 +301,19 @@ files:
300
301
  - lib/lhj/command/yapi/formatters/base.rb
301
302
  - lib/lhj/command/yapi/formatters/command_context.rb
302
303
  - lib/lhj/command/yapi/formatters/service.rb
304
+ - lib/lhj/command/yapi/formatters/template/model.erb
305
+ - lib/lhj/command/yapi/formatters/template/pgyer.erb
306
+ - lib/lhj/command/yapi/formatters/template/yapi.erb
303
307
  - lib/lhj/config.rb
308
+ - lib/lhj/helper/dingtalk_config.rb
309
+ - lib/lhj/helper/dingtalk_helper.rb
304
310
  - lib/lhj/helper/local_config.rb
305
311
  - lib/lhj/helper/oss_config.rb
306
312
  - lib/lhj/helper/oss_helper.rb
313
+ - lib/lhj/helper/pgyer_config.rb
314
+ - lib/lhj/helper/pgyer_helper.rb
315
+ - lib/lhj/helper/tb_config.rb
316
+ - lib/lhj/helper/tb_helper.rb
307
317
  - lib/lhj/helper/trans_helper.rb
308
318
  - lib/lhj/tools.rb
309
319
  - lib/lhj/tools/version.rb