cocoapods-aomi-bin 0.1.3 → 0.1.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cocoapods-lhj-bin/command/bin.rb +3 -2
- data/lib/cocoapods-lhj-bin/command/bin/local/fetch.rb +147 -0
- data/lib/cocoapods-lhj-bin/command/bin/{local.rb → local/local.rb} +96 -36
- data/lib/cocoapods-lhj-bin/command/bin/local/upload.rb +46 -0
- data/lib/cocoapods-lhj-bin/command/bin/oss/del.rb +1 -1
- data/lib/cocoapods-lhj-bin/command/bin/oss/list.rb +0 -4
- data/lib/cocoapods-lhj-bin/config/config.rb +0 -3
- data/lib/cocoapods-lhj-bin/gem_version.rb +1 -1
- data/lib/cocoapods-lhj-bin/helpers/oss_helper.rb +8 -0
- metadata +5 -4
- data/lib/cocoapods-lhj-bin/command/bin/fetch.rb +0 -68
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d60564dc2567c05414925657a0bfcc79c03e29346af7799a236e824a48b522b
|
4
|
+
data.tar.gz: c58a951a5261bd33adff5d05e133385a3cc225059b103769a0fb8af333072917
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a21bb3fff848840bf1a72671bfc09fadec1dbf67c2103a1958a897065f6fd3d2f69332715bc0afe2e64ed4fc39f2ae3490a3a5b8c3e9eb4df155bf718b522c85
|
7
|
+
data.tar.gz: 352d771b8a7731af97c00ac7f83753178f2a8d7bbab02d188d1e4f45f31246f8cb523e2b6d26167034a6766eae96a2ce83b8b95675d37a443cf8c7304898dd48
|
@@ -6,9 +6,10 @@ require 'cocoapods-lhj-bin/command/bin/code'
|
|
6
6
|
require 'cocoapods-lhj-bin/command/bin/update'
|
7
7
|
require 'cocoapods-lhj-bin/command/bin/install'
|
8
8
|
require 'cocoapods-lhj-bin/command/bin/import'
|
9
|
-
require 'cocoapods-lhj-bin/command/bin/local'
|
9
|
+
require 'cocoapods-lhj-bin/command/bin/local/local'
|
10
|
+
require 'cocoapods-lhj-bin/command/bin/local/fetch'
|
11
|
+
require 'cocoapods-lhj-bin/command/bin/local/upload'
|
10
12
|
require 'cocoapods-lhj-bin/command/bin/trans'
|
11
|
-
require 'cocoapods-lhj-bin/command/bin/fetch'
|
12
13
|
require 'cocoapods-lhj-bin/command/bin/lhj'
|
13
14
|
require 'cocoapods-lhj-bin/command/bin/config/push'
|
14
15
|
require 'cocoapods-lhj-bin/command/bin/oss/list'
|
@@ -0,0 +1,147 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'csv'
|
4
|
+
|
5
|
+
module Pod
|
6
|
+
class Command
|
7
|
+
class Bin < Command
|
8
|
+
class Fetch < Bin
|
9
|
+
self.summary = '提取源码的中文字符串,并生成中英文对照csv文件'
|
10
|
+
|
11
|
+
def self.options
|
12
|
+
[
|
13
|
+
%w[--file-type 从文件扩展名中查找中文字符串,默认为m,h],
|
14
|
+
%w[--file-name 生成csv文件名,默认为gen_cn_key.csv]
|
15
|
+
]
|
16
|
+
end
|
17
|
+
|
18
|
+
def initialize(argv)
|
19
|
+
@current_path = argv.shift_argument || Dir.pwd
|
20
|
+
@file_type = argv.option('file-type', 'm,h')
|
21
|
+
@file_name = argv.option('file-name', 'gen_cn_key.csv')
|
22
|
+
@cn_keys = []
|
23
|
+
@key_map = {}
|
24
|
+
super
|
25
|
+
end
|
26
|
+
|
27
|
+
def run
|
28
|
+
handle_files
|
29
|
+
gen_csv
|
30
|
+
# update_source_header
|
31
|
+
end
|
32
|
+
|
33
|
+
def csv_file_name
|
34
|
+
file_name = @file_name
|
35
|
+
file_name = "#{@file_name}.csv" unless /.csv$/ =~ @file_name
|
36
|
+
file_name
|
37
|
+
end
|
38
|
+
|
39
|
+
def gen_csv
|
40
|
+
file = File.join(@current_path, csv_file_name)
|
41
|
+
FileUtils.rm_rf(file) if File.exist?(file)
|
42
|
+
CSV.open(file, 'wb:utf-8') do |csv|
|
43
|
+
csv << %w[国际化key 中文 英文 所在文件 文件路径]
|
44
|
+
@cn_keys.each do |k|
|
45
|
+
csv << [k[:key], k[:cn], k[:en], k[:fname], k[:dirname]]
|
46
|
+
end
|
47
|
+
end
|
48
|
+
UI.puts "生成csv文件完成.\n文件路径:#{File.absolute_path(file)}".green
|
49
|
+
end
|
50
|
+
|
51
|
+
def handle_files
|
52
|
+
Dir.glob("#{@current_path}/**/*.{#{@file_type}}").each do |f|
|
53
|
+
handle_file f
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def zh_ch_reg
|
58
|
+
/@"[^"]*[\u4e00-\u9fa5]+[^"]*"/
|
59
|
+
end
|
60
|
+
|
61
|
+
def handle_file(file)
|
62
|
+
File.open(file, 'r') do |f|
|
63
|
+
f.each_line do |line|
|
64
|
+
handle_line(file, line) if zh_ch_reg =~ line
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def handle_line(file, line)
|
70
|
+
line.scan(zh_ch_reg) do |str|
|
71
|
+
fname = File.basename(file)
|
72
|
+
dir_name = File.dirname(file)
|
73
|
+
mod_name = framework_name(dir_name)
|
74
|
+
key = "#{mod_name}.#{File.basename(file, '.*')}.#{rand(36**8).to_s(36)}"
|
75
|
+
cn_str = str[2, str.length - 3]
|
76
|
+
en_str = cn_str.gsub(/[\u4e00-\u9fa5]/, 'x')
|
77
|
+
@cn_keys << { key: key, cn: cn_str, en: en_str, fname: fname, dirname: dir_name }
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def framework_name(path)
|
82
|
+
mod_name = 'Main'
|
83
|
+
if /pods/i =~ path
|
84
|
+
ary = path.split('/')
|
85
|
+
index = ary.find_index { |p| p.eql?('Pods') }
|
86
|
+
if index
|
87
|
+
i = index + 1
|
88
|
+
mod_name = ary[i]
|
89
|
+
end
|
90
|
+
end
|
91
|
+
mod_name
|
92
|
+
end
|
93
|
+
|
94
|
+
def handle_static_line(file, line)
|
95
|
+
line.scan(zh_ch_reg) do |str|
|
96
|
+
ma = line.match(/\*.*=/)
|
97
|
+
key = ma[0][1, ma[0].length - 2].strip
|
98
|
+
@key_map[key.to_sym] = str
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def update_source_header
|
103
|
+
Dir.glob("#{@current_path}/**/*.{m,h}").each do |f|
|
104
|
+
if f =~ /Pods/
|
105
|
+
handler_file(f) if f =~ %r{Pods/MLF} || f =~ %r{Pods/MLU} || f =~ %r{Pods/MLN}
|
106
|
+
else
|
107
|
+
handler_file(f)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
def handler_file(file)
|
113
|
+
puts "#{File.absolute_path(file)} \n"
|
114
|
+
File.chmod(0o644, file)
|
115
|
+
str = file_string(file)
|
116
|
+
File.open(file, 'w+') do |f|
|
117
|
+
f.write(str)
|
118
|
+
end
|
119
|
+
File.chmod(0o444, file) if file =~ /Pods/
|
120
|
+
end
|
121
|
+
|
122
|
+
def file_string(file)
|
123
|
+
str = ''
|
124
|
+
File.open(file, 'r+') do |f|
|
125
|
+
f.each_line do |line|
|
126
|
+
str += format_string(f, line)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
str
|
130
|
+
end
|
131
|
+
|
132
|
+
def format_string(file, line)
|
133
|
+
result = line
|
134
|
+
unless /static/ =~ line
|
135
|
+
@key_map.each_key do |key|
|
136
|
+
n_key = /#{key.to_s}\s/
|
137
|
+
n_val = "#{@key_map[key]}\s"
|
138
|
+
result = result.gsub(n_key, n_val)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
result
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
require 'csv'
|
4
4
|
require 'cocoapods-lhj-bin/helpers/trans_helper'
|
5
|
+
require 'cocoapods-lhj-bin/helpers/oss_helper'
|
5
6
|
|
6
7
|
module Pod
|
7
8
|
class Command
|
@@ -14,11 +15,12 @@ module Pod
|
|
14
15
|
%w[--key-col 国际化key在csv中第几列,默认为0],
|
15
16
|
%w[--cn-col 中文在csv中第几列,默认为1],
|
16
17
|
%w[--en-col 英文在csv中第几列,默认为2],
|
17
|
-
%w[--csv
|
18
|
-
%w[--
|
18
|
+
%w[--download-csv 云端下载cvs的文件名],
|
19
|
+
%w[--read-csv-file 读取csv的文件名,默认为当前目录下所有csv文件],
|
20
|
+
%w[--gen-file 生成配置文件名,默认名为:Localizable.strings],
|
19
21
|
%w[--modify-source 修改源码,使用国际化key代替中文字符串],
|
20
22
|
%w[--modify-file-type 需要修改源码的文件类型,默认为m,h],
|
21
|
-
%w[--modify-format-string 修改为国际化后的字符格式,默认为NSLocalizedString(%s
|
23
|
+
%w[--modify-format-string 修改为国际化后的字符格式,默认为NSLocalizedString(%s,@"")]
|
22
24
|
]
|
23
25
|
end
|
24
26
|
|
@@ -27,7 +29,8 @@ module Pod
|
|
27
29
|
@key_col = argv.option('key-col', 0).to_i
|
28
30
|
@cn_col = argv.option('cn-col', 1).to_i
|
29
31
|
@en_col = argv.option('en-col', 2).to_i
|
30
|
-
@
|
32
|
+
@download_csv_files = argv.option('download-csv')
|
33
|
+
@read_csv_file = argv.option('read-csv-file', '*')
|
31
34
|
@gen_file_name = argv.option('gen-file', 'Localizable.strings')
|
32
35
|
@modify_source_flag = argv.flag?('modify-source', false)
|
33
36
|
@modify_file_type = argv.option('modify-file-type', 'm,h')
|
@@ -37,46 +40,109 @@ module Pod
|
|
37
40
|
end
|
38
41
|
|
39
42
|
def run
|
43
|
+
down_load_csv_file if @download_csv_files
|
40
44
|
read_csv_file
|
41
45
|
if @key_map.keys.length.positive?
|
42
|
-
|
43
|
-
|
44
|
-
|
46
|
+
write_en_strings
|
47
|
+
write_zh_cn_strings
|
48
|
+
write_zh_hk_strings
|
45
49
|
handle_modify_source if @modify_source_flag
|
46
50
|
else
|
47
|
-
UI.puts "获取中英文映射文件失败, 检查参数--csv-file=xx是否正常\n".red
|
51
|
+
UI.puts "获取中英文映射文件失败, 检查参数--read-csv-file=xx是否正常\n".red
|
48
52
|
end
|
49
53
|
end
|
50
54
|
|
51
55
|
def en_dir_name
|
52
|
-
'en.lproj'
|
56
|
+
'local_gen/en.lproj'
|
53
57
|
end
|
54
58
|
|
55
59
|
def zh_hk_dir_name
|
56
|
-
'zh-hk.lproj'
|
60
|
+
'local_gen/zh-hk.lproj'
|
57
61
|
end
|
58
62
|
|
59
63
|
def zh_cn_dir_name
|
60
|
-
'zh-cn.lproj'
|
64
|
+
'local_gen/zh-cn.lproj'
|
61
65
|
end
|
62
66
|
|
63
67
|
def generate_file_name
|
64
68
|
@gen_file_name
|
65
69
|
end
|
66
70
|
|
71
|
+
def read_csv_file_name
|
72
|
+
file_name = @read_csv_file
|
73
|
+
file_name = "#{@read_csv_file}.csv" unless /.csv$/ =~ @read_csv_file
|
74
|
+
file_name
|
75
|
+
end
|
76
|
+
|
77
|
+
def down_load_csv_file
|
78
|
+
ary = get_download_keys
|
79
|
+
ary.each do |key|
|
80
|
+
file_name = File.basename(key)
|
81
|
+
file = File.join(@current_path, file_name)
|
82
|
+
backup_csv_file file if File.exist?(file)
|
83
|
+
UI.puts "下载csv文件:#{CBin::OSS::Helper.instance.object_url(key)} 到目录#{file}\n".green
|
84
|
+
CBin::OSS::Helper.instance.down_load(key, file)
|
85
|
+
end
|
86
|
+
UI.puts "下载云端csv文件完成 \n".green
|
87
|
+
end
|
88
|
+
|
89
|
+
def backup_csv_file(file)
|
90
|
+
dest_file = bak_file(file)
|
91
|
+
FileUtils.mkdir_p(File.dirname(dest_file)) unless File.exist?(File.dirname(dest_file))
|
92
|
+
UI.puts "备份csv文件:#{file} 到目录#{dest_file}".green
|
93
|
+
FileUtils.cp file, dest_file
|
94
|
+
FileUtils.rm_rf file
|
95
|
+
end
|
96
|
+
|
97
|
+
def bak_file(file)
|
98
|
+
dest_file = File.join(File.dirname(file), 'csv_bak', File.basename(file))
|
99
|
+
File.exist?(dest_file) ? bak_file(dest_file) : dest_file
|
100
|
+
end
|
101
|
+
|
102
|
+
def get_download_keys
|
103
|
+
download_keys = []
|
104
|
+
csv_files = @download_csv_files.split(/,/).map(&:strip)
|
105
|
+
all_keys = CBin::OSS::Helper.instance.list.map(&:key)
|
106
|
+
csv_files.each do |f|
|
107
|
+
arr = all_keys.select { |k| %r{^csv/} =~ k && /#{f}/ =~ k }
|
108
|
+
if arr.count.positive?
|
109
|
+
arr.sort! { |a, b| b.split(%r{/})[1].to_i <=> a.split(%r{/})[1].to_i }
|
110
|
+
download_keys << arr[0]
|
111
|
+
end
|
112
|
+
end
|
113
|
+
download_keys
|
114
|
+
end
|
115
|
+
|
116
|
+
def read_csv_file
|
117
|
+
path = File.join(@current_path, read_csv_file_name)
|
118
|
+
Dir.glob(path).each do |p|
|
119
|
+
CSV.foreach(p) do |row|
|
120
|
+
key = row[@key_col]
|
121
|
+
@key_map[key] = { key: key, zh: row[@cn_col], en: row[@en_col] } unless key =~ /[\u4e00-\u9fa5]/
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
67
126
|
def handle_modify_source
|
68
|
-
UI.puts '
|
127
|
+
UI.puts '修改源码开始'
|
69
128
|
Dir.glob("#{@current_path}/**/*.{#{@modify_file_type}}").each do |f|
|
70
|
-
handle_modify_file f if File.stat(f).writable?
|
129
|
+
# handle_modify_file f if File.stat(f).writable?
|
130
|
+
if f =~ /Pods/
|
131
|
+
handle_modify_file(f) if f =~ %r{Pods/ML}
|
132
|
+
else
|
133
|
+
handle_modify_file(f)
|
134
|
+
end
|
71
135
|
end
|
72
|
-
UI.puts '
|
136
|
+
UI.puts '修改源码结束'
|
73
137
|
end
|
74
138
|
|
75
139
|
def handle_modify_file(file)
|
140
|
+
File.chmod(0o644, file)
|
76
141
|
str = modify_file_string(file)
|
77
142
|
File.open(file, 'w+') do |f|
|
78
143
|
f.write(str)
|
79
144
|
end
|
145
|
+
File.chmod(0o444, file) if file =~ /Pods/
|
80
146
|
end
|
81
147
|
|
82
148
|
def modify_file_string(file)
|
@@ -89,42 +155,36 @@ module Pod
|
|
89
155
|
str
|
90
156
|
end
|
91
157
|
|
158
|
+
def zh_ch_reg
|
159
|
+
/@"[^"]*[\u4e00-\u9fa5]+[^"]*"/
|
160
|
+
end
|
161
|
+
|
92
162
|
def modify_format_string(file, line)
|
93
163
|
result = line
|
94
|
-
result = handle_modify_line line if
|
164
|
+
result = handle_modify_line(file, line) if zh_ch_reg =~ line
|
95
165
|
result
|
96
166
|
end
|
97
167
|
|
98
|
-
def handle_modify_line(line)
|
168
|
+
def handle_modify_line(file, line)
|
99
169
|
result = line
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
170
|
+
line.scan(zh_ch_reg) do |m|
|
171
|
+
key = find_key_by_cn_val(file, m)
|
172
|
+
if key
|
173
|
+
val = format(@modify_format_string, "@\"#{key}\"")
|
174
|
+
result = result.gsub(m, val)
|
175
|
+
end
|
106
176
|
end
|
107
177
|
result
|
108
178
|
end
|
109
179
|
|
110
|
-
def find_key_by_cn_val(val)
|
180
|
+
def find_key_by_cn_val(file, val)
|
181
|
+
file_name = File.basename(file, '.*')
|
111
182
|
cn_key = val[2, val.length - 3]
|
112
|
-
index = @key_map.values.find_index
|
113
|
-
|
114
|
-
end
|
183
|
+
index = @key_map.values.find_index { |obj| cn_key.eql?(obj[:zh]) && /#{file_name}/ =~ obj[:key] }
|
184
|
+
index ||= @key_map.values.find_index { |obj| cn_key.eql?(obj[:zh]) }
|
115
185
|
@key_map.values[index][:key] if index
|
116
186
|
end
|
117
187
|
|
118
|
-
def read_csv_file
|
119
|
-
path = "#{@current_path}/#{@csv_file}.csv"
|
120
|
-
Dir.glob(path).each do |p|
|
121
|
-
CSV.foreach(p) do |row|
|
122
|
-
key = row[@key_col]
|
123
|
-
@key_map[key] = { key: key, zh: row[@cn_col], en: row[@en_col] } unless key =~ /[\u4e00-\u9fa5]/
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
188
|
def format_str(type, area = :cn)
|
129
189
|
str = ''
|
130
190
|
@key_map.each do |k, v|
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'cocoapods-lhj-bin/helpers/oss_helper'
|
2
|
+
|
3
|
+
module Pod
|
4
|
+
class Command
|
5
|
+
class Bin < Command
|
6
|
+
class Local < Bin
|
7
|
+
class Upload < Local
|
8
|
+
self.summary = '上传中英文对照csv文件'
|
9
|
+
|
10
|
+
def self.options
|
11
|
+
[
|
12
|
+
%w[--upload-file 上传中英文对照csv文件名]
|
13
|
+
]
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(argv)
|
17
|
+
@pwd_path = argv.shift_argument || Dir.pwd
|
18
|
+
@upload_csv_file = argv.option('upload-file', '*.csv')
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
def csv_file_name
|
23
|
+
file_name = @upload_csv_file
|
24
|
+
file_name = "#{@upload_csv_file}.csv" unless /.csv$/ =~ @upload_csv_file
|
25
|
+
file_name
|
26
|
+
end
|
27
|
+
|
28
|
+
def csv_oss_key(file_name)
|
29
|
+
"csv/#{Time.now.to_i}/#{file_name}"
|
30
|
+
end
|
31
|
+
|
32
|
+
def run
|
33
|
+
csv_files = File.join(@pwd_path, '**', csv_file_name)
|
34
|
+
Dir.glob(csv_files).each do |f|
|
35
|
+
file_name = File.basename(f)
|
36
|
+
oss_key = csv_oss_key file_name
|
37
|
+
CBin::OSS::Helper.instance.upload(oss_key, f)
|
38
|
+
url = CBin::OSS::Helper.instance.object_url(oss_key)
|
39
|
+
UI.puts "云端上传成功.下载Url:#{url}\n".green
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -36,12 +36,9 @@ module CBin
|
|
36
36
|
case configuration_env
|
37
37
|
when 'release_iphoneos'
|
38
38
|
file = config_release_iphoneos_file
|
39
|
-
puts "\n====== #{configuration_env} 环境 ========"
|
40
39
|
when 'debug_iphoneos'
|
41
40
|
file = config_debug_iphoneos_file
|
42
|
-
puts "\n====== #{configuration_env} 环境 ========"
|
43
41
|
when 'dev'
|
44
|
-
puts "\n====== #{configuration_env} 环境 ========"
|
45
42
|
else
|
46
43
|
raise "\n===== #{configuration_env} 参数有误,请检查%w[dev debug_iphoneos release_iphoneos]===="
|
47
44
|
end
|
@@ -19,6 +19,14 @@ module CBin
|
|
19
19
|
@bucket.put_object(key, :file => file)
|
20
20
|
end
|
21
21
|
|
22
|
+
def down_load(key, file)
|
23
|
+
@bucket.get_object(key, :file => file)
|
24
|
+
end
|
25
|
+
|
26
|
+
def object_url(key)
|
27
|
+
@bucket.object_url(key, false)
|
28
|
+
end
|
29
|
+
|
22
30
|
def list
|
23
31
|
@bucket.list_objects
|
24
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cocoapods-aomi-bin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- lihaijian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-05-
|
11
|
+
date: 2021-05-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cocoapods
|
@@ -111,14 +111,15 @@ files:
|
|
111
111
|
- lib/cocoapods-lhj-bin/command/bin/code.rb
|
112
112
|
- lib/cocoapods-lhj-bin/command/bin/config/push.rb
|
113
113
|
- lib/cocoapods-lhj-bin/command/bin/dup.rb
|
114
|
-
- lib/cocoapods-lhj-bin/command/bin/fetch.rb
|
115
114
|
- lib/cocoapods-lhj-bin/command/bin/import.rb
|
116
115
|
- lib/cocoapods-lhj-bin/command/bin/init.rb
|
117
116
|
- lib/cocoapods-lhj-bin/command/bin/initHotKey.rb
|
118
117
|
- lib/cocoapods-lhj-bin/command/bin/install.rb
|
119
118
|
- lib/cocoapods-lhj-bin/command/bin/lhj.rb
|
120
119
|
- lib/cocoapods-lhj-bin/command/bin/lib/lint.rb
|
121
|
-
- lib/cocoapods-lhj-bin/command/bin/local.rb
|
120
|
+
- lib/cocoapods-lhj-bin/command/bin/local/fetch.rb
|
121
|
+
- lib/cocoapods-lhj-bin/command/bin/local/local.rb
|
122
|
+
- lib/cocoapods-lhj-bin/command/bin/local/upload.rb
|
122
123
|
- lib/cocoapods-lhj-bin/command/bin/oss/del.rb
|
123
124
|
- lib/cocoapods-lhj-bin/command/bin/oss/list.rb
|
124
125
|
- lib/cocoapods-lhj-bin/command/bin/repo/update.rb
|
@@ -1,68 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'csv'
|
4
|
-
|
5
|
-
module Pod
|
6
|
-
class Command
|
7
|
-
class Bin < Command
|
8
|
-
class Fetch < Bin
|
9
|
-
self.summary = '提取源码的中文字符串,并生成中英文对照csv文件'
|
10
|
-
|
11
|
-
def self.options
|
12
|
-
[
|
13
|
-
%w[--file-type 从文件扩展名中查找中文字符串,默认为m,h],
|
14
|
-
%w[--file-name 生成csv文件名,默认为gen_cn_key.csv]
|
15
|
-
]
|
16
|
-
end
|
17
|
-
|
18
|
-
def initialize(argv)
|
19
|
-
@current_path = argv.shift_argument || Dir.pwd
|
20
|
-
@file_type = argv.option('file-type', 'm,h')
|
21
|
-
@file_name = argv.option('file-name', 'gen_cn_key.csv')
|
22
|
-
@cn_keys = []
|
23
|
-
super
|
24
|
-
end
|
25
|
-
|
26
|
-
def run
|
27
|
-
handle_files
|
28
|
-
gen_csv
|
29
|
-
end
|
30
|
-
|
31
|
-
def gen_csv
|
32
|
-
file = File.join(@current_path, @file_name)
|
33
|
-
FileUtils.rm_rf(file) if File.exist?(file)
|
34
|
-
CSV.open(file, 'wb:utf-8') do |csv|
|
35
|
-
csv << %w[国际化key 中文 英文 原字符 所在文件 文件路径]
|
36
|
-
@cn_keys.each do |k|
|
37
|
-
csv << [k[:key], k[:cn], k[:en], k[:str], k[:fname], k[:dirname]]
|
38
|
-
end
|
39
|
-
end
|
40
|
-
UI.puts "生成csv文件完成.\n文件路径:#{File.absolute_path(file)}".green
|
41
|
-
end
|
42
|
-
|
43
|
-
def handle_files
|
44
|
-
Dir.glob("#{@current_path}/**/*.{#{@file_type}}").each do |f|
|
45
|
-
handle_file f
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
def handle_file(file)
|
50
|
-
File.open(file, 'r') do |f|
|
51
|
-
f.each_line do |line|
|
52
|
-
handle_line(file, line) if line =~ /@"[^"]*[\u4e00-\u9fa5]+[^"]*"/
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def handle_line(file, line)
|
58
|
-
reg = /@"[^"]*[\u4e00-\u9fa5]+[^"]*"/
|
59
|
-
ma = reg.match(line)
|
60
|
-
str = ma[0]
|
61
|
-
key = "#{File.basename(file, '.*')}.#{rand(36**8).to_s(36)}"
|
62
|
-
@cn_keys << { key: key, cn: str[2, str.length - 3], en: '', str: str, dirname: File.dirname(file),
|
63
|
-
fname: File.basename(file) }
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|