lhj-tools 0.2.72 → 0.2.74
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/local/fetch.rb +4 -4
- data/lib/lhj/helper/ios_api_available_check_helper.rb +106 -0
- data/lib/lhj/lhj.rb +1 -0
- data/lib/lhj/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d7617205034e037486f6f9cb332e7064f49bd32d509d9f1e957c5df47100dabb
|
4
|
+
data.tar.gz: 254627f1697ed73f5aeb332d8e9da0f15e2b356698e02d1ce695836d0e7139cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f596ee969cb0231148e553cff8683280ea271dd4bf303ea6347c2963d6ee8f05b8802d05ebca7f174834aec3e09874b58ba16141df418420f1a44304584a1b6
|
7
|
+
data.tar.gz: 8cdcccbca6add90899a7e0efb3c3b62a5c67bc9f7ba054c5c183b4e6626cb369da5dc6c11026090a46e059f9d6fb4f6b172f1d33fb523d42d6ce63714e5a75f0
|
@@ -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
|
-
|
48
|
-
|
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
|
-
|
60
|
-
|
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,106 @@
|
|
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}}").reject do |p|
|
9
|
+
p =~ /Pods/
|
10
|
+
end
|
11
|
+
result = {}
|
12
|
+
all_files.each do |f|
|
13
|
+
wrapper_lines = find_available_wrapper(f)
|
14
|
+
infos = handle_file(f, wrapper_lines)
|
15
|
+
result[File.basename(f)] = infos if infos.length.positive?
|
16
|
+
end
|
17
|
+
# result
|
18
|
+
# show_result(result)
|
19
|
+
result.keys.each_slice(10) { |a| notify(result.slice(*a)) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.show_result(result)
|
23
|
+
result.each do |k, v|
|
24
|
+
puts k
|
25
|
+
v.each do |o|
|
26
|
+
puts "第#{o[:idx]}行:"
|
27
|
+
puts o[:line]
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.find_available_wrapper(file)
|
33
|
+
lines = []
|
34
|
+
File.open(file, 'r') do |f|
|
35
|
+
multi_comment = false
|
36
|
+
available_idx = 0
|
37
|
+
f.readlines.each_with_index do |line, idx|
|
38
|
+
multi_comment = true if line =~ %r{/\*} && line !~ %r{\*/} && !multi_comment
|
39
|
+
if line !~ %r{/\*} && line =~ %r{\*/} && multi_comment
|
40
|
+
multi_comment = false
|
41
|
+
next
|
42
|
+
end
|
43
|
+
|
44
|
+
next if multi_comment
|
45
|
+
next if line =~ %r{\s*//}
|
46
|
+
next unless line =~ API_AVAILABLE_KEY_BEGIN_REGEX || available_idx.positive?
|
47
|
+
|
48
|
+
available_idx += 1 if line =~ /\{/
|
49
|
+
available_idx -= 1 if line =~ /\}/
|
50
|
+
lines << { idx: idx, line: line }
|
51
|
+
end
|
52
|
+
end
|
53
|
+
lines
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.handle_file(file, wrapper_lines)
|
57
|
+
result = []
|
58
|
+
File.open(file, 'r') do |f|
|
59
|
+
multi_comment = false
|
60
|
+
f.readlines.each_with_index do |line, idx|
|
61
|
+
multi_comment = true if line =~ %r{/\*} && line !~ %r{\*/} && !multi_comment
|
62
|
+
if line !~ %r{/\*} && line =~ %r{\*/} && multi_comment
|
63
|
+
multi_comment = false
|
64
|
+
next
|
65
|
+
end
|
66
|
+
|
67
|
+
next if multi_comment
|
68
|
+
next if line =~ %r{\s*//}
|
69
|
+
# 1. 白名单查找
|
70
|
+
next unless match_white_list_reg(line)
|
71
|
+
# 2. 找到的行是否已available代码块
|
72
|
+
next if wrapper_lines.length.positive? && wrapper_lines.any? { |w| w[:idx] == idx }
|
73
|
+
|
74
|
+
result << { idx: idx + 1, line: line }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
result
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.match_white_list_reg(line)
|
81
|
+
regs ||= load_white_api_list
|
82
|
+
regs.any? { |r| line =~ /#{r}/ }
|
83
|
+
end
|
84
|
+
|
85
|
+
def self.load_white_api_list
|
86
|
+
require 'yaml'
|
87
|
+
yaml_file = File.join(Lhj::Config.instance.home_dir, 'ios_available_api_white_list.yml')
|
88
|
+
YAML.safe_load(File.open(yaml_file))
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.robot_url
|
92
|
+
'https://oapi.dingtalk.com/robot/send?access_token=fe879fd3e7a3b5e59d5719b2384845b7884901919be5a78fe443cbf777869807'
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.notify(result)
|
96
|
+
temp = Lhj::ErbTemplateHelper.load('ios_avaliable_api_notify')
|
97
|
+
temp_result = Lhj::ErbTemplateHelper.render(temp, { result: result, branch: git_branch }, '-')
|
98
|
+
Lhj::Dingtalk.post_message_robot(robot_url, 'check code', temp_result)
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.git_branch
|
102
|
+
branch ||= Lhj::LogHelper.instance.fetch_branch
|
103
|
+
branch
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
data/lib/lhj/lhj.rb
CHANGED
data/lib/lhj/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.2.
|
4
|
+
version: 0.2.74
|
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-
|
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
|