cocoapods-aomi-bin 0.1.8 → 0.1.13

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: 8d60564dc2567c05414925657a0bfcc79c03e29346af7799a236e824a48b522b
4
- data.tar.gz: c58a951a5261bd33adff5d05e133385a3cc225059b103769a0fb8af333072917
3
+ metadata.gz: 5ae3af0a13e50fda02f0dc94b7167bcc90dfbaeb4dbf7e41dacbbf473adbf584
4
+ data.tar.gz: cf58dc5598b22637808983c72c38d7051d9c927aa34769c7a8cf8429c970e90a
5
5
  SHA512:
6
- metadata.gz: a21bb3fff848840bf1a72671bfc09fadec1dbf67c2103a1958a897065f6fd3d2f69332715bc0afe2e64ed4fc39f2ae3490a3a5b8c3e9eb4df155bf718b522c85
7
- data.tar.gz: 352d771b8a7731af97c00ac7f83753178f2a8d7bbab02d188d1e4f45f31246f8cb523e2b6d26167034a6766eae96a2ce83b8b95675d37a443cf8c7304898dd48
6
+ metadata.gz: 3837f523f1839690351f4d660a2735daf00bd50641175c9bf95c77f8e4c2f851ec4f171e52ebbfedcaa0fb8bffd54285493ee31443c844834700f8b1f5b4b30b
7
+ data.tar.gz: 83f0c980b2e5a8459dd4e406b86ec68fb7b6dd55e79d282659d52cd936ef6595bd391a40f47430eb3aa863a7a14fa54ee575eb392f30641764d412639b888c2a
@@ -8,6 +8,8 @@ require 'cocoapods-lhj-bin/command/bin/install'
8
8
  require 'cocoapods-lhj-bin/command/bin/import'
9
9
  require 'cocoapods-lhj-bin/command/bin/local/local'
10
10
  require 'cocoapods-lhj-bin/command/bin/local/fetch'
11
+ require 'cocoapods-lhj-bin/command/bin/local/filter'
12
+ require 'cocoapods-lhj-bin/command/bin/local/micro_service'
11
13
  require 'cocoapods-lhj-bin/command/bin/local/upload'
12
14
  require 'cocoapods-lhj-bin/command/bin/trans'
13
15
  require 'cocoapods-lhj-bin/command/bin/lhj'
@@ -18,8 +18,8 @@ module Pod
18
18
  end
19
19
 
20
20
  def push_cn_hk
21
- file = File.expand_path("#{Pod::Config.instance.home_dir}/zh2hant.yml")
22
- CBin::OSS::Helper.instance.upload('zh2hant.yml', file)
21
+ file = File.expand_path("#{Pod::Config.instance.home_dir}/localizable_config.yml")
22
+ CBin::OSS::Helper.instance.upload('localizable_config.yml', file)
23
23
  end
24
24
 
25
25
  def push
@@ -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
@@ -50,7 +50,13 @@ module Pod
50
50
 
51
51
  def handle_files
52
52
  Dir.glob("#{@current_path}/**/*.{#{@file_type}}").each do |f|
53
- handle_file f
53
+ dir_name = File.dirname(f)
54
+ if /Pods/ =~ f
55
+ mod_name = framework_name(dir_name)
56
+ handle_file f if /^ML/ =~ mod_name
57
+ else
58
+ handle_file f
59
+ end
54
60
  end
55
61
  end
56
62
 
@@ -61,7 +67,7 @@ module Pod
61
67
  def handle_file(file)
62
68
  File.open(file, 'r') do |f|
63
69
  f.each_line do |line|
64
- handle_line(file, line) if zh_ch_reg =~ line
70
+ handle_line(file, line) if zh_ch_reg =~ line && !((/DDLog/ =~ line) || (/NSLog/ =~ line))
65
71
  end
66
72
  end
67
73
  end
@@ -102,9 +108,11 @@ module Pod
102
108
  def update_source_header
103
109
  Dir.glob("#{@current_path}/**/*.{m,h}").each do |f|
104
110
  if f =~ /Pods/
105
- handler_file(f) if f =~ %r{Pods/MLF} || f =~ %r{Pods/MLU} || f =~ %r{Pods/MLN}
111
+ dir_name = File.dirname(f)
112
+ mod_name = framework_name(dir_name)
113
+ handle_file f if /^ML/ =~ mod_name
106
114
  else
107
- handler_file(f)
115
+ handler_file f
108
116
  end
109
117
  end
110
118
  end
@@ -140,7 +148,6 @@ module Pod
140
148
  end
141
149
  result
142
150
  end
143
-
144
151
  end
145
152
  end
146
153
  end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'csv'
4
+
5
+ module Pod
6
+ class Command
7
+ class Bin < Command
8
+ class Filter < Bin
9
+ self.summary = '过滤重复对象'
10
+
11
+ def initialize(argv)
12
+ @current_path = argv.shift_argument || Dir.pwd
13
+ @file_type = argv.option('file-type', 'm,h')
14
+ @file_name = argv.option('file-name', 'MaucaoLife_zh_en.csv')
15
+ @cn_keys = []
16
+ @key_map = {}
17
+ @used_keys = []
18
+ super
19
+ end
20
+
21
+ def run
22
+ fetch_keys
23
+ read_csv
24
+ gen_csv
25
+ end
26
+
27
+ def csv_file_name
28
+ file_name = @file_name
29
+ file_name = "#{@file_name}.csv" unless /.csv$/ =~ @file_name
30
+ file_name
31
+ end
32
+
33
+ def read_csv
34
+ path = File.join(@current_path, csv_file_name)
35
+ Dir.glob(path).each do |p|
36
+ CSV.foreach(p) do |row|
37
+ key = row[0]
38
+ if @used_keys.any? { |k| k.eql?(key) }
39
+ @cn_keys << { key: key, cn: row[1], en: row[2], fname: row[3], dirname: row[4] }
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ def gen_csv
46
+ file = File.join(@current_path, csv_file_name)
47
+ FileUtils.rm_rf(file) if File.exist?(file)
48
+ CSV.open(file, 'wb:utf-8') do |csv|
49
+ csv << %w[国际化key 中文 英文 所在文件 文件路径]
50
+ @cn_keys.each do |k|
51
+ csv << [k[:key], k[:cn], k[:en], k[:fname], k[:dirname]]
52
+ end
53
+ end
54
+ UI.puts "生成csv文件完成.\n文件路径:#{File.absolute_path(file)}".green
55
+ end
56
+
57
+ def fetch_keys
58
+ Dir.glob("#{@current_path}/**/*.{#{@file_type}}").each do |f|
59
+ handle_file f
60
+ end
61
+ end
62
+
63
+ def zh_ch_reg
64
+ /MLLocalizedString\([^)]+\)/
65
+ end
66
+
67
+ def handle_file(file)
68
+ File.open(file, 'r') do |f|
69
+ f.each_line do |line|
70
+ handle_line(file, line) if zh_ch_reg =~ line
71
+ end
72
+ end
73
+ end
74
+
75
+ def handle_line(file, line)
76
+ line.scan(zh_ch_reg) do |str|
77
+ str[20, str.length - 22]
78
+ @used_keys << str[20, str.length - 22]
79
+ end
80
+ end
81
+
82
+ end
83
+ end
84
+ end
85
+ 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
- read_csv_file
44
+ down_load_csv_file if need_download
45
+ read_csv
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
@@ -101,7 +110,7 @@ module Pod
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 }
@@ -113,12 +122,27 @@ module Pod
113
122
  download_keys
114
123
  end
115
124
 
116
- def read_csv_file
125
+ def read_csv
117
126
  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]/
127
+ Dir.glob(path).each do |f|
128
+ read_csv_file f
129
+ end
130
+ end
131
+
132
+ def read_csv_file(file)
133
+ key_c = CBin::LocalConfig.instance.get_col_by_name(file, 'csv_key_col')
134
+ cn_c = CBin::LocalConfig.instance.get_col_by_name(file, 'csv_cn_col')
135
+ en_c = CBin::LocalConfig.instance.get_col_by_name(file, 'csv_en_col')
136
+ trans_hk = CBin::LocalConfig.instance.get_col_by_name(file, 'trans_zh_hk')
137
+ trans_cn = CBin::LocalConfig.instance.get_col_by_name(file, 'trans_zh_cn')
138
+ CSV.foreach(file) do |row|
139
+ if row.length > 2
140
+ key = row[key_c]
141
+ cn_str = row[cn_c]
142
+ hk_str = row[cn_c]
143
+ cn_str = CBin::Trans::Helper.instance.trans_zh_cn_str(cn_str) if trans_cn
144
+ hk_str = CBin::Trans::Helper.instance.trans_zh_hk_str(hk_str) if trans_hk
145
+ @key_map[key] = { key: key, cn: cn_str, hk: hk_str, en: row[en_c] } unless key =~ /[\u4e00-\u9fa5]/
122
146
  end
123
147
  end
124
148
  end
@@ -161,7 +185,7 @@ module Pod
161
185
 
162
186
  def modify_format_string(file, line)
163
187
  result = line
164
- result = handle_modify_line(file, line) if zh_ch_reg =~ line
188
+ result = handle_modify_line(file, line) if zh_ch_reg =~ line && !((/DDLog/ =~ line) || (/NSLog/ =~ line))
165
189
  result
166
190
  end
167
191
 
@@ -185,17 +209,10 @@ module Pod
185
209
  @key_map.values[index][:key] if index
186
210
  end
187
211
 
188
- def format_str(type, area = :cn)
212
+ def format_str(type)
189
213
  str = ''
190
214
  @key_map.each do |k, v|
191
- val = v[type]
192
- case area
193
- when :hk
194
- val = CBin::Trans::Helper.instance.trans_zh_hk_str val
195
- when :cn
196
- val = CBin::Trans::Helper.instance.trans_zh_cn_str val
197
- end
198
- str += "\"#{k}\" = \"#{val}\";\n"
215
+ str += "\"#{k}\" = \"#{v[type]}\";\n"
199
216
  end
200
217
  str
201
218
  end
@@ -220,14 +237,26 @@ module Pod
220
237
  end
221
238
 
222
239
  def write_zh_cn_strings
240
+ gen_zh_cn_strings_file
241
+ end
242
+
243
+ def gen_zh_cn_strings_file
223
244
  file = File.join(@current_path, zh_cn_dir_name, generate_file_name)
224
- generate_file(file, :zh)
245
+ content = format_str(:cn)
246
+ write_to_file(file, content)
225
247
  UI.puts "生成简体中文配置完成.文件路径:#{File.absolute_path(file)}\n".green
226
248
  end
227
249
 
250
+ def copy_hk_to_cn_file
251
+ source_file = File.join(@current_path, zh_hk_dir_name, generate_file_name)
252
+ dest_file = File.join(@current_path, zh_cn_dir_name, generate_file_name)
253
+ FileUtils.cp source_file, dest_file
254
+ UI.puts "繁体中文配置覆盖简体中文配置\n".green
255
+ end
256
+
228
257
  def write_zh_hk_strings
229
258
  file = File.join(@current_path, zh_hk_dir_name, generate_file_name)
230
- content = format_str(:zh, :hk)
259
+ content = format_str(:hk)
231
260
  write_to_file(file, content)
232
261
  UI.puts "生成繁体中文配置完成.文件路径:#{File.absolute_path(file)}\n".green
233
262
  end
@@ -0,0 +1,89 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'csv'
4
+
5
+ module Pod
6
+ class Command
7
+ class Bin < Command
8
+ class Service < Bin
9
+ self.summary = '微服务名变更'
10
+
11
+ def initialize(argv)
12
+ @current_path = argv.shift_argument || Dir.pwd
13
+ @file_type = argv.option('file-type', 'm,h')
14
+ @file_name = argv.option('file-name', 'service_map.csv')
15
+ @service_map = {}
16
+ super
17
+ end
18
+
19
+ def run
20
+ read_csv
21
+ update_source
22
+ end
23
+
24
+ def read_csv
25
+ path = File.join(@current_path, csv_file_name)
26
+ Dir.glob(path).each do |p|
27
+ CSV.foreach(p) do |row|
28
+ @service_map[row[0]] = row[1] if row[0]
29
+ end
30
+ end
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 update_source
40
+ Dir.glob("#{@current_path}/**/*.{m,h}").each do |f|
41
+ if f =~ /Pods/
42
+ update_file(f) if f =~ %r{Pods/ML}
43
+ else
44
+ update_file(f)
45
+ end
46
+ end
47
+ end
48
+
49
+ def update_file(file)
50
+ File.chmod(0o644, file)
51
+ str = file_string(file)
52
+ File.open(file, 'w+') do |f|
53
+ f.write(str)
54
+ end
55
+ File.chmod(0o444, file) if file =~ /Pods/
56
+ end
57
+
58
+ def file_string(file)
59
+ str = ''
60
+ File.open(file, 'r+') do |f|
61
+ f.each_line do |line|
62
+ str += format_string(f, line)
63
+ end
64
+ end
65
+ str
66
+ end
67
+
68
+ def format_string(file, line)
69
+ result = line
70
+ if url_reg =~ line
71
+ line.scan(url_reg).flatten.each do |key|
72
+ result = result.gsub(key, @service_map[key]) if key && @service_map[key]
73
+ end
74
+ end
75
+ result
76
+ end
77
+
78
+ def url_reg
79
+ @url_key_reg ||= begin
80
+ keys = @service_map.keys.join('|')
81
+ /(#{keys})/
82
+ end
83
+ @url_key_reg
84
+ end
85
+
86
+ end
87
+ end
88
+ end
89
+ end
@@ -0,0 +1,57 @@
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
+ syn_config_file unless File.exist?(config_file)
37
+ YAML.load_file(config_file)
38
+ end
39
+
40
+ def get_col_by_name(file_name, col_name = 'csv_key_col')
41
+ m = config
42
+ col = m[col_name]
43
+ fo = m['read_targets'].find{ |o| /#{o['csv_file']}/ =~ file_name }
44
+ col = fo[col_name] if fo
45
+ col
46
+ end
47
+
48
+ def config
49
+ @config ||= load_config
50
+ end
51
+
52
+ def self.instance
53
+ @instance ||= new
54
+ end
55
+
56
+ end
57
+ end
@@ -1,5 +1,5 @@
1
1
  module CBin
2
- VERSION = '0.1.8'
2
+ VERSION = '0.1.13'
3
3
  end
4
4
 
5
5
  module Pod
@@ -19,8 +19,8 @@ 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)
22
+ def down_load(key, file, &block)
23
+ @bucket.get_object(key, :file => file, &block)
24
24
  end
25
25
 
26
26
  def object_url(key)
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.8
4
+ version: 0.1.13
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-19 00:00:00.000000000 Z
11
+ date: 2021-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cocoapods
@@ -118,7 +118,9 @@ files:
118
118
  - lib/cocoapods-lhj-bin/command/bin/lhj.rb
119
119
  - lib/cocoapods-lhj-bin/command/bin/lib/lint.rb
120
120
  - lib/cocoapods-lhj-bin/command/bin/local/fetch.rb
121
+ - lib/cocoapods-lhj-bin/command/bin/local/filter.rb
121
122
  - lib/cocoapods-lhj-bin/command/bin/local/local.rb
123
+ - lib/cocoapods-lhj-bin/command/bin/local/micro_service.rb
122
124
  - lib/cocoapods-lhj-bin/command/bin/local/upload.rb
123
125
  - lib/cocoapods-lhj-bin/command/bin/oss/del.rb
124
126
  - lib/cocoapods-lhj-bin/command/bin/oss/list.rb
@@ -132,6 +134,7 @@ files:
132
134
  - lib/cocoapods-lhj-bin/config/config_builder.rb
133
135
  - lib/cocoapods-lhj-bin/config/config_hot_key.rb
134
136
  - lib/cocoapods-lhj-bin/config/config_hot_key_asker.rb
137
+ - lib/cocoapods-lhj-bin/config/local_config.rb
135
138
  - lib/cocoapods-lhj-bin/gem_version.rb
136
139
  - lib/cocoapods-lhj-bin/helpers.rb
137
140
  - lib/cocoapods-lhj-bin/helpers/Info.plist