cocoapods-jxedt 0.0.12 → 0.0.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.
Files changed (27) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cocoapods-jxedt/binary/Intergation.rb +18 -13
  3. data/lib/cocoapods-jxedt/binary/config.rb +62 -0
  4. data/lib/cocoapods-jxedt/binary/helper/podfile_post_install_hook.rb +29 -0
  5. data/lib/cocoapods-jxedt/binary/hooks/CocoapodsJxedtHook.rb +6 -9
  6. data/lib/cocoapods-jxedt/binary/hooks/post_install.rb +2 -2
  7. data/lib/cocoapods-jxedt/binary/hooks/pre_install.rb +30 -10
  8. data/lib/cocoapods-jxedt/binary/main.rb +1 -0
  9. data/lib/cocoapods-jxedt/binary/pod-room/framework.rb +40 -0
  10. data/lib/cocoapods-jxedt/binary/pod-room/xcodebuild_command.rb +79 -1
  11. data/lib/cocoapods-jxedt/binary/pod-room/xcodebuild_raw.rb +1 -1
  12. data/lib/cocoapods-jxedt/binary/prebuild.rb +92 -14
  13. data/lib/cocoapods-jxedt/command/binary/binary.rb +36 -0
  14. data/lib/cocoapods-jxedt/command/binary/command/build.rb +84 -0
  15. data/lib/cocoapods-jxedt/command/binary/command/clean.rb +101 -0
  16. data/lib/cocoapods-jxedt/command/binary/command/fetch.rb +36 -0
  17. data/lib/cocoapods-jxedt/command/binary/command/push.rb +41 -0
  18. data/lib/cocoapods-jxedt/command/binary/command/statistics.rb +104 -0
  19. data/lib/cocoapods-jxedt/command/jxedt.rb +1 -1
  20. data/lib/cocoapods-jxedt/command/options/options.rb +85 -2
  21. data/lib/cocoapods-jxedt/gem_version.rb +1 -1
  22. data/lib/cocoapods-jxedt/git_helper/cache_fetcher.rb +34 -0
  23. data/lib/cocoapods-jxedt/git_helper/cache_pucher.rb +42 -0
  24. data/lib/cocoapods-jxedt/git_helper/git_command.rb +48 -0
  25. data/lib/cocoapods-jxedt/git_helper/zip.rb +22 -0
  26. metadata +14 -3
  27. data/lib/cocoapods-jxedt/command/statistics/statistics.rb +0 -98
@@ -0,0 +1,84 @@
1
+ module Pod
2
+ class Command
3
+ class JxedtCommand < Command
4
+ class Binary < JxedtCommand
5
+ class Build < Binary
6
+ self.summary = '组件编译成二进制'
7
+ self.description = <<-DESC
8
+ 统计二进制组件
9
+ DESC
10
+ self.command = 'build'
11
+ self.arguments = [
12
+ ]
13
+ def self.options
14
+ [
15
+ ['--name', '编译的组件name,多个以,分隔'],
16
+ ['--output-path', '编译的二进制文件输出路径'],
17
+ ['--push', 'prebuild frameworks push origin.'],
18
+ ['--force-push', 'force push generated frameworks']
19
+ ]
20
+ end
21
+ def initialize(argv)
22
+ @names = argv.option('name', '').split(',')
23
+ @output_path = argv.option('output-path')
24
+ @force_push = argv.flag?('force-push', false)
25
+ @should_push = argv.flag?('push', false) || @force_push
26
+ super
27
+ end
28
+
29
+ def validate!
30
+ super
31
+ end
32
+
33
+ def run
34
+ podfile = Pod::Config.instance.podfile
35
+ lockfile = Pod::Config.instance.lockfile
36
+ sandbox = Pod::Config.instance.sandbox
37
+ help! '请检查命令执行路径,需要在Podfile文件所在目录执行' if podfile.nil? || lockfile.nil? || sandbox.nil?
38
+
39
+ # 修改config配置
40
+ options = {
41
+ :keep_source_project => true, # 保留源码工程
42
+ }
43
+ Jxedt.config.dsl_config.merge!(options)
44
+
45
+ require 'cocoapods-jxedt/binary/helper/target_definition'
46
+ require 'cocoapods-jxedt/binary/helper/prebuild_sandbox'
47
+ require 'cocoapods-jxedt/binary/helper/podfile_post_install_hook'
48
+
49
+ # 获取原始的installer对象,必须先获取对象
50
+ prebuild_sandbox = Pod::PrebuildSandbox.from_standard_sandbox(sandbox)
51
+ source_installer = Pod::Installer.new(prebuild_sandbox, podfile, lockfile)
52
+ # 执行install
53
+ source_installer.install!
54
+
55
+ # 保存首次`pod install`的lockfile结果,用来验证二进制文件和后面做结果校验
56
+ sandbox.source_lockfile = prebuild_sandbox.source_lockfile = source_installer.lockfile
57
+
58
+ require 'cocoapods-jxedt/binary/helper/podfile_options'
59
+ require 'cocoapods-jxedt/binary/prebuild'
60
+
61
+ # prebuild_job
62
+ prebuild_sandbox.link_source_project!
63
+ log_section "🚀 Prebuild frameworks"
64
+ # 默认放在Pods源码工程同级目录下
65
+ @output_path = prebuild_sandbox.project_path.parent + '.command_build' if @output_path.nil?
66
+ build_targets = Jxedt::Prebuild.new(source_installer).build_targets :names => @names, :binary_output => @output_path
67
+ if @should_push && Jxedt.config.cache_repo_enabled?
68
+ require 'cocoapods-jxedt/git_helper/cache_pucher'
69
+ output_dir = Pathname.new(@output_path)
70
+ Jxedt::CachePucher.push(output_dir, build_targets, @force_push)
71
+ end
72
+ prebuild_sandbox.clean_source_project!
73
+ end
74
+
75
+ def log_section(message)
76
+ Pod::UI.puts "-----------------------------------------"
77
+ Pod::UI.puts message
78
+ Pod::UI.puts "-----------------------------------------"
79
+ end
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,101 @@
1
+ module Pod
2
+ class Command
3
+ class JxedtCommand < Command
4
+ class Clean < JxedtCommand
5
+ class Fecth < Binary
6
+ self.summary = 'clean cache repo.'
7
+ self.description = <<-DESC
8
+ clean cache repo.
9
+ DESC
10
+ self.command = 'clean'
11
+ self.arguments = [
12
+ ]
13
+ def self.options
14
+ [
15
+ ['--name', 'Remove the file with the corresponding name.'],
16
+ ['--local', 'Remove local cache.'],
17
+ ['--all', 'Remove all files.'],
18
+ ]
19
+ end
20
+ def initialize(argv)
21
+ @names = argv.option('name', '').split(',')
22
+ @local = argv.flag?('local', false)
23
+ @all = argv.flag?('all', false)
24
+ super
25
+ end
26
+
27
+ def validate!
28
+ help! "Please enter the necessary options." if @names.empty? && !@all
29
+ super
30
+ end
31
+
32
+ def run
33
+ podfile = Pod::Config.instance.podfile
34
+ help! '请检查命令执行路径,需要在Podfile文件所在目录执行' if podfile.nil?
35
+
36
+ require 'cocoapods-jxedt/git_helper/git_command'
37
+
38
+ repo = Jxedt.config.git_remote_repo
39
+ cache_path = Jxedt.config.git_cache_path
40
+ branch = Jxedt.config.cache_branch
41
+
42
+ local_cache_dir = Pod::Config.instance.sandbox.root + Jxedt.config.binary_dir
43
+
44
+ commander = nil
45
+ commander = Jxedt::GitCommand.new(cache_path) if !@local && Jxedt.config.cache_repo_enabled?
46
+ # fetch
47
+ commander.git_fetch(repo, branch) if commander
48
+
49
+ if @names.size > 0
50
+ local_deleted, remote_deleted = [], []
51
+ @names.each do |name|
52
+ local_cache = local_cache_dir + name
53
+ if local_cache.exist?
54
+ local_cache.rmtree
55
+ local_deleted << name
56
+ end
57
+
58
+ if commander
59
+ remote_cache_dir = Pathname.new(cache_path) + "GeneratedFrameworks"
60
+ remote_cache = remote_cache_dir + name
61
+ if remote_cache.exist?
62
+ remote_cache.rmtree
63
+ remote_deleted << name
64
+ end
65
+ end
66
+ end
67
+ # push
68
+ commander.git_commit_and_push(branch) if commander && remote_deleted.size > 0
69
+ UI.puts "⚠️ ⚠️ ⚠️ 本地缓存文件已清除: #{local_deleted}" if local_deleted.size > 0
70
+ UI.puts "⚠️ ⚠️ ⚠️ 远程缓存文件已清除: #{remote_deleted}" if remote_deleted.size > 0
71
+ else
72
+ random = (0...10).map { (97 + rand(26)).chr }.join
73
+ input = get_stdin("你确认要清除所有缓存吗?包括远程仓库的缓存。确认请输入: #{random}")
74
+ help! "输入错误,自动退出。" if random != input
75
+
76
+ local_cache_dir.rmtree if local_cache_dir.exist?
77
+
78
+ if commander
79
+ remote_cache_dir = Pathname.new(cache_path) + "GeneratedFrameworks"
80
+ if remote_cache_dir.exist?
81
+ remote_cache_dir.rmtree
82
+ # push
83
+ commander.git_commit_and_push(branch)
84
+ end
85
+ end
86
+ UI.puts "⚠️ ⚠️ ⚠️ 所有缓存文件已清除"
87
+ end
88
+
89
+ end
90
+
91
+ def get_stdin(message)
92
+ UI.puts "#{message}".red
93
+ print "请输入--> ".green
94
+ val = STDIN.gets.chomp.strip
95
+ val
96
+ end
97
+ end
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,36 @@
1
+ module Pod
2
+ class Command
3
+ class JxedtCommand < Command
4
+ class Binary < JxedtCommand
5
+ class Fecth < Binary
6
+ self.summary = 'fetch cache repo.'
7
+ self.description = <<-DESC
8
+ fetch cache repo.
9
+ DESC
10
+ self.command = 'fetch'
11
+ self.arguments = [
12
+ ]
13
+ def self.options
14
+ []
15
+ end
16
+ def initialize(argv)
17
+ super
18
+ end
19
+
20
+ def validate!
21
+ super
22
+ end
23
+
24
+ def run
25
+ podfile = Pod::Config.instance.podfile
26
+ help! '请检查命令执行路径,需要在Podfile文件所在目录执行' if podfile.nil?
27
+ help! '你需要在cache_repo中配置正确的git仓库地址!' unless Jxedt.config.cache_repo_enabled?
28
+
29
+ require 'cocoapods-jxedt/git_helper/cache_fetcher'
30
+ Jxedt::CacheFetcher.fetch
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,41 @@
1
+ module Pod
2
+ class Command
3
+ class JxedtCommand < Command
4
+ class Binary < JxedtCommand
5
+ class Push < Binary
6
+ self.summary = 'sync local files to git repo.'
7
+ self.description = <<-DESC
8
+ sync local files to git repo.
9
+ DESC
10
+ self.command = 'push'
11
+ self.arguments = [
12
+ ]
13
+ def self.options
14
+ [
15
+ ['--force-push', 'force push generated frameworks']
16
+ ]
17
+ end
18
+ def initialize(argv)
19
+ @force_push = argv.flag?('force-push', false)
20
+ super
21
+ end
22
+
23
+ def validate!
24
+ super
25
+ end
26
+
27
+ def run
28
+ podfile = Pod::Config.instance.podfile
29
+ help! '请检查命令执行路径,需要在Podfile文件所在目录执行' if podfile.nil?
30
+ help! '你需要在cache_repo中配置正确的git仓库地址!' unless Jxedt.config.cache_repo_enabled?
31
+
32
+ require 'cocoapods-jxedt/git_helper/cache_pucher'
33
+
34
+ output_dir = Pod::Config.instance.sandbox.root + Jxedt.config.binary_dir
35
+ Jxedt::CachePucher.push(output_dir, nil, @force_push)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,104 @@
1
+ module Pod
2
+ class Command
3
+ class JxedtCommand < Command
4
+ class Binary < JxedtCommand
5
+ class Statistics < Binary
6
+ self.summary = '统计二进制使用情况'
7
+ self.description = <<-DESC
8
+ 统计二进制使用详情
9
+ DESC
10
+ self.command = 'statistics'
11
+ self.arguments = [
12
+ ]
13
+ def self.options
14
+ [
15
+ ['--failed', '统计校验失败的二进制'],
16
+ ]
17
+ end
18
+ def initialize(argv)
19
+ @check_failed = argv.flag?('failed')
20
+ super
21
+ end
22
+
23
+ def validate!
24
+ super
25
+ end
26
+
27
+ def run
28
+ podfile = Pod::Config.instance.podfile
29
+ lockfile = Pod::Config.instance.lockfile
30
+ help! '请检查命令执行路径,需要在Podfile文件所在目录执行' if podfile.nil? || lockfile.nil?
31
+
32
+ require 'cocoapods-jxedt/binary/config'
33
+ require 'cocoapods-jxedt/binary/helper/podfile_options'
34
+
35
+ pods_root = Pathname.new(File.dirname(podfile.defined_in_file)) + "Pods"
36
+ binary_dir = pods_root + Jxedt.config.binary_dir
37
+
38
+ used_binary = []
39
+ Dir.glob("#{pods_root}/*/_Prebuild") do |file_path|
40
+ next unless File.directory?(file_path)
41
+ dir_name = File.dirname(file_path)
42
+ name = File.basename(dir_name).to_s
43
+ target_path = binary_dir + name
44
+ next unless target_path.exist? # 路径不存在,跳过
45
+
46
+ new_hash = {}
47
+ # name
48
+ new_hash[:name] = name
49
+
50
+ # multiple_configuration
51
+ configuration_enable = target_path.children().select { |path| "#{path.basename}" == 'Debug' || "#{path.basename}" == 'Release' }.count == 2
52
+ new_hash[:multiple_configuration] = configuration_enable
53
+
54
+ # checksum validation
55
+ checksum_files = target_path.children().select { |path| path.extname == '.checksum' }
56
+ checksum_file = checksum_files.first
57
+ new_hash[:checksum] = checksum_file.basename.to_s.gsub('.checksum', '') unless checksum_file.nil?
58
+ new_hash[:checksum_count] = checksum_files.count
59
+
60
+ used_binary << new_hash
61
+ end
62
+
63
+ # print
64
+ index, failed = 0, []
65
+ used_binary.sort_by {|hash| hash[:name].capitalize }.each do |hash|
66
+ name = hash[:name]
67
+
68
+ checksum = lockfile.spec_checksums_hash_key(name)
69
+ validation_passed = checksum && checksum == hash[:checksum] && hash[:checksum_count] == 1
70
+ failed << name unless validation_passed
71
+
72
+ # 校验和是否用的 git commitid
73
+ checkout_options = lockfile.internal_data["CHECKOUT OPTIONS"] || {}
74
+ is_git_commitid = checkout_options[name] && checkout_options[name][:commit]
75
+
76
+ if validation_passed
77
+ next if @check_failed
78
+ index += 1
79
+ log = <<~LOG
80
+ #{index}). #{name}:
81
+ multiple configuration: #{hash[:multiple_configuration]}
82
+ checksum#{"(git commitid)" if is_git_commitid}: #{hash[:checksum]}
83
+ LOG
84
+ Pod::UI.puts log
85
+ else
86
+ index += 1
87
+ log = <<~LOG
88
+ #{index}). #{name}:
89
+ multiple configuration: #{hash[:multiple_configuration]}
90
+ checksum: #{hash[:checksum]}
91
+ checksum in lockfile#{"(git commitid)" if is_git_commitid}: #{checksum}
92
+ checksum file count: #{hash[:checksum_count]}
93
+ LOG
94
+ Pod::UI.puts log.red
95
+ end
96
+ end
97
+ Pod::UI.puts "checksum校验失败的组件: #{failed}".red if failed.size > 0
98
+ Pod::UI.puts "建议使用命令清除prebuild缓存,再重新pod install或使用pod jxedt binary build。clean命令:`pod jxedt binary clean --name=#{failed.join(',')}`".red if failed.size > 0
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
104
+ end
@@ -1,6 +1,6 @@
1
1
  require_relative 'options/options'
2
2
  require_relative 'header/header'
3
- require_relative 'statistics/statistics'
3
+ require_relative 'binary/binary'
4
4
 
5
5
  module Pod
6
6
  class Command
@@ -10,9 +10,14 @@ module Pod
10
10
  self.arguments = [
11
11
  ]
12
12
  def self.options
13
- []
13
+ [
14
+ ['--more-config', '获取cocoapods-jxedt插件的完整配置'],
15
+ ['--config', '获取cocoapods-jxedt插件的基础配置']
16
+ ]
14
17
  end
15
18
  def initialize(argv)
19
+ @config = argv.flag?('config', false)
20
+ @more_config = argv.flag?('more-config', false)
16
21
  super
17
22
  end
18
23
 
@@ -22,10 +27,88 @@ module Pod
22
27
 
23
28
  def run
24
29
  require 'cocoapods-jxedt/binary/config'
30
+
31
+ return print_options_config if @more_config
32
+ return print_base_options_config if @config
33
+
25
34
  require 'json'
26
35
 
36
+ log_section "🌹 APPLICABLE_DSL_CONFIG"
27
37
  dsl_config = Jxedt::Config::APPLICABLE_DSL_CONFIG
28
- puts JSON.pretty_generate(dsl_config)
38
+ Pod::UI.puts JSON.pretty_generate(dsl_config)
39
+
40
+ log_section "🌹 GIT_CACHE_CONFIG"
41
+ git_config = Jxedt::Config::GIT_CACHE_CONFIG
42
+ Pod::UI.puts JSON.pretty_generate(git_config)
43
+ end
44
+
45
+ def print_base_options_config
46
+ config = <<CONFIG
47
+ use_frameworks! :linkage => :static
48
+ # use_modular_headers!
49
+
50
+ plugin 'cocoapods-jxedt'
51
+ options = {
52
+ 'all_binary': true, # 所有组件开启binary
53
+ 'keep_source_project': true, # 保留源码pod工程,所在目录`Pods-Source`
54
+ 'excluded_pods': [], # 排除binary的组件名称
55
+ 'framework_header_search_enabled': true, # 兼容头文件引用`#import "xxx.h"`
56
+ 'configurations': ['Release'], # 支持的configurations ['Release', 'Debug']
57
+ 'device_build_enabled': true, # 真机
58
+ 'simulator_build_enabled': false # 模拟器
59
+ }
60
+ cocoapods_jxedt_config(options)
61
+ CONFIG
62
+ Pod::UI.puts config
63
+ end
64
+
65
+ def print_options_config
66
+ dsl_config = Jxedt::Config::APPLICABLE_DSL_CONFIG
67
+ git_config = Jxedt::Config::GIT_CACHE_CONFIG
68
+
69
+ config = <<CONFIG
70
+ use_frameworks! :linkage => :static # 插件是支持使用library的,插件会把编译后的.a生成framework。如果你的工程不支持module,可以删掉或者注释掉这一行。不影响使用
71
+ # use_modular_headers!
72
+
73
+ plugin 'cocoapods-jxedt'
74
+
75
+ # 这里默认配置了大部分常用的配置参数,只需要简单修改就可以使用了
76
+ options = {
77
+ 'all_binary': true, # #{dsl_config[:all_binary]}
78
+ 'binary_dir': '../_Prebuild', # #{dsl_config[:binary_dir]}
79
+ 'binary_switch': true, # #{dsl_config[:binary_switch]}
80
+ 'prebuild_job': true, # #{dsl_config[:prebuild_job]}
81
+ 'keep_source_project': false, # #{dsl_config[:keep_source_project]}
82
+ 'excluded_pods': [], # #{dsl_config[:excluded_pods]}
83
+ 'framework_header_search_enabled': false, # #{dsl_config[:framework_header_search_enabled]}
84
+ 'configurations': ['Release'], # #{dsl_config[:configurations]}
85
+ 'xcframework': false, # #{dsl_config[:xcframework]}
86
+ 'clean_build': true, # #{dsl_config[:clean_build]}
87
+ 'device_build_enabled': true, # #{dsl_config[:device_build_enabled]}
88
+ 'simulator_build_enabled': false, # #{dsl_config[:simulator_build_enabled]}
89
+ 'disable_resource_compilable_pods': false, # #{dsl_config[:disable_resource_compilable_pods]}
90
+ 'build_args': { # 下面是默认的配置,如果没有改动可删除节点
91
+ 'default': ["ONLY_ACTIVE_ARCH=NO", "BUILD_LIBRARY_FOR_DISTRIBUTION=YES"],
92
+ 'device': ["ARCHS='arm64'"],
93
+ 'simulator': ["ARCHS='x86_64'"]
94
+ },
95
+ 'git_cache': { # 如果不需要git缓存,直接删掉这个节点即可
96
+ 'repo': '', # #{git_config[:repo]}
97
+ 'branch': 'develop', # #{git_config[:branch]}
98
+ 'auto_fetch': true, # #{git_config[:auto_fetch]}
99
+ 'auto_push': false # #{git_config[:auto_push]}
100
+ }
101
+ }
102
+ cocoapods_jxedt_config(options)
103
+ CONFIG
104
+
105
+ Pod::UI.puts config
106
+ end
107
+
108
+ def log_section(message)
109
+ Pod::UI.puts "-----------------------------------------"
110
+ Pod::UI.puts message
111
+ Pod::UI.puts "-----------------------------------------"
29
112
  end
30
113
  end
31
114
  end
@@ -1,3 +1,3 @@
1
1
  module CocoapodsJxedt
2
- VERSION = "0.0.12"
2
+ VERSION = "0.0.13"
3
3
  end
@@ -0,0 +1,34 @@
1
+ module Jxedt
2
+ module CacheFetcher
3
+ def self.fetch
4
+ require_relative 'git_command'
5
+ repo = Jxedt.config.git_remote_repo
6
+ cache_path = Jxedt.config.git_cache_path
7
+ branch = Jxedt.config.cache_branch
8
+
9
+ commander = Jxedt::GitCommand.new(cache_path)
10
+ commander.git_fetch(repo, branch)
11
+ end
12
+
13
+ def self.sync(binary_hash, to_dir)
14
+ # fetch
15
+ fetch
16
+
17
+ require_relative 'zip'
18
+
19
+ cache_dir = Pathname.new(Jxedt.config.git_cache_path) + "GeneratedFrameworks"
20
+ to_dir = Pathname.new(to_dir)
21
+ binary_hash.each do |name, checksum|
22
+ zip_file = cache_dir + name + "#{checksum}.zip"
23
+ next unless zip_file.exist?
24
+
25
+ file_path = to_dir + name + "#{checksum}.checksum"
26
+ next if file_path.exist? # 存在同校验和的文件,跳过
27
+ file_path.parent.rmtree if file_path.parent.exist?
28
+
29
+ Jxedt::ZipUtils.unzip(zip_file, :to_dir => to_dir)
30
+ Pod::UI.puts "✅ 已从缓存下载组件#{name}, 校验和:#{checksum}".yellow
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,42 @@
1
+ module Jxedt
2
+ module CachePucher
3
+ def self.push(output_dir, targets=nil, force_push=false)
4
+ require_relative 'git_command'
5
+ require_relative 'zip'
6
+
7
+ repo = Jxedt.config.git_remote_repo
8
+ cache_path = Jxedt.config.git_cache_path
9
+ branch = Jxedt.config.cache_branch
10
+ commander = Jxedt::GitCommand.new(cache_path)
11
+ # fetch
12
+ commander.git_fetch(repo, branch)
13
+
14
+ output_dir = Pathname.new(output_dir)
15
+ approve, refuse = [], []
16
+ output_dir.children.each do |child|
17
+ next unless child.directory?
18
+ pod_name = child.basename.to_s
19
+ next if targets && targets.is_a?(Array) && !(targets.include?(pod_name))
20
+
21
+ pod_checksum = child.children.select { |ch| ch.extname == '.checksum' }.first
22
+ pod_checksum = pod_checksum.basename.sub_ext('').to_s unless pod_checksum.nil?
23
+ next if pod_checksum.nil?
24
+
25
+ to_dir = Pathname.new(cache_path) + "GeneratedFrameworks" + pod_name
26
+ to_dir.mkpath unless to_dir.exist?
27
+ zip_file = to_dir + "#{pod_checksum}.zip"
28
+ skip = zip_file.exist? && !force_push
29
+ next refuse << pod_name if skip
30
+
31
+ approve << pod_name
32
+ Jxedt::ZipUtils.zip(child.to_s, :zip_name => pod_checksum, :to_dir => to_dir)
33
+ end
34
+
35
+ # push
36
+ commander.git_commit_and_push(branch) if approve.size > 0
37
+
38
+ Pod::UI.puts "🎉 组件已缓存成功: #{approve}".yellow if approve.size > 0
39
+ Pod::UI.puts "👻 组件缓存失败,存在相同的校验和: #{refuse}".red if refuse.size > 0
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,48 @@
1
+ module Jxedt
2
+ class GitCommand
3
+ def initialize(cache_path)
4
+ @cache_path = File.expand_path(cache_path)
5
+ prepare_cache_dir
6
+ end
7
+
8
+ def prepare_cache_dir
9
+ FileUtils.mkdir_p(@cache_path) if @cache_path
10
+ end
11
+
12
+ def git(cmd, ignore_output: false, can_fail: false, git_dir: true)
13
+ comps = ["git"]
14
+ comps << "-C" << @cache_path if git_dir
15
+ comps << cmd
16
+ comps << "&> /dev/null" if ignore_output
17
+ comps << "|| true" if can_fail
18
+ cmd = comps.join(" ")
19
+ raise "Fail to run command '#{cmd}'" unless system(cmd)
20
+ end
21
+
22
+ def git_clone(cmd, options = {})
23
+ git("clone #{cmd}", :git_dir => false)
24
+ end
25
+
26
+ def git_fetch(repo, branch)
27
+ Pod::UI.puts "Fetching cache from #{repo} (branch: #{branch})".green
28
+ dest_dir = @cache_path
29
+ if Dir.exist?(dest_dir + "/.git")
30
+ git("fetch origin #{branch}")
31
+ git("checkout -f FETCH_HEAD", ignore_output: true)
32
+ git("branch -D #{branch}", ignore_output: true, can_fail: true)
33
+ git("checkout -b #{branch}")
34
+ else
35
+ FileUtils.rm_rf(dest_dir)
36
+ git_clone("--depth=1 --branch=#{branch} #{repo} #{dest_dir}")
37
+ end
38
+ end
39
+
40
+ def git_commit_and_push(branch)
41
+ commit_message = "Update prebuilt cache"
42
+ git("add .")
43
+ git("commit -m '#{commit_message}'")
44
+ git("push origin #{branch}")
45
+ end
46
+ end
47
+ end
48
+
@@ -0,0 +1,22 @@
1
+ module Jxedt
2
+ module ZipUtils
3
+ def self.zip(path, zip_name: nil, to_dir: nil)
4
+ basename = File.basename(path)
5
+ zip_name = basename if zip_name.nil?
6
+ out_path = to_dir.nil? ? "#{zip_name}.zip" : "#{to_dir}/#{zip_name}.zip"
7
+ cmd = []
8
+ cmd << "cd" << File.dirname(path)
9
+ cmd << "&& zip -r --symlinks" << out_path << basename
10
+ cmd << "&& cd -"
11
+ `#{cmd.join(" ")}`
12
+ end
13
+
14
+ def self.unzip(path, to_dir: nil)
15
+ cmd = []
16
+ cmd << "unzip -nq" << path
17
+ cmd << "-d" << to_dir unless to_dir.nil?
18
+ `#{cmd.join(" ")}`
19
+ end
20
+ end
21
+ end
22
+