cocoapods-aomi-bin 0.1.5 → 0.1.10

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: 554bc02daf76ce2c1ff292e42d014d21f20278a2514f48d799c458db509e9865
4
- data.tar.gz: f1f818abd7656a5d88996c54975a14e3f65ca31be61bf54e615917f72766b174
3
+ metadata.gz: 64f241532f973a1e5903475c7b395bda5e20c234aae56f570785f68e3e6f7911
4
+ data.tar.gz: 10b05f2cf2f632d8db9fa4298ee76f6df6b11f4eca036dded2e6c4890e4aaee9
5
5
  SHA512:
6
- metadata.gz: 87a3ff4a95188fbdcb2e22860791fba9d5e55ec6eb1a49289f09aab9f08f34ae5f76cb3aa7c650279a2b29c66ddc1c031c89527ccefc3e0fc0735f1dcf6fb09d
7
- data.tar.gz: 70cd528a6c20c68043e5fc9c51b2bc2e0f5a387250f082a92f2af899610bf523963212c950d46eea3cf86d5317de3c6ba1b2091c4f4c8e1a9baa234a4dae6ab4
6
+ metadata.gz: ffb72bdc8ae5cd1f604e4ccd03f98710f180dd15ae1a96ceb02c273f07dcf783f4a40da828ac124faafa6b234cfe81820a1ad3541d42ec8a45ebb9f0a0ce5ac1
7
+ data.tar.gz: 2a0cd1ca1db7712681c6b626f5ef87e1c5c0db90c7c0557e16670af5fd013d35e9b732b9c35e26f9f1f918569671a617f9e8c897e70608a9bdfac95389b226c6
@@ -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
@@ -20,12 +20,14 @@ module Pod
20
20
  @file_type = argv.option('file-type', 'm,h')
21
21
  @file_name = argv.option('file-name', 'gen_cn_key.csv')
22
22
  @cn_keys = []
23
+ @key_map = {}
23
24
  super
24
25
  end
25
26
 
26
27
  def run
27
28
  handle_files
28
29
  gen_csv
30
+ # update_source_header
29
31
  end
30
32
 
31
33
  def csv_file_name
@@ -38,9 +40,9 @@ module Pod
38
40
  file = File.join(@current_path, csv_file_name)
39
41
  FileUtils.rm_rf(file) if File.exist?(file)
40
42
  CSV.open(file, 'wb:utf-8') do |csv|
41
- csv << %w[国际化key 中文 英文 原字符 所在文件 文件路径]
43
+ csv << %w[国际化key 中文 英文 所在文件 文件路径]
42
44
  @cn_keys.each do |k|
43
- csv << [k[:key], k[:cn], k[:en], k[:str], k[:fname], k[:dirname]]
45
+ csv << [k[:key], k[:cn], k[:en], k[:fname], k[:dirname]]
44
46
  end
45
47
  end
46
48
  UI.puts "生成csv文件完成.\n文件路径:#{File.absolute_path(file)}".green
@@ -52,22 +54,93 @@ module Pod
52
54
  end
53
55
  end
54
56
 
57
+ def zh_ch_reg
58
+ /@"[^"]*[\u4e00-\u9fa5]+[^"]*"/
59
+ end
60
+
55
61
  def handle_file(file)
56
62
  File.open(file, 'r') do |f|
57
63
  f.each_line do |line|
58
- handle_line(file, line) if line =~ /@"[^"]*[\u4e00-\u9fa5]+[^"]*"/
64
+ handle_line(file, line) if zh_ch_reg =~ line
59
65
  end
60
66
  end
61
67
  end
62
68
 
63
69
  def handle_line(file, line)
64
- reg = /@"[^"]*[\u4e00-\u9fa5]+[^"]*"/
65
- ma = reg.match(line)
66
- str = ma[0]
67
- key = "#{File.basename(file, '.*')}.#{rand(36**8).to_s(36)}"
68
- @cn_keys << { key: key, cn: str[2, str.length - 3], en: '', str: str, dirname: File.dirname(file),
69
- fname: File.basename(file) }
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
70
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
+
71
144
  end
72
145
  end
73
146
  end
@@ -3,6 +3,7 @@
3
3
  require 'csv'
4
4
  require 'cocoapods-lhj-bin/helpers/trans_helper'
5
5
  require 'cocoapods-lhj-bin/helpers/oss_helper'
6
+ require 'cocoapods-lhj-bin/config/local_config'
6
7
 
7
8
  module Pod
8
9
  class Command
@@ -26,26 +27,26 @@ module Pod
26
27
 
27
28
  def initialize(argv)
28
29
  @current_path = argv.shift_argument || Dir.pwd
29
- @key_col = argv.option('key-col', 0).to_i
30
- @cn_col = argv.option('cn-col', 1).to_i
31
- @en_col = argv.option('en-col', 2).to_i
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
32
33
  @download_csv_files = argv.option('download-csv')
33
- @read_csv_file = argv.option('read-csv-file', '*')
34
- @gen_file_name = argv.option('gen-file', 'Localizable.strings')
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'])
35
36
  @modify_source_flag = argv.flag?('modify-source', false)
36
37
  @modify_file_type = argv.option('modify-file-type', 'm,h')
37
- @modify_format_string = argv.option('modify-format-string', 'NSLocalizedString(%s, @"")')
38
+ @modify_format_string = argv.option('modify-format-string', CBin::LocalConfig.instance.config['source_format_string'])
38
39
  @key_map = {}
39
40
  super
40
41
  end
41
42
 
42
43
  def run
43
- down_load_csv_file if @download_csv_files
44
+ down_load_csv_file if need_download
44
45
  read_csv_file
45
46
  if @key_map.keys.length.positive?
46
47
  write_en_strings
47
- write_zh_cn_strings
48
48
  write_zh_hk_strings
49
+ write_zh_cn_strings
49
50
  handle_modify_source if @modify_source_flag
50
51
  else
51
52
  UI.puts "获取中英文映射文件失败, 检查参数--read-csv-file=xx是否正常\n".red
@@ -53,21 +54,29 @@ module Pod
53
54
  end
54
55
 
55
56
  def en_dir_name
56
- 'local_gen/en.lproj'
57
+ CBin::LocalConfig.instance.config['gen_en_dir']
57
58
  end
58
59
 
59
60
  def zh_hk_dir_name
60
- 'local_gen/zh-hk.lproj'
61
+ CBin::LocalConfig.instance.config['gen_zh_hk_dir']
61
62
  end
62
63
 
63
64
  def zh_cn_dir_name
64
- 'local_gen/zh-cn.lproj'
65
+ CBin::LocalConfig.instance.config['gen_zh_cn_dir']
65
66
  end
66
67
 
67
68
  def generate_file_name
68
69
  @gen_file_name
69
70
  end
70
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
+
71
80
  def read_csv_file_name
72
81
  file_name = @read_csv_file
73
82
  file_name = "#{@read_csv_file}.csv" unless /.csv$/ =~ @read_csv_file
@@ -75,33 +84,33 @@ module Pod
75
84
  end
76
85
 
77
86
  def down_load_csv_file
78
- UI.puts '下载中英对照csv文件...'.green
79
87
  ary = get_download_keys
80
88
  ary.each do |key|
81
- file_name = key.split(%r{/})[2] || key
89
+ file_name = File.basename(key)
82
90
  file = File.join(@current_path, file_name)
83
91
  backup_csv_file file if File.exist?(file)
84
- UI.puts "下载csv文件:#{key} 到目录#{file}".green
92
+ UI.puts "下载csv文件:#{CBin::OSS::Helper.instance.object_url(key)} 到目录#{file}\n".green
85
93
  CBin::OSS::Helper.instance.down_load(key, file)
86
94
  end
95
+ UI.puts "下载云端csv文件完成 \n".green
87
96
  end
88
97
 
89
98
  def backup_csv_file(file)
90
99
  dest_file = bak_file(file)
100
+ FileUtils.mkdir_p(File.dirname(dest_file)) unless File.exist?(File.dirname(dest_file))
91
101
  UI.puts "备份csv文件:#{file} 到目录#{dest_file}".green
92
102
  FileUtils.cp file, dest_file
93
103
  FileUtils.rm_rf file
94
104
  end
95
105
 
96
106
  def bak_file(file)
97
- bak_name = "bak_#{File.basename(file)}"
98
- dest_file = File.join(File.dirname(file), bak_name)
107
+ dest_file = File.join(File.dirname(file), 'csv_bak', File.basename(file))
99
108
  File.exist?(dest_file) ? bak_file(dest_file) : dest_file
100
109
  end
101
110
 
102
111
  def get_download_keys
103
112
  download_keys = []
104
- csv_files = @download_csv_files.split(/,/).map(&:strip)
113
+ csv_files = download_cvs_str.split(/,/).map(&:strip)
105
114
  all_keys = CBin::OSS::Helper.instance.list.map(&:key)
106
115
  csv_files.each do |f|
107
116
  arr = all_keys.select { |k| %r{^csv/} =~ k && /#{f}/ =~ k }
@@ -126,16 +135,23 @@ module Pod
126
135
  def handle_modify_source
127
136
  UI.puts '修改源码开始'
128
137
  Dir.glob("#{@current_path}/**/*.{#{@modify_file_type}}").each do |f|
129
- handle_modify_file f if File.stat(f).writable?
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
130
144
  end
131
145
  UI.puts '修改源码结束'
132
146
  end
133
147
 
134
148
  def handle_modify_file(file)
149
+ File.chmod(0o644, file)
135
150
  str = modify_file_string(file)
136
151
  File.open(file, 'w+') do |f|
137
152
  f.write(str)
138
153
  end
154
+ File.chmod(0o444, file) if file =~ /Pods/
139
155
  end
140
156
 
141
157
  def modify_file_string(file)
@@ -148,33 +164,37 @@ module Pod
148
164
  str
149
165
  end
150
166
 
167
+ def zh_ch_reg
168
+ /@"[^"]*[\u4e00-\u9fa5]+[^"]*"/
169
+ end
170
+
151
171
  def modify_format_string(file, line)
152
172
  result = line
153
- result = handle_modify_line line if line =~ /@"[^"]*[\u4e00-\u9fa5]+[^"]*"/
173
+ result = handle_modify_line(file, line) if zh_ch_reg =~ line
154
174
  result
155
175
  end
156
176
 
157
- def handle_modify_line(line)
177
+ def handle_modify_line(file, line)
158
178
  result = line
159
- reg = /@"[^"]*[\u4e00-\u9fa5]+[^"]*"/
160
- ma = reg.match(line)
161
- key = find_key_by_cn_val(ma[0])
162
- if key
163
- val = format(@modify_format_string, "@\"#{key}\"")
164
- result = line.gsub(ma[0], val)
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
165
185
  end
166
186
  result
167
187
  end
168
188
 
169
- def find_key_by_cn_val(val)
189
+ def find_key_by_cn_val(file, val)
190
+ file_name = File.basename(file, '.*')
170
191
  cn_key = val[2, val.length - 3]
171
- index = @key_map.values.find_index do |obj|
172
- /^#{cn_key}$/ =~ obj[:zh]
173
- end
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]) }
174
194
  @key_map.values[index][:key] if index
175
195
  end
176
196
 
177
- def format_str(type, area = :cn)
197
+ def format_str(type, area = :origin)
178
198
  str = ''
179
199
  @key_map.each do |k, v|
180
200
  val = v[type]
@@ -209,14 +229,34 @@ module Pod
209
229
  end
210
230
 
211
231
  def write_zh_cn_strings
232
+ if CBin::LocalConfig.instance.config['gen_zh_cn']
233
+ gen_zh_cn_strings_file
234
+ else
235
+ copy_hk_to_cn_file
236
+ end
237
+ end
238
+
239
+ def gen_zh_cn_strings_file
212
240
  file = File.join(@current_path, zh_cn_dir_name, generate_file_name)
213
- generate_file(file, :zh)
241
+ area = :origin
242
+ area = :cn if CBin::LocalConfig.instance.config['trans_zh_cn']
243
+ content = format_str(:zh, area)
244
+ write_to_file(file, content)
214
245
  UI.puts "生成简体中文配置完成.文件路径:#{File.absolute_path(file)}\n".green
215
246
  end
216
247
 
248
+ def copy_hk_to_cn_file
249
+ source_file = File.join(@current_path, zh_hk_dir_name, generate_file_name)
250
+ dest_file = File.join(@current_path, zh_cn_dir_name, generate_file_name)
251
+ FileUtils.cp source_file, dest_file
252
+ UI.puts "繁体中文配置覆盖简体中文配置\n".green
253
+ end
254
+
217
255
  def write_zh_hk_strings
218
256
  file = File.join(@current_path, zh_hk_dir_name, generate_file_name)
219
- content = format_str(:zh, :hk)
257
+ area = :origin
258
+ area = :hk if CBin::LocalConfig.instance.config['trans_zh_hk']
259
+ content = format_str(:zh, area)
220
260
  write_to_file(file, content)
221
261
  UI.puts "生成繁体中文配置完成.文件路径:#{File.absolute_path(file)}\n".green
222
262
  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.5'
2
+ VERSION = '0.1.10'
3
3
  end
4
4
 
5
5
  module Pod
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.5
4
+ version: 0.1.10
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-17 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
@@ -132,6 +132,7 @@ files:
132
132
  - lib/cocoapods-lhj-bin/config/config_builder.rb
133
133
  - lib/cocoapods-lhj-bin/config/config_hot_key.rb
134
134
  - lib/cocoapods-lhj-bin/config/config_hot_key_asker.rb
135
+ - lib/cocoapods-lhj-bin/config/local_config.rb
135
136
  - lib/cocoapods-lhj-bin/gem_version.rb
136
137
  - lib/cocoapods-lhj-bin/helpers.rb
137
138
  - lib/cocoapods-lhj-bin/helpers/Info.plist