lhj-tools 0.2.72 → 0.2.73

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: 860185cadd542b509b1d85d198c0a3ca6c7ec7bb2188dda3b26b2f7521f6ace0
4
- data.tar.gz: 674170f9e7b21c43965218b22a349b4cd49a706513ec1cbd486662a9d23e2c40
3
+ metadata.gz: 8f290f1dcacdb4ffd6a22237a2bcf16e2e859a722855c8ca63a508d36bc9004d
4
+ data.tar.gz: 0cfa5b7a21ca263afab94639ecb90703f01baa9c15db786d6c92c62dcac0ad05
5
5
  SHA512:
6
- metadata.gz: 18ce56d41b9fa74f995c137f10f5e5608b95e709e1dc88c07dc6f92791f2e5a1937ed0f556fd5aadde9a4561b58f2bc14d2d2848de6c2932a132ac7d5a16c82f
7
- data.tar.gz: 93e29e58679ed49389f7dae92badcd7ae738dec2bc56e93bdb301950f9d9f7708466f8f1d9bd891f209a30d9f9c358159ee925c373505079c82e9e15821657e6
6
+ metadata.gz: 7a83825633df792ce139161b02f3b882c900ae140a84f517736de5480902766721b177b314154b4ef3fa8e4323f9aad6681d7585b650b605a9593e1684b2f844
7
+ data.tar.gz: 7d9436fcc3141dbcc19212c676783bf79e5e457d9f18e029eb791103faf9c7eb8afd6ee744d93cab52cc47c294e1836b2860d3813e0f6ac72524c70780037f8f
@@ -44,8 +44,8 @@ module Lhj
44
44
  def gen_csv
45
45
  file = File.join(@current_path, csv_file_name)
46
46
  FileUtils.rm_rf(file) if File.exist?(file)
47
- header = %w[国际化key 中文 英文 所在文件 文件路径 行号]
48
- CSV.open(file, 'wb:utf-8', headers: true, converters: :numeric, header_converters: :symbol) do |csv|
47
+ CSV.open(file, 'wb:utf-8') do |csv|
48
+ csv << %w[国际化key 中文 英文 所在文件 文件路径 行号]
49
49
  @cn_keys.each do |k|
50
50
  csv << [k[:key], k[:cn], k[:en], k[:fname], k[:dirname], k[:idx]]
51
51
  end
@@ -56,8 +56,8 @@ module Lhj
56
56
  def gen_csv_unique
57
57
  file = File.join(@current_path, unique_csv_file_name)
58
58
  FileUtils.rm_rf(file) if File.exist?(file)
59
- header = %w[国际化key 中文 英文 所在文件 文件路径 行号]
60
- CSV.open(file, 'wb:utf-8', headers: true, write_headers: header) do |csv|
59
+ CSV.open(file, 'wb:utf-8') do |csv|
60
+ csv << %w[国际化key 中文 英文 所在文件 文件路径 行号]
61
61
  @cn_keys.uniq { |k| k[:cn] }.each do |k|
62
62
  csv << [k[:key], k[:cn], k[:en], k[:fname], k[:dirname], k[:idx]]
63
63
  end
@@ -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.72'
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.72
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-04 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