cocoapods-aomi-bin 0.1.4 → 0.1.5

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: 554bc02daf76ce2c1ff292e42d014d21f20278a2514f48d799c458db509e9865
4
+ data.tar.gz: f1f818abd7656a5d88996c54975a14e3f65ca31be61bf54e615917f72766b174
5
5
  SHA512:
6
- metadata.gz: b48994525d355172d178eadeebfc60770f826ed25089ebe5821e6fe6e12ee6db78db8245e173eb0feb41de802bfe61e7491fd2d9d17751cb5450b5e5833be7b6
7
- data.tar.gz: 1c013f1e9ad8571db0e49fe462b7878ec293ec91b8485b00d2fbf58ecca444687a47262aa3102fcd1bb131983ec90569544262537d47ce41cde2160006b28e00
6
+ metadata.gz: 87a3ff4a95188fbdcb2e22860791fba9d5e55ec6eb1a49289f09aab9f08f34ae5f76cb3aa7c650279a2b29c66ddc1c031c89527ccefc3e0fc0735f1dcf6fb09d
7
+ data.tar.gz: 70cd528a6c20c68043e5fc9c51b2bc2e0f5a387250f082a92f2af899610bf523963212c950d46eea3cf86d5317de3c6ba1b2091c4f4c8e1a9baa234a4dae6ab4
@@ -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 中文 英文 原字符 所在文件 文件路径]
@@ -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,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
- @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')
@@ -37,6 +40,7 @@ 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
46
  write_en_strings
@@ -44,32 +48,87 @@ module Pod
44
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
+ UI.puts '下载中英对照csv文件...'.green
79
+ ary = get_download_keys
80
+ ary.each do |key|
81
+ file_name = key.split(%r{/})[2] || key
82
+ file = File.join(@current_path, file_name)
83
+ backup_csv_file file if File.exist?(file)
84
+ UI.puts "下载csv文件:#{key} 到目录#{file}".green
85
+ CBin::OSS::Helper.instance.down_load(key, file)
86
+ end
87
+ end
88
+
89
+ def backup_csv_file(file)
90
+ dest_file = bak_file(file)
91
+ UI.puts "备份csv文件:#{file} 到目录#{dest_file}".green
92
+ FileUtils.cp file, dest_file
93
+ FileUtils.rm_rf file
94
+ end
95
+
96
+ def bak_file(file)
97
+ bak_name = "bak_#{File.basename(file)}"
98
+ dest_file = File.join(File.dirname(file), bak_name)
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
129
  handle_modify_file f if File.stat(f).writable?
71
130
  end
72
- UI.puts '开始修改源码结束'
131
+ UI.puts '修改源码结束'
73
132
  end
74
133
 
75
134
  def handle_modify_file(file)
@@ -115,16 +174,6 @@ module Pod
115
174
  @key_map.values[index][:key] if index
116
175
  end
117
176
 
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
177
  def format_str(type, area = :cn)
129
178
  str = ''
130
179
  @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
@@ -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.4'
2
+ VERSION = '0.1.5'
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.5
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-17 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