cocoapods-aomi-bin 0.1.4 → 0.1.9

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: b31cd439148cbac76a496c9217cc83c046cc3cd9467ef0fcb7d8a29e971e8394
4
- data.tar.gz: 817d39af867d6c1ad9307fb3b234fab459f244bacfb180b06e3e88a9f3fa6c81
3
+ metadata.gz: 8fc461c5e823740442cc8c083a408a4acb93360fc6363a183a5679d070c79df0
4
+ data.tar.gz: '0397bd469fb875c69681e7c5739439a923bf31ef7846386f6d07f2f63952c122'
5
5
  SHA512:
6
- metadata.gz: b48994525d355172d178eadeebfc60770f826ed25089ebe5821e6fe6e12ee6db78db8245e173eb0feb41de802bfe61e7491fd2d9d17751cb5450b5e5833be7b6
7
- data.tar.gz: 1c013f1e9ad8571db0e49fe462b7878ec293ec91b8485b00d2fbf58ecca444687a47262aa3102fcd1bb131983ec90569544262537d47ce41cde2160006b28e00
6
+ metadata.gz: c963ee1a10a974416d2cd5525f539a905e79439bbf8680a9fe2cf44bf531de1782bfbe40e96fb0aeafe911ac833d2c7a88223cbaec1ff0dfca06803004e6fcdd
7
+ data.tar.gz: 171b50fc4a031baf5414c3a9641665e790d46c5a7bf0ea530ef45ab633ad50ee5035295d2b14e8f36d015b60cac0f35749aa6c2b709aa8da66a9feb80af4276b
@@ -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'
@@ -35,9 +35,13 @@ module Pod
35
35
  require 'open-uri'
36
36
 
37
37
  UI.puts "开始下载配置文件...\n"
38
- file = open(url)
39
- contents = YAML.safe_load(file.read)
40
-
38
+ str = ''
39
+ URI.open(url) do |f|
40
+ f.each_line do |line|
41
+ str += line
42
+ end
43
+ end
44
+ contents = YAML.safe_load(str)
41
45
  UI.puts "开始同步配置文件...\n"
42
46
  CBin.config.sync_config(contents.to_hash)
43
47
  UI.puts "设置完成.\n".green
@@ -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
@@ -0,0 +1,251 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'csv'
4
+ require 'cocoapods-lhj-bin/helpers/trans_helper'
5
+ require 'cocoapods-lhj-bin/helpers/oss_helper'
6
+ require 'cocoapods-lhj-bin/config/local_config'
7
+
8
+ module Pod
9
+ class Command
10
+ class Bin < Command
11
+ class Local < Bin
12
+ self.summary = '根据中英文对照csv文件,生成国际化配置, 及批量更新源码(使用国际化写法)'
13
+
14
+ def self.options
15
+ [
16
+ %w[--key-col 国际化key在csv中第几列,默认为0],
17
+ %w[--cn-col 中文在csv中第几列,默认为1],
18
+ %w[--en-col 英文在csv中第几列,默认为2],
19
+ %w[--download-csv 云端下载cvs的文件名],
20
+ %w[--read-csv-file 读取csv的文件名,默认为当前目录下所有csv文件],
21
+ %w[--gen-file 生成配置文件名,默认名为:Localizable.strings],
22
+ %w[--modify-source 修改源码,使用国际化key代替中文字符串],
23
+ %w[--modify-file-type 需要修改源码的文件类型,默认为m,h],
24
+ %w[--modify-format-string 修改为国际化后的字符格式,默认为NSLocalizedString(%s,@"")]
25
+ ]
26
+ end
27
+
28
+ def initialize(argv)
29
+ @current_path = argv.shift_argument || Dir.pwd
30
+ @key_col = argv.option('key-col', CBin::LocalConfig.instance.config['csv_key_col']).to_i
31
+ @cn_col = argv.option('cn-col', CBin::LocalConfig.instance.config['csv_cn_col']).to_i
32
+ @en_col = argv.option('en-col', CBin::LocalConfig.instance.config['csv_en_col']).to_i
33
+ @download_csv_files = argv.option('download-csv')
34
+ @read_csv_file = argv.option('read-csv-file', CBin::LocalConfig.instance.config['read_csv_file'])
35
+ @gen_file_name = argv.option('gen-file', CBin::LocalConfig.instance.config['gen_file_name'])
36
+ @modify_source_flag = argv.flag?('modify-source', false)
37
+ @modify_file_type = argv.option('modify-file-type', 'm,h')
38
+ @modify_format_string = argv.option('modify-format-string', CBin::LocalConfig.instance.config['source_format_string'])
39
+ @key_map = {}
40
+ super
41
+ end
42
+
43
+ def run
44
+ down_load_csv_file if need_download
45
+ read_csv_file
46
+ if @key_map.keys.length.positive?
47
+ write_en_strings
48
+ write_zh_cn_strings if CBin::LocalConfig.instance.config['gen_zh_cn']
49
+ write_zh_hk_strings
50
+ handle_modify_source if @modify_source_flag
51
+ else
52
+ UI.puts "获取中英文映射文件失败, 检查参数--read-csv-file=xx是否正常\n".red
53
+ end
54
+ end
55
+
56
+ def en_dir_name
57
+ CBin::LocalConfig.instance.config['gen_en_dir']
58
+ end
59
+
60
+ def zh_hk_dir_name
61
+ CBin::LocalConfig.instance.config['gen_zh_hk_dir']
62
+ end
63
+
64
+ def zh_cn_dir_name
65
+ CBin::LocalConfig.instance.config['gen_zh_cn_dir']
66
+ end
67
+
68
+ def generate_file_name
69
+ @gen_file_name
70
+ end
71
+
72
+ def need_download
73
+ @download_csv_files || CBin::LocalConfig.instance.config['download']
74
+ end
75
+
76
+ def download_cvs_str
77
+ @download_csv_files || CBin::LocalConfig.instance.config['download_csv']
78
+ end
79
+
80
+ def read_csv_file_name
81
+ file_name = @read_csv_file
82
+ file_name = "#{@read_csv_file}.csv" unless /.csv$/ =~ @read_csv_file
83
+ file_name
84
+ end
85
+
86
+ def down_load_csv_file
87
+ ary = get_download_keys
88
+ ary.each do |key|
89
+ file_name = File.basename(key)
90
+ file = File.join(@current_path, file_name)
91
+ backup_csv_file file if File.exist?(file)
92
+ UI.puts "下载csv文件:#{CBin::OSS::Helper.instance.object_url(key)} 到目录#{file}\n".green
93
+ CBin::OSS::Helper.instance.down_load(key, file)
94
+ end
95
+ UI.puts "下载云端csv文件完成 \n".green
96
+ end
97
+
98
+ def backup_csv_file(file)
99
+ dest_file = bak_file(file)
100
+ FileUtils.mkdir_p(File.dirname(dest_file)) unless File.exist?(File.dirname(dest_file))
101
+ UI.puts "备份csv文件:#{file} 到目录#{dest_file}".green
102
+ FileUtils.cp file, dest_file
103
+ FileUtils.rm_rf file
104
+ end
105
+
106
+ def bak_file(file)
107
+ dest_file = File.join(File.dirname(file), 'csv_bak', File.basename(file))
108
+ File.exist?(dest_file) ? bak_file(dest_file) : dest_file
109
+ end
110
+
111
+ def get_download_keys
112
+ download_keys = []
113
+ csv_files = download_cvs_str.split(/,/).map(&:strip)
114
+ all_keys = CBin::OSS::Helper.instance.list.map(&:key)
115
+ csv_files.each do |f|
116
+ arr = all_keys.select { |k| %r{^csv/} =~ k && /#{f}/ =~ k }
117
+ if arr.count.positive?
118
+ arr.sort! { |a, b| b.split(%r{/})[1].to_i <=> a.split(%r{/})[1].to_i }
119
+ download_keys << arr[0]
120
+ end
121
+ end
122
+ download_keys
123
+ end
124
+
125
+ def read_csv_file
126
+ path = File.join(@current_path, read_csv_file_name)
127
+ Dir.glob(path).each do |p|
128
+ CSV.foreach(p) do |row|
129
+ key = row[@key_col]
130
+ @key_map[key] = { key: key, zh: row[@cn_col], en: row[@en_col] } unless key =~ /[\u4e00-\u9fa5]/
131
+ end
132
+ end
133
+ end
134
+
135
+ def handle_modify_source
136
+ UI.puts '修改源码开始'
137
+ Dir.glob("#{@current_path}/**/*.{#{@modify_file_type}}").each do |f|
138
+ # handle_modify_file f if File.stat(f).writable?
139
+ if f =~ /Pods/
140
+ handle_modify_file(f) if f =~ %r{Pods/ML}
141
+ else
142
+ handle_modify_file(f)
143
+ end
144
+ end
145
+ UI.puts '修改源码结束'
146
+ end
147
+
148
+ def handle_modify_file(file)
149
+ File.chmod(0o644, file)
150
+ str = modify_file_string(file)
151
+ File.open(file, 'w+') do |f|
152
+ f.write(str)
153
+ end
154
+ File.chmod(0o444, file) if file =~ /Pods/
155
+ end
156
+
157
+ def modify_file_string(file)
158
+ str = ''
159
+ File.open(file, 'r') do |f|
160
+ f.each_line do |line|
161
+ str += modify_format_string(f, line)
162
+ end
163
+ end
164
+ str
165
+ end
166
+
167
+ def zh_ch_reg
168
+ /@"[^"]*[\u4e00-\u9fa5]+[^"]*"/
169
+ end
170
+
171
+ def modify_format_string(file, line)
172
+ result = line
173
+ result = handle_modify_line(file, line) if zh_ch_reg =~ line
174
+ result
175
+ end
176
+
177
+ def handle_modify_line(file, line)
178
+ result = line
179
+ line.scan(zh_ch_reg) do |m|
180
+ key = find_key_by_cn_val(file, m)
181
+ if key
182
+ val = format(@modify_format_string, "@\"#{key}\"")
183
+ result = result.gsub(m, val)
184
+ end
185
+ end
186
+ result
187
+ end
188
+
189
+ def find_key_by_cn_val(file, val)
190
+ file_name = File.basename(file, '.*')
191
+ cn_key = val[2, val.length - 3]
192
+ index = @key_map.values.find_index { |obj| cn_key.eql?(obj[:zh]) && /#{file_name}/ =~ obj[:key] }
193
+ index ||= @key_map.values.find_index { |obj| cn_key.eql?(obj[:zh]) }
194
+ @key_map.values[index][:key] if index
195
+ end
196
+
197
+ def format_str(type, area = :origin)
198
+ str = ''
199
+ @key_map.each do |k, v|
200
+ val = v[type]
201
+ case area
202
+ when :hk
203
+ val = CBin::Trans::Helper.instance.trans_zh_hk_str val
204
+ when :cn
205
+ val = CBin::Trans::Helper.instance.trans_zh_cn_str val
206
+ end
207
+ str += "\"#{k}\" = \"#{val}\";\n"
208
+ end
209
+ str
210
+ end
211
+
212
+ def write_to_file(file, contents)
213
+ FileUtils.rm_rf(file) if File.exist?(file)
214
+ FileUtils.mkdir_p(File.dirname(file)) unless File.exist?(File.dirname(file))
215
+ File.open(file, 'w+') do |f|
216
+ f.write(contents)
217
+ end
218
+ end
219
+
220
+ def generate_file(file, type)
221
+ content = format_str(type)
222
+ write_to_file(file, content)
223
+ end
224
+
225
+ def write_en_strings
226
+ file = File.join(@current_path, en_dir_name, generate_file_name)
227
+ generate_file(file, :en)
228
+ UI.puts "生成英文配置完成.文件路径:#{File.absolute_path(file)}\n".green
229
+ end
230
+
231
+ def write_zh_cn_strings
232
+ file = File.join(@current_path, zh_cn_dir_name, generate_file_name)
233
+ area = :origin
234
+ area = :cn if CBin::LocalConfig.instance.config['trans_zh_cn']
235
+ content = format_str(:zh, area)
236
+ write_to_file(file, content)
237
+ UI.puts "生成简体中文配置完成.文件路径:#{File.absolute_path(file)}\n".green
238
+ end
239
+
240
+ def write_zh_hk_strings
241
+ file = File.join(@current_path, zh_hk_dir_name, generate_file_name)
242
+ area = :origin
243
+ area = :hk if CBin::LocalConfig.instance.config['trans_zh_hk']
244
+ content = format_str(:zh, area)
245
+ write_to_file(file, content)
246
+ UI.puts "生成繁体中文配置完成.文件路径:#{File.absolute_path(file)}\n".green
247
+ end
248
+ end
249
+ end
250
+ end
251
+ end
@@ -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
@@ -24,7 +24,7 @@ module Pod
24
24
  end
25
25
 
26
26
  def validate!
27
- help! "请输入key" unless @key
27
+ help! '请输入key' unless @key
28
28
  super
29
29
  end
30
30
 
@@ -8,10 +8,6 @@ module Pod
8
8
  class List < OSS
9
9
  self.summary = '查看OSS列表'
10
10
 
11
- def initialize(argv)
12
- super
13
- end
14
-
15
11
  def run
16
12
  objects = CBin::OSS::Helper.instance.list
17
13
  objects.each do |o|
@@ -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
@@ -0,0 +1,52 @@
1
+ require 'yaml'
2
+ require 'cocoapods-lhj-bin/helpers/oss_helper'
3
+
4
+ module CBin
5
+ class LocalConfig
6
+ def config_file
7
+ File.join(Pod::Config.instance.home_dir, config_file_name)
8
+ end
9
+
10
+ def config_file_name
11
+ 'localizable_config.yml'
12
+ end
13
+
14
+ def syn_config_file
15
+ CBin::OSS::Helper.instance.down_load(config_file_name, config_file)
16
+ end
17
+
18
+ def default_config
19
+ { 'gen_en_dir' => 'local_gen/en.lproj',
20
+ 'gen_zh_hk_dir' => 'local_gen/zh-Hant.lproj',
21
+ 'gen_zh_cn_dir' => 'local_gen/zh-Hans.lproj',
22
+ 'gen_file_name' => 'Localizable.strings',
23
+ 'source_format_string' => 'NSLocalizedString(%s, @"")',
24
+ 'csv_key_col' => 0,
25
+ 'csv_cn_col' => 1,
26
+ 'csv_en_col' => 2,
27
+ 'read_csv_file' => '*.csv',
28
+ 'gen_zh_cn' => true,
29
+ 'trans_zh_hk' => false,
30
+ 'trans_zh_cn' => false,
31
+ 'download' => false,
32
+ 'download_csv' => 'zh_en.csv' }
33
+ end
34
+
35
+ def load_config
36
+ if File.exist?(config_file)
37
+ YAML.load_file(config_file)
38
+ else
39
+ default_config
40
+ end
41
+ end
42
+
43
+ def config
44
+ @config ||= load_config
45
+ end
46
+
47
+ def self.instance
48
+ @instance ||= new
49
+ end
50
+
51
+ end
52
+ end
@@ -1,5 +1,5 @@
1
1
  module CBin
2
- VERSION = '0.1.4'
2
+ VERSION = '0.1.9'
3
3
  end
4
4
 
5
5
  module Pod
@@ -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
4
+ version: 0.1.9
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-14 00:00:00.000000000 Z
11
+ date: 2021-05-20 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
@@ -131,6 +132,7 @@ files:
131
132
  - lib/cocoapods-lhj-bin/config/config_builder.rb
132
133
  - lib/cocoapods-lhj-bin/config/config_hot_key.rb
133
134
  - lib/cocoapods-lhj-bin/config/config_hot_key_asker.rb
135
+ - lib/cocoapods-lhj-bin/config/local_config.rb
134
136
  - lib/cocoapods-lhj-bin/gem_version.rb
135
137
  - lib/cocoapods-lhj-bin/helpers.rb
136
138
  - lib/cocoapods-lhj-bin/helpers/Info.plist
@@ -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
@@ -1,177 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'csv'
4
- require 'cocoapods-lhj-bin/helpers/trans_helper'
5
-
6
- module Pod
7
- class Command
8
- class Bin < Command
9
- class Local < Bin
10
- self.summary = '根据中英文对照csv文件,生成国际化配置, 及批量更新源码(使用国际化写法)'
11
-
12
- def self.options
13
- [
14
- %w[--key-col 国际化key在csv中第几列,默认为0],
15
- %w[--cn-col 中文在csv中第几列,默认为1],
16
- %w[--en-col 英文在csv中第几列,默认为2],
17
- %w[--csv-file csv文件名,默认为当前目录下所有csv文件],
18
- %w[--gen-file 生成配置文件名,默认名为: Localizable.strings],
19
- %w[--modify-source 修改源码,使用国际化key代替中文字符串],
20
- %w[--modify-file-type 需要修改源码的文件类型,默认为m,h],
21
- %w[--modify-format-string 修改为国际化后的字符格式,默认为NSLocalizedString(%s, @"")]
22
- ]
23
- end
24
-
25
- def initialize(argv)
26
- @current_path = argv.shift_argument || Dir.pwd
27
- @key_col = argv.option('key-col', 0).to_i
28
- @cn_col = argv.option('cn-col', 1).to_i
29
- @en_col = argv.option('en-col', 2).to_i
30
- @csv_file = argv.option('csv-file', '*')
31
- @gen_file_name = argv.option('gen-file', 'Localizable.strings')
32
- @modify_source_flag = argv.flag?('modify-source', false)
33
- @modify_file_type = argv.option('modify-file-type', 'm,h')
34
- @modify_format_string = argv.option('modify-format-string', 'NSLocalizedString(%s, @"")')
35
- @key_map = {}
36
- super
37
- end
38
-
39
- def run
40
- read_csv_file
41
- if @key_map.keys.length.positive?
42
- write_en_strings
43
- write_zh_cn_strings
44
- write_zh_hk_strings
45
- handle_modify_source if @modify_source_flag
46
- else
47
- UI.puts "获取中英文映射文件失败, 检查参数--csv-file=xx是否正常\n".red
48
- end
49
- end
50
-
51
- def en_dir_name
52
- 'en.lproj'
53
- end
54
-
55
- def zh_hk_dir_name
56
- 'zh-hk.lproj'
57
- end
58
-
59
- def zh_cn_dir_name
60
- 'zh-cn.lproj'
61
- end
62
-
63
- def generate_file_name
64
- @gen_file_name
65
- end
66
-
67
- def handle_modify_source
68
- UI.puts '开始修改源码开始'
69
- Dir.glob("#{@current_path}/**/*.{#{@modify_file_type}}").each do |f|
70
- handle_modify_file f if File.stat(f).writable?
71
- end
72
- UI.puts '开始修改源码结束'
73
- end
74
-
75
- def handle_modify_file(file)
76
- str = modify_file_string(file)
77
- File.open(file, 'w+') do |f|
78
- f.write(str)
79
- end
80
- end
81
-
82
- def modify_file_string(file)
83
- str = ''
84
- File.open(file, 'r') do |f|
85
- f.each_line do |line|
86
- str += modify_format_string(f, line)
87
- end
88
- end
89
- str
90
- end
91
-
92
- def modify_format_string(file, line)
93
- result = line
94
- result = handle_modify_line line if line =~ /@"[^"]*[\u4e00-\u9fa5]+[^"]*"/
95
- result
96
- end
97
-
98
- def handle_modify_line(line)
99
- result = line
100
- reg = /@"[^"]*[\u4e00-\u9fa5]+[^"]*"/
101
- ma = reg.match(line)
102
- key = find_key_by_cn_val(ma[0])
103
- if key
104
- val = format(@modify_format_string, "@\"#{key}\"")
105
- result = line.gsub(ma[0], val)
106
- end
107
- result
108
- end
109
-
110
- def find_key_by_cn_val(val)
111
- cn_key = val[2, val.length - 3]
112
- index = @key_map.values.find_index do |obj|
113
- /^#{cn_key}$/ =~ obj[:zh]
114
- end
115
- @key_map.values[index][:key] if index
116
- end
117
-
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
- def format_str(type, area = :cn)
129
- str = ''
130
- @key_map.each do |k, v|
131
- val = v[type]
132
- case area
133
- when :hk
134
- val = CBin::Trans::Helper.instance.trans_zh_hk_str val
135
- when :cn
136
- val = CBin::Trans::Helper.instance.trans_zh_cn_str val
137
- end
138
- str += "\"#{k}\" = \"#{val}\";\n"
139
- end
140
- str
141
- end
142
-
143
- def write_to_file(file, contents)
144
- FileUtils.rm_rf(file) if File.exist?(file)
145
- FileUtils.mkdir_p(File.dirname(file)) unless File.exist?(File.dirname(file))
146
- File.open(file, 'w+') do |f|
147
- f.write(contents)
148
- end
149
- end
150
-
151
- def generate_file(file, type)
152
- content = format_str(type)
153
- write_to_file(file, content)
154
- end
155
-
156
- def write_en_strings
157
- file = File.join(@current_path, en_dir_name, generate_file_name)
158
- generate_file(file, :en)
159
- UI.puts "生成英文配置完成.文件路径:#{File.absolute_path(file)}\n".green
160
- end
161
-
162
- def write_zh_cn_strings
163
- file = File.join(@current_path, zh_cn_dir_name, generate_file_name)
164
- generate_file(file, :zh)
165
- UI.puts "生成简体中文配置完成.文件路径:#{File.absolute_path(file)}\n".green
166
- end
167
-
168
- def write_zh_hk_strings
169
- file = File.join(@current_path, zh_hk_dir_name, generate_file_name)
170
- content = format_str(:zh, :hk)
171
- write_to_file(file, content)
172
- UI.puts "生成繁体中文配置完成.文件路径:#{File.absolute_path(file)}\n".green
173
- end
174
- end
175
- end
176
- end
177
- end