pixab 1.8.0 → 1.9.0

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: ea5e126059d8afc2bf728cbad73ebdc6daef4302d8d1eb175d25799191949f75
4
- data.tar.gz: fe311f10dbde070db2f146060bcd79c531a49c0f08d5429be5e0e36696e9d823
3
+ metadata.gz: fdba62ae7047c7ef946363083adac26824b0cb07b225e271835be82bc6665ed6
4
+ data.tar.gz: cfceb1c4a436385adf52dfc6eef0ac38d059ce0696abff97e348c2c6d4f62e15
5
5
  SHA512:
6
- metadata.gz: dc0aa68915ddc765958ec7931afe991779b4ec29559af33701b64dcd737bd7df019aee59717a16f1fcf4ef4e6f14b6f13f631bd7a93fe4a254ff9ad4d8bb5765
7
- data.tar.gz: 87b5b227fffc9666c624c92f18ff9866a5b00cef3d3e0d7d549bc6a0ce032bf139186a388368a500788b30e24b2dbf95cf3e21ae35604b2150fa854fad109c10
6
+ metadata.gz: bd569f56a0420a882377aede3a6f78ae0909ca066477a4669dc2166e7aec4c077d0f050f49ac965519bc07bd15521cb01b8f578ff279fa03ea62176c75144569
7
+ data.tar.gz: 0face14f5ad601b66713ab16432cb930e8a20637a71fad8770e34b12f989894c545997f95776a621ebdd9a1d86784e00cee7ecc7d4d8aa04093ed0291a62f84a
data/exe/pixab CHANGED
@@ -10,6 +10,7 @@ require_relative '../lib/Package.rb'
10
10
  require_relative '../lib/LocalizationSmartcat.rb'
11
11
  require_relative '../lib/LocalizationSmartcatImport.rb'
12
12
  require_relative '../lib/LocalizationSmartcatMerge.rb'
13
+ require_relative '../lib/mbox/Mbox.rb'
13
14
 
14
15
  case ARGV[0]
15
16
  when '--version'
@@ -52,6 +53,8 @@ when 'localize'
52
53
  else
53
54
  Pixab::LocalizationSmartcat.new.run(ARGV[1..-1])
54
55
  end
56
+ when 'mbox'
57
+ Pixab::Mbox.new.run(ARGV[1..-1])
55
58
  else
56
59
  puts "Invalid command".red
57
60
  end
@@ -4,14 +4,14 @@
4
4
  require "fileutils"
5
5
  require 'colored2'
6
6
  require 'open3'
7
- require_relative './Utilities.rb'
7
+ require_relative './GitUtils.rb'
8
8
  require_relative './RepoManager.rb'
9
9
 
10
10
  module Pixab
11
11
 
12
12
  class ComponentSynchronizer
13
13
 
14
- attr_accessor :is_need_build, :is_need_remote_repo, :is_need_pod_install
14
+ attr_accessor :is_need_build, :is_need_remote_repo, :is_need_pod_install, :is_use__target_branch
15
15
  attr_reader :repo_manager, :repos, :main_repo_name, :updated_repo_names
16
16
 
17
17
  def initialize(repo_manager = RepoManager.new, commands = nil)
@@ -19,6 +19,8 @@ module Pixab
19
19
  @is_need_build = false
20
20
  @is_need_remote_repo = false
21
21
  @is_need_pod_install = true
22
+ @is_use__target_branch = true
23
+
22
24
  if commands.nil?
23
25
  return
24
26
  end
@@ -31,9 +33,12 @@ module Pixab
31
33
  @is_need_remote_repo = true
32
34
  when "--no-pod-install"
33
35
  @is_need_pod_install = false
36
+ when "--current-branch"
37
+ @is_use__target_branch = false
34
38
  else
35
39
  end
36
40
  end
41
+
37
42
  end
38
43
 
39
44
  def run
@@ -121,9 +126,14 @@ module Pixab
121
126
  repo_commite_id = {}
122
127
  repos.each do |repo|
123
128
  repo_name = repo["name"]
124
- repo_target_branch = repo["target_branch"]
129
+
125
130
  FileUtils.cd("#{repo_manager.root_path}/#{repo_name}")
126
- `git fetch origin #{repo_target_branch}`
131
+ repo_target_branch = @is_use__target_branch ? repo_target_branch = repo["target_branch"] : GitUtils.current_branch
132
+ next unless GitUtils.check_remote_branch_exists_fast("origin/#{repo_target_branch}")
133
+
134
+ stdout, status = Open3.capture2("git fetch origin #{repo_target_branch}")
135
+ next unless status.success?
136
+
127
137
  commit_id = `git log origin/#{repo_target_branch} -n 1 --pretty=format:"%H"`
128
138
  if !commit_id.nil?
129
139
  repo_commite_id[repo_name] = commit_id
@@ -199,5 +209,4 @@ module Pixab
199
209
 
200
210
  end
201
211
 
202
- end
203
-
212
+ end
data/lib/GitUtils.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  # encoding: UTF-8
3
3
 
4
+ require 'open3'
4
5
  require_relative './Utilities.rb'
5
6
 
6
7
  module Pixab
@@ -96,6 +97,39 @@ module Pixab
96
97
  return Utilities.execute_shell(commad)
97
98
  end
98
99
 
100
+ # 获取当前分支的远程分支
101
+ def current_remote_branch
102
+ local_branch = current_branch
103
+ return nil if local_branch.nil?
104
+
105
+ remote_branch, status = Open3.capture2("git for-each-ref --format='%(upstream:short)' refs/heads/#{local_branch}")
106
+ remote_branch.strip!
107
+ return nil if !status.success? || remote_branch.empty?
108
+
109
+ return nil unless check_remote_branch_exists_fast(remote_branch)
110
+ return remote_branch
111
+ rescue => e
112
+ puts "Error: get current remote branch failed, #{e.message}".red
113
+ return nil
114
+ end
115
+
116
+ # 在远程仓库检查远程分支是否存在
117
+ # remote_branch: 远程分支名称,不需要remote前缀,使用origin作为remote
118
+ def check_remote_branch_exists(remote_branch)
119
+ exisit_remote_branch, status= Open3.capture2("git ls-remote --heads origin #{remote_branch}")
120
+ return status.success? && !exisit_remote_branch.strip.empty?
121
+ rescue => e
122
+ puts "Error: check remote branch exists failed, #{e.message}".red
123
+ return false
124
+ end
125
+
126
+ # 在本地仓库检查远程分支是否存在
127
+ # remote_branch: 远程分支名称
128
+ def check_remote_branch_exists_fast(remote_branch)
129
+ exisit_remote_branch, status = Open3.capture2("git branch -r --list #{remote_branch}")
130
+ status.success? && !exisit_remote_branch.strip.empty?
131
+ end
132
+
99
133
  end
100
134
 
101
135
  class << GitUtils
@@ -6,7 +6,11 @@ module Pixab
6
6
 
7
7
  class LocalizationSmartcatImport
8
8
 
9
- attr_accessor :project, :collection, :format, :tags, :completion_state, :conflicting_values
9
+ attr_accessor :project, :collection, :format, :tags, :completion_state, :conflicting_values, :delete_file_after_import
10
+
11
+ def initialize()
12
+ @delete_file_after_import = false
13
+ end
10
14
 
11
15
  def run(commands = nil)
12
16
  commands.each_index do |index|
@@ -40,6 +44,10 @@ module Pixab
40
44
  @completion_state = commands[index + 1]
41
45
  when '--conflicting-values'
42
46
  @conflicting_values = commands[index + 1]
47
+ when '--delete-file-after-import'
48
+ @delete_file_after_import = true
49
+ when '--keep-file-after-import'
50
+ @delete_file_after_import = false
43
51
  end
44
52
  end
45
53
 
@@ -70,7 +78,9 @@ module Pixab
70
78
  import_params = generate_import_params_from_file_name(entry)
71
79
  import_id = import_localization(import_url, import_params, file_path)
72
80
  puts "#{entry} 正在上传中,上传ID:#{import_id}"
73
- File.delete(file_path) if File.exist?(file_path)
81
+ if @delete_file_after_import
82
+ File.delete(file_path) if File.exist?(file_path)
83
+ end
74
84
  end
75
85
 
76
86
  puts "\n》》》》》本地化文案上传已完成 》》》》》》》》》》\n".green
@@ -12,6 +12,8 @@ module Pixab
12
12
 
13
13
  Project_AirBrushVideo = '16cbeffd-bb6e-46e8-a32e-9c79d23a796f'
14
14
 
15
+ Project_AirBrush_test = '0dafd468-f131-4c33-91f8-66d13e1eb6f4'
16
+
15
17
  end
16
18
 
17
19
  end
@@ -8,7 +8,7 @@ module Pixab
8
8
 
9
9
  def run(commands=nil)
10
10
  download_params = []
11
- import_params = []
11
+ import_params = ["--delete-file-after-import"]
12
12
  commands.each_index do |index|
13
13
  command = commands[index]
14
14
 
data/lib/RepoManager.rb CHANGED
@@ -37,6 +37,10 @@ module Pixab
37
37
  def main_repo
38
38
  repos.first
39
39
  end
40
+
41
+ def main_repo_name
42
+ main_repo["name"]
43
+ end
40
44
 
41
45
  def sub_repos
42
46
  if repos.length > 1
@@ -47,6 +51,12 @@ module Pixab
47
51
  return []
48
52
  end
49
53
 
54
+ def sub_repo_names
55
+ sub_repos.map do |sub_repo|
56
+ sub_repo["name"]
57
+ end
58
+ end
59
+
50
60
  def feature_name
51
61
  feature["name"]
52
62
  end
@@ -0,0 +1,11 @@
1
+ module Pixab
2
+
3
+ class AirBrushProjectInfo
4
+
5
+ COMPONENT_FILE_PATH = 'AirBrushPodfiles/pix_ab_component.rb'
6
+
7
+ DEFAULT_BRANCH = 'develop'
8
+
9
+ end
10
+
11
+ end
data/lib/mbox/Mbox.rb ADDED
@@ -0,0 +1,33 @@
1
+ require_relative './MboxAdd.rb'
2
+ require_relative './MboxRemove.rb'
3
+
4
+ module Pixab
5
+
6
+ class Mbox
7
+
8
+ attr_reader :repo_manager
9
+
10
+ def initialize
11
+ @repo_manager = RepoManager.new
12
+ end
13
+
14
+ def run(commands)
15
+ if commands.empty?
16
+ puts "请输入命令".red
17
+ return
18
+ end
19
+
20
+ command = commands[0]
21
+ case command
22
+ when "add"
23
+ MboxAdd.new(repo_manager).run(commands[1..-1])
24
+ when "remove"
25
+ MboxRemove.new(repo_manager).run(commands[1..-1])
26
+ else
27
+ `mbox #{commands.join(" ")}`
28
+ end
29
+ end
30
+
31
+ end
32
+
33
+ end
@@ -0,0 +1,84 @@
1
+ require 'open3'
2
+ require_relative './AirBrushProjectInfo.rb'
3
+ require_relative '../Utilities.rb'
4
+ require_relative '../RepoManager.rb'
5
+
6
+ module Pixab
7
+
8
+ class MboxAdd
9
+
10
+ attr_reader :repo_manager
11
+
12
+ def initialize(repo_manager)
13
+ @repo_manager = repo_manager
14
+ end
15
+
16
+ def run(commands)
17
+ if commands.empty?
18
+ repo_names = get_all_sub_repo_names
19
+ if !repo_names.empty?
20
+ selected_item_names = Utilities.display_choose_list(repo_names, nil, "仓库", "请选择需要添加的仓库:", nil, nil, true)
21
+ selected_item_names.each do |repo_name|
22
+ add_repo([repo_name.strip, AirBrushProjectInfo::DEFAULT_BRANCH])
23
+ end
24
+ end
25
+ elsif commands[0] == "--all"
26
+ repo_names = get_all_sub_repo_names
27
+ repo_names.each do |repo_name|
28
+ add_repo([repo_name, AirBrushProjectInfo::DEFAULT_BRANCH])
29
+ end
30
+ else
31
+ add_repo(commands)
32
+ end
33
+
34
+ system("mbox status")
35
+
36
+ end
37
+
38
+ def add_repo(commands)
39
+ return if commands.empty?
40
+
41
+ execute_commad = "mbox add"
42
+ commands.each do |command|
43
+ execute_commad += " #{command}"
44
+ end
45
+
46
+ stdout, status = Open3.capture2(execute_commad)
47
+ if status.success?
48
+ pull_lfs_files_if_needed(commands[0])
49
+ end
50
+ end
51
+
52
+ # 获取所有的子仓名
53
+ def get_all_sub_repo_names
54
+ podfile_path = "#{@repo_manager.root_path}/#{@repo_manager.main_repo_name}/#{AirBrushProjectInfo::COMPONENT_FILE_PATH}"
55
+ podfile_content = File.read(podfile_path)
56
+ matches = podfile_content.match(/def pix_ab_component(.*?)end/m)
57
+ return [] if matches.nil?
58
+ podfile_content = matches[0]
59
+ reg = /'([^']+).+:commit => '(.+)'/
60
+ matches = podfile_content.scan(reg)
61
+ repo_names = matches.map do |match|
62
+ match[0]
63
+ end
64
+ repo_names - @repo_manager.sub_repo_names
65
+ end
66
+
67
+ # 如果使用了lfs,则拉取lfs文件
68
+ def pull_lfs_files_if_needed(repo_name)
69
+ # 使用此方法切换路径时可以避免在控制台打印路径,并在执行完成后会切换回原路径
70
+ FileUtils.cd("#{@repo_manager.root_path}/#{repo_name}") do
71
+ break unless File.exist?(".gitattributes")
72
+
73
+ file_content = File.read(".gitattributes")
74
+ break unless file_content.include?("filter=lfs")
75
+
76
+ Open3.capture3("mbox git hooks --disable")
77
+ `git lfs pull`
78
+ Open3.capture3("mbox git hooks --enable")
79
+ end
80
+ end
81
+
82
+ end
83
+
84
+ end
@@ -0,0 +1,46 @@
1
+ module Pixab
2
+
3
+ class MboxRemove
4
+
5
+ attr_reader :repo_manager
6
+
7
+ def initialize(repo_manager)
8
+ @repo_manager = repo_manager
9
+ end
10
+
11
+ def run(commands)
12
+ if commands.empty?
13
+ repo_names = @repo_manager.sub_repo_names
14
+ if !repo_names.empty?
15
+ selected_item_names = Utilities.display_choose_list(repo_names, nil, "仓库", "请选择需要移除的仓库:", nil, nil, true)
16
+ selected_item_names.each do |repo_name|
17
+ remove_repo([repo_name.strip])
18
+ end
19
+ end
20
+ elsif commands[0] == "--all"
21
+ repo_names = @repo_manager.sub_repo_names
22
+ repo_names.each do |repo_name|
23
+ remove_repo([repo_name])
24
+ end
25
+ else
26
+ remove_repo(commands)
27
+ end
28
+
29
+ system("mbox status")
30
+
31
+ end
32
+
33
+ def remove_repo(commands)
34
+ return if commands.empty?
35
+
36
+ execute_commad = "mbox remove"
37
+ commands.each do |command|
38
+ execute_commad += " #{command}"
39
+ end
40
+
41
+ `#{execute_commad}`
42
+ end
43
+
44
+ end
45
+
46
+ end
data/lib/pixab/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Pixab
4
- VERSION = "1.8.0"
4
+ VERSION = "1.9.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pixab
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.0
4
+ version: 1.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 廖再润
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-01-11 00:00:00.000000000 Z
11
+ date: 2024-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colored2
@@ -93,6 +93,10 @@ files:
93
93
  - lib/Package.rb
94
94
  - lib/RepoManager.rb
95
95
  - lib/Utilities.rb
96
+ - lib/mbox/AirBrushProjectInfo.rb
97
+ - lib/mbox/Mbox.rb
98
+ - lib/mbox/MboxAdd.rb
99
+ - lib/mbox/MboxRemove.rb
96
100
  - lib/pixab.rb
97
101
  - lib/pixab/version.rb
98
102
  - pixab.gemspec