lhj-tools 0.2.71 → 0.2.73

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: e9f34207902253cd7e343b132210af875a99f7b0cbc17a14f811e4044af781ce
4
- data.tar.gz: c85d8572ea5c1e480753aa2a1f8f842882ae6ef374cb869f98789583adbea7fb
3
+ metadata.gz: 8f290f1dcacdb4ffd6a22237a2bcf16e2e859a722855c8ca63a508d36bc9004d
4
+ data.tar.gz: 0cfa5b7a21ca263afab94639ecb90703f01baa9c15db786d6c92c62dcac0ad05
5
5
  SHA512:
6
- metadata.gz: ee0d0dce1b75b11a7d7894d24e161698e03e438c1d61f60058c3acda029cccc7f1cbf0e02352fa49cee03c7ec94b8658a407bf5a14a1b8514b00bd78718619ce
7
- data.tar.gz: f7f2d0d2f5d4916b3b363aeedb588c00814f7b4ae89fb1264841b226365d5574a8743b7468b9f63aad57d9139cf0ea938684c16143b0b789e5086cc4adfd4d49
6
+ metadata.gz: 7a83825633df792ce139161b02f3b882c900ae140a84f517736de5480902766721b177b314154b4ef3fa8e4323f9aad6681d7585b650b605a9593e1684b2f844
7
+ data.tar.gz: 7d9436fcc3141dbcc19212c676783bf79e5e457d9f18e029eb791103faf9c7eb8afd6ee744d93cab52cc47c294e1836b2860d3813e0f6ac72524c70780037f8f
@@ -27,7 +27,7 @@ module Lhj
27
27
  write_zh_cn_strings
28
28
  handle_modify_source if @modify_source_flag
29
29
  else
30
- puts "获取中英文映射文件失败, 检查参数--read-csv-file=xx是否正常\n"
30
+ puts "获取中英文映射文件失败\n"
31
31
  end
32
32
  end
33
33
 
@@ -45,7 +45,11 @@ module Lhj
45
45
  en_col = @cli.ask('中英对应照csv<<英文>>所在的列, 默认为2: '.yellow, Integer) do |q|
46
46
  q.default = 2
47
47
  end
48
- read_csv_file(csv_file, key_col, cn_col, en_col)
48
+ begin
49
+ read_csv_file(csv_file, key_col, cn_col, en_col)
50
+ rescue ArgumentError => e
51
+ puts e.message.red
52
+ end
49
53
  need_add_other = @cli.ask('是否继续添加csv文件yes?: '.yellow, ->(yn) { yn.downcase[0] == 'y' }) do |q|
50
54
  q.default = false
51
55
  end
@@ -58,23 +62,23 @@ module Lhj
58
62
  time = Time.now.strftime('%Y%m%d_%H%M')
59
63
  q.default = "Localizable_#{time}.strings"
60
64
  end
61
- @en_dir_name = @cli.ask('生成英文.strings文件对应路径: '.yellow, String) do |q|
65
+ @en_dir_name = @cli.ask('存放英文的文件夹: '.yellow, String) do |q|
62
66
  q.default = 'MacauLife/en.lproj'
63
67
  end
64
- @zh_hk_dir_name = @cli.ask('生成繁体.strings文件对应路径: '.yellow, String) do |q|
68
+ @zh_hk_dir_name = @cli.ask('存放繁体的文件夹: '.yellow, String) do |q|
65
69
  q.default = 'MacauLife/zh-Hant.lproj'
66
70
  end
67
- @zh_cn_dir_name = @cli.ask('生成简体.strings文件对应路径: '.yellow, String) do |q|
71
+ @zh_cn_dir_name = @cli.ask('存放简体的文件夹: '.yellow, String) do |q|
68
72
  q.default = 'MacauLife/zh-Hans.lproj'
69
73
  end
70
74
  @modify_source_flag = @cli.agree(HighLine.color('是否要修改源码yes?:', :red))
71
- if @modify_source_flag
72
- @modify_file_type = @cli.ask('需要修改源码的文件类型: '.yellow, String) do |q|
73
- q.default = 'm,h'
74
- end
75
- @modify_format_string = @cli.ask('修改为国际化后的字符格式: '.yellow, String) do |q|
76
- q.default = 'MLLocalizedString(%s)'
77
- end
75
+ return unless @modify_source_flag
76
+
77
+ @modify_file_type = @cli.ask('源码的文件类型: '.yellow, String) do |q|
78
+ q.default = 'm,h'
79
+ end
80
+ @modify_format_string = @cli.ask('国际化字符格式: '.yellow, String) do |q|
81
+ q.default = 'MLLocalizedString(%s)'
78
82
  end
79
83
  end
80
84
 
@@ -88,17 +92,22 @@ module Lhj
88
92
  end
89
93
 
90
94
  def read_csv_file(file, key_c, cn_c, en_c)
91
- # trans_hk = false
92
- # trans_cn = true
93
- CSV.foreach(file) do |row|
94
- if row.length > 2
95
- key = row[key_c]
96
- cn_str = row[cn_c]
97
- hk_str = row[cn_c]
98
- # cn_str = Lhj::Trans::Helper.instance.trans_zh_cn_str(cn_str) if trans_cn
99
- hk_str = Lhj::Trans::Helper.instance.trans_zh_hk_str(hk_str) if hk_str&.length&.positive?
100
- @key_map[key] = { key: key, cn: cn_str, hk: hk_str, en: row[en_c] } unless key =~ /[\u4e00-\u9fa5]/
95
+ begin
96
+ current_row = nil
97
+ CSV.foreach(file, quote_char: ',') do |row|
98
+ current_row = row
99
+ if row.length > 2
100
+ key = row[key_c]
101
+ cn_str = row[cn_c]
102
+ hk_str = row[cn_c]
103
+ # cn_str = Lhj::Trans::Helper.instance.trans_zh_cn_str(cn_str) if trans_cn
104
+ hk_str = Lhj::Trans::Helper.instance.trans_zh_hk_str(hk_str) if hk_str&.length&.positive?
105
+ @key_map[key] = { key: key, cn: cn_str, hk: hk_str, en: row[en_c] } unless key =~ /[\u4e00-\u9fa5]/
106
+ end
101
107
  end
108
+ rescue CSV::MalformedCSVError => e
109
+ error = "读取csv异常,文件中的第#{e.line_number}行格式有误!! \n 上一行信息#{current_row}"
110
+ raise ArgumentError, error
102
111
  end
103
112
  end
104
113
 
@@ -0,0 +1,104 @@
1
+ # frozen_string_literal: true
2
+ module Lhj
3
+ class IosApiAvailableCheckHelper
4
+
5
+ API_AVAILABLE_KEY_BEGIN_REGEX = /@available\(/.freeze
6
+
7
+ def self.check(path, type = 'm')
8
+ all_files = Dir.glob("#{path}/**/*.{#{type}}")
9
+ result = {}
10
+ all_files.each do |f|
11
+ wrapper_lines = find_available_wrapper(f)
12
+ infos = handle_file(f, wrapper_lines)
13
+ result[File.basename(f)] = infos if infos.length.positive?
14
+ end
15
+ # result
16
+ # show_result(result)
17
+ result.keys.each_slice(10) { |a| notify(result.slice(*a)) }
18
+ end
19
+
20
+ def self.show_result(result)
21
+ result.each do |k, v|
22
+ puts k
23
+ v.each do |o|
24
+ puts "第#{o[:idx]}行:"
25
+ puts o[:line]
26
+ end
27
+ end
28
+ end
29
+
30
+ def self.find_available_wrapper(file)
31
+ lines = []
32
+ File.open(file, 'r') do |f|
33
+ multi_comment = false
34
+ available_idx = 0
35
+ f.readlines.each_with_index do |line, idx|
36
+ multi_comment = true if line =~ %r{/\*} && line !~ %r{\*/} && !multi_comment
37
+ if line !~ %r{/\*} && line =~ %r{\*/} && multi_comment
38
+ multi_comment = false
39
+ next
40
+ end
41
+
42
+ next if multi_comment
43
+ next if line =~ %r{\s*//}
44
+ next unless line =~ API_AVAILABLE_KEY_BEGIN_REGEX || available_idx.positive?
45
+
46
+ available_idx += 1 if line =~ /\{/
47
+ available_idx -= 1 if line =~ /\}/
48
+ lines << { idx: idx, line: line }
49
+ end
50
+ end
51
+ lines
52
+ end
53
+
54
+ def self.handle_file(file, wrapper_lines)
55
+ result = []
56
+ File.open(file, 'r') do |f|
57
+ multi_comment = false
58
+ f.readlines.each_with_index do |line, idx|
59
+ multi_comment = true if line =~ %r{/\*} && line !~ %r{\*/} && !multi_comment
60
+ if line !~ %r{/\*} && line =~ %r{\*/} && multi_comment
61
+ multi_comment = false
62
+ next
63
+ end
64
+
65
+ next if multi_comment
66
+ next if line =~ %r{\s*//}
67
+ # 1. 白名单查找
68
+ next unless match_white_list_reg(line)
69
+ # 2. 找到的行是否已available代码块
70
+ next if wrapper_lines.length.positive? && wrapper_lines.any? { |w| w[:idx] == idx }
71
+
72
+ result << { idx: idx + 1, line: line }
73
+ end
74
+ end
75
+ result
76
+ end
77
+
78
+ def self.match_white_list_reg(line)
79
+ regs ||= load_white_api_list
80
+ regs.any? { |r| line =~ /#{r}/ }
81
+ end
82
+
83
+ def self.load_white_api_list
84
+ require 'yaml'
85
+ yaml_file = File.join(Lhj::Config.instance.home_dir, 'ios_available_api_white_list.yml')
86
+ YAML.safe_load(File.open(yaml_file))
87
+ end
88
+
89
+ def self.robot_url
90
+ 'https://oapi.dingtalk.com/robot/send?access_token=fe879fd3e7a3b5e59d5719b2384845b7884901919be5a78fe443cbf777869807'
91
+ end
92
+
93
+ def self.notify(result)
94
+ temp = Lhj::ErbTemplateHelper.load('ios_avaliable_api_notify')
95
+ temp_result = Lhj::ErbTemplateHelper.render(temp, { result: result, branch: git_branch }, '-')
96
+ Lhj::Dingtalk.post_message_robot(robot_url, 'check code', temp_result)
97
+ end
98
+
99
+ def self.git_branch
100
+ branch ||= Lhj::LogHelper.instance.fetch_branch
101
+ branch
102
+ end
103
+ end
104
+ end
data/lib/lhj/lhj.rb CHANGED
@@ -32,6 +32,7 @@ module Lhj
32
32
  require 'lhj/helper/traditional_check_helper'
33
33
  require 'lhj/helper/todo_check_helper'
34
34
  require 'lhj/helper/image_oss_check_helper'
35
+ require 'lhj/helper/ios_api_available_check_helper'
35
36
 
36
37
  class Error < StandardError; end
37
38
 
data/lib/lhj/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Lhj
4
- VERSION = '0.2.71'
4
+ VERSION = '0.2.73'
5
5
  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.2.71
4
+ version: 0.2.73
5
5
  platform: ruby
6
6
  authors:
7
7
  - lihaijian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-01-02 00:00:00.000000000 Z
11
+ date: 2024-01-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xcodeproj
@@ -393,6 +393,7 @@ files:
393
393
  - lib/lhj/helper/git_branch_feature_config.rb
394
394
  - lib/lhj/helper/git_helper.rb
395
395
  - lib/lhj/helper/image_oss_check_helper.rb
396
+ - lib/lhj/helper/ios_api_available_check_helper.rb
396
397
  - lib/lhj/helper/ios_robot_config.rb
397
398
  - lib/lhj/helper/jenkins_config.rb
398
399
  - lib/lhj/helper/local_config.rb