cocoapods-aomi-bin 0.1.2 → 0.1.7

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: ff454de568d2c55f94a01c7c5309403ce55484b1e249f93dff8e5f4d2444ba89
4
- data.tar.gz: b8d6e9bca5a8be1808ba78bfc4a9cb4fba8c0cd5dd7599a4c9f6aabbcfa02170
3
+ metadata.gz: daeba67369d05792796bf13709af702f4ed8937c74f4a66755fc02160a4cc8e9
4
+ data.tar.gz: 1f4db6b1b3609a580b14da4b6d548ec17b4fc8d16d06e1ae85f199695c65f088
5
5
  SHA512:
6
- metadata.gz: 5903c78b3823f165bd11a85cf6e31ba6563222a572f01b69b0c1233df4f846410eca99f054668a18368d03fa0fb0b0e35a19db59c8f2c673992bbe7ae63caab3
7
- data.tar.gz: 586dac7e96c3d2ccf29d089134e5c8140da29086d87e52e54196bdf1c73121a1ac89aba955b0ec3f5feb14e5e441bb0da797b29418190d3525bc3d07dc9c4beb
6
+ metadata.gz: d96eb617e47fa8bf0e399d610d8aab68a30b21fac029168a2c4839b4ae3570b839f4f71a1e518a954bff1cb822c635ec1c47d052fad147daa8e9e423930ed5c5
7
+ data.tar.gz: 94e010fbd073a784cf9a4be53e961dc922b201cd51d69bb35221c301d782b9da500902df86b4f8b0e3d3d4e29f4bbafeefaa20dc689f6e2f8923ec7bc3b28a3f
@@ -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'
@@ -28,8 +28,14 @@ module Pod
28
28
  gen_csv
29
29
  end
30
30
 
31
+ def csv_file_name
32
+ file_name = @file_name
33
+ file_name = "#{@file_name}.csv" unless /.csv$/ =~ @file_name
34
+ file_name
35
+ end
36
+
31
37
  def gen_csv
32
- file = File.join(@current_path, @file_name)
38
+ file = File.join(@current_path, csv_file_name)
33
39
  FileUtils.rm_rf(file) if File.exist?(file)
34
40
  CSV.open(file, 'wb:utf-8') do |csv|
35
41
  csv << %w[国际化key 中文 英文 原字符 所在文件 文件路径]
@@ -46,21 +52,24 @@ module Pod
46
52
  end
47
53
  end
48
54
 
55
+ def zh_ch_reg
56
+ /@"[^"]*[\u4e00-\u9fa5]+[^"]*"/
57
+ end
58
+
49
59
  def handle_file(file)
50
60
  File.open(file, 'r') do |f|
51
61
  f.each_line do |line|
52
- handle_line(file, line) if line =~ /@"[^"]*[\u4e00-\u9fa5]+[^"]*"/
62
+ handle_line(file, line) if zh_ch_reg =~ line
53
63
  end
54
64
  end
55
65
  end
56
66
 
57
67
  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) }
68
+ line.scan(zh_ch_reg) do |str|
69
+ key = "#{File.basename(file, '.*')}.#{rand(36**8).to_s(36)}"
70
+ @cn_keys << { key: key, cn: str[2, str.length - 3], en: '', str: str, dirname: File.dirname(file),
71
+ fname: File.basename(file) }
72
+ end
64
73
  end
65
74
  end
66
75
  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-file csv文件名,默认为当前目录下所有csv文件],
18
- %w[--gen-file 生成配置文件名,默认名为: Localizable.strings],
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,17 +29,18 @@ 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
- @csv_file = argv.option('csv-file', '*')
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')
34
37
  @modify_format_string = argv.option('modify-format-string', 'NSLocalizedString(%s, @"")')
35
38
  @key_map = {}
36
- @cn_key_map = {}
37
39
  super
38
40
  end
39
41
 
40
42
  def run
43
+ down_load_csv_file if @download_csv_files
41
44
  read_csv_file
42
45
  if @key_map.keys.length.positive?
43
46
  write_en_strings
@@ -45,32 +48,87 @@ module Pod
45
48
  write_zh_hk_strings
46
49
  handle_modify_source if @modify_source_flag
47
50
  else
48
- UI.puts "获取中英文映射文件失败, 检查参数--csv-file=xx是否正常\n".red
51
+ UI.puts "获取中英文映射文件失败, 检查参数--read-csv-file=xx是否正常\n".red
49
52
  end
50
53
  end
51
54
 
52
55
  def en_dir_name
53
- 'en.lproj'
56
+ 'local_gen/en.lproj'
54
57
  end
55
58
 
56
59
  def zh_hk_dir_name
57
- 'zh-hk.lproj'
60
+ 'local_gen/zh-hk.lproj'
58
61
  end
59
62
 
60
63
  def zh_cn_dir_name
61
- 'zh-cn.lproj'
64
+ 'local_gen/zh-cn.lproj'
62
65
  end
63
66
 
64
67
  def generate_file_name
65
68
  @gen_file_name
66
69
  end
67
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
+
68
126
  def handle_modify_source
69
- UI.puts '开始修改源码开始'
127
+ UI.puts '修改源码开始'
70
128
  Dir.glob("#{@current_path}/**/*.{#{@modify_file_type}}").each do |f|
71
129
  handle_modify_file f if File.stat(f).writable?
72
130
  end
73
- UI.puts '开始修改源码结束'
131
+ UI.puts '修改源码结束'
74
132
  end
75
133
 
76
134
  def handle_modify_file(file)
@@ -90,40 +148,34 @@ module Pod
90
148
  str
91
149
  end
92
150
 
151
+ def zh_ch_reg
152
+ /@"[^"]*[\u4e00-\u9fa5]+[^"]*"/
153
+ end
154
+
93
155
  def modify_format_string(file, line)
94
156
  result = line
95
- result = handle_modify_line line if line =~ /@"[^"]*[\u4e00-\u9fa5]+[^"]*"/
157
+ result = handle_modify_line(file, line) if zh_ch_reg =~ line
96
158
  result
97
159
  end
98
160
 
99
- def handle_modify_line(line)
161
+ def handle_modify_line(file, line)
100
162
  result = line
101
- reg = /@"[^"]*[\u4e00-\u9fa5]+[^"]*"/
102
- ma = reg.match(line)
103
- key = find_key_by_cn_val(ma[0])
104
- if key
105
- val = format(@modify_format_string, "@\"#{key}\"")
106
- result = line.gsub(ma[0], val)
163
+ line.scan(zh_ch_reg) do |m|
164
+ key = find_key_by_cn_val(file, m)
165
+ if key
166
+ val = format(@modify_format_string, "@\"#{key}\"")
167
+ result = result.gsub(m, val)
168
+ end
107
169
  end
108
170
  result
109
171
  end
110
172
 
111
- def find_key_by_cn_val(val)
173
+ def find_key_by_cn_val(file, val)
174
+ file_name = File.basename(file, '.*')
112
175
  cn_key = val[2, val.length - 3]
113
- @cn_key_map[cn_key]
114
- end
115
-
116
- def read_csv_file
117
- path = "#{@current_path}/#{@csv_file}.csv"
118
- Dir.glob(path).each do |p|
119
- CSV.foreach(p) do |row|
120
- key = row[@key_col]
121
- unless key =~ /[\u4e00-\u9fa5]/
122
- @key_map[key] = { zh: row[@cn_col], en: row[@en_col] }
123
- @cn_key_map[row[@cn_col]] = key
124
- end
125
- end
126
- end
176
+ index = @key_map.values.find_index { |obj| /^#{cn_key}$/ =~ obj[:zh] && /^#{file_name}/ =~ obj[:key] }
177
+ index ||= @key_map.values.find_index { |obj| /^#{cn_key}$/ =~ obj[:zh] }
178
+ @key_map.values[index][:key] if index
127
179
  end
128
180
 
129
181
  def format_str(type, area = :cn)
@@ -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
@@ -1,5 +1,5 @@
1
1
  module CBin
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.7'
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.2
4
+ version: 0.1.7
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-18 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