cocoapods-miBin 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/.rakeTasks +7 -0
  4. data/Gemfile +13 -0
  5. data/Gemfile.lock +104 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +522 -0
  8. data/Rakefile +13 -0
  9. data/cocoapods-miBin.gemspec +27 -0
  10. data/lib/cocoapods-miBin.rb +4 -0
  11. data/lib/cocoapods-miBin/command.rb +3 -0
  12. data/lib/cocoapods-miBin/command/bin.rb +60 -0
  13. data/lib/cocoapods-miBin/command/bin/archive.rb +134 -0
  14. data/lib/cocoapods-miBin/command/bin/init.rb +71 -0
  15. data/lib/cocoapods-miBin/command/bin/lib.rb +14 -0
  16. data/lib/cocoapods-miBin/command/bin/lib/lint.rb +69 -0
  17. data/lib/cocoapods-miBin/command/bin/list.rb +50 -0
  18. data/lib/cocoapods-miBin/command/bin/open.rb +61 -0
  19. data/lib/cocoapods-miBin/command/bin/repo.rb +15 -0
  20. data/lib/cocoapods-miBin/command/bin/repo/push.rb +116 -0
  21. data/lib/cocoapods-miBin/command/bin/repo/update.rb +42 -0
  22. data/lib/cocoapods-miBin/command/bin/search.rb +69 -0
  23. data/lib/cocoapods-miBin/command/bin/spec.rb +15 -0
  24. data/lib/cocoapods-miBin/command/bin/spec/create.rb +75 -0
  25. data/lib/cocoapods-miBin/command/bin/spec/lint.rb +111 -0
  26. data/lib/cocoapods-miBin/command/bin/umbrella.rb +55 -0
  27. data/lib/cocoapods-miBin/config/config.rb +81 -0
  28. data/lib/cocoapods-miBin/config/config_asker.rb +58 -0
  29. data/lib/cocoapods-miBin/gem_version.rb +11 -0
  30. data/lib/cocoapods-miBin/helpers.rb +5 -0
  31. data/lib/cocoapods-miBin/helpers/framework.rb +64 -0
  32. data/lib/cocoapods-miBin/helpers/framework_builder.rb +227 -0
  33. data/lib/cocoapods-miBin/helpers/sources_helper.rb +33 -0
  34. data/lib/cocoapods-miBin/helpers/spec_creator.rb +159 -0
  35. data/lib/cocoapods-miBin/helpers/spec_files_helper.rb +77 -0
  36. data/lib/cocoapods-miBin/native.rb +21 -0
  37. data/lib/cocoapods-miBin/native/acknowledgements.rb +27 -0
  38. data/lib/cocoapods-miBin/native/analyzer.rb +53 -0
  39. data/lib/cocoapods-miBin/native/installation_options.rb +26 -0
  40. data/lib/cocoapods-miBin/native/installer.rb +116 -0
  41. data/lib/cocoapods-miBin/native/linter.rb +26 -0
  42. data/lib/cocoapods-miBin/native/path_source.rb +33 -0
  43. data/lib/cocoapods-miBin/native/pod_source_installer.rb +19 -0
  44. data/lib/cocoapods-miBin/native/pod_target.rb +8 -0
  45. data/lib/cocoapods-miBin/native/podfile.rb +79 -0
  46. data/lib/cocoapods-miBin/native/podfile_env.rb +36 -0
  47. data/lib/cocoapods-miBin/native/podspec_finder.rb +25 -0
  48. data/lib/cocoapods-miBin/native/resolver.rb +200 -0
  49. data/lib/cocoapods-miBin/native/sandbox_analyzer.rb +34 -0
  50. data/lib/cocoapods-miBin/native/source.rb +35 -0
  51. data/lib/cocoapods-miBin/native/sources_manager.rb +20 -0
  52. data/lib/cocoapods-miBin/native/specification.rb +31 -0
  53. data/lib/cocoapods-miBin/native/validator.rb +16 -0
  54. data/lib/cocoapods-miBin/source_provider_hook.rb +21 -0
  55. data/lib/cocoapods_plugin.rb +5 -0
  56. data/spec/command/bin_spec.rb +12 -0
  57. data/spec/spec_helper.rb +50 -0
  58. metadata +173 -0
@@ -0,0 +1,13 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ def specs(dir)
4
+ FileList["spec/#{dir}/*_spec.rb"].shuffle.join(' ')
5
+ end
6
+
7
+ desc 'Runs all the specs'
8
+ task :specs do
9
+ sh "bundle exec bacon #{specs('**')}"
10
+ end
11
+
12
+ task :default => :specs
13
+
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cocoapods-miBin/gem_version.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'cocoapods-miBin'
8
+ spec.version = CBin::VERSION
9
+ spec.authors = ['zhangyanbin']
10
+ spec.email = ['zhangyanbin@xiaomi.com']
11
+ spec.description = %q{cocoapods-miBin is a plugin which helps develpers switching pods between source code and binary.}
12
+ spec.summary = %q{cocoapods-miBin is a plugin which helps develpers switching pods between source code and binary.}
13
+ spec.homepage = 'https://github.com/zhangjianbin/cocoapods-bin.git'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'parallel'
22
+ spec.add_dependency 'cocoapods', '~> 1.4'
23
+ spec.add_dependency 'cocoapods-generate', '~> 1.4'
24
+
25
+ spec.add_development_dependency 'bundler', '~> 1.3'
26
+ spec.add_development_dependency 'rake'
27
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cocoapods-miBin/gem_version'
4
+ require 'cocoapods-miBin/native/sources_manager'
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cocoapods-miBin/command/bin'
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cocoapods-miBin/command/bin/init'
4
+ require 'cocoapods-miBin/command/bin/spec'
5
+ require 'cocoapods-miBin/command/bin/lib'
6
+ require 'cocoapods-miBin/command/bin/repo'
7
+ require 'cocoapods-miBin/command/bin/open'
8
+ require 'cocoapods-miBin/command/bin/search'
9
+ require 'cocoapods-miBin/command/bin/list'
10
+ require 'cocoapods-miBin/command/bin/archive'
11
+ require 'cocoapods-miBin/command/bin/umbrella'
12
+ require 'cocoapods-miBin/helpers'
13
+
14
+ module Pod
15
+ class Command
16
+ # This is an example of a cocoapods plugin adding a top-level subcommand
17
+ # to the 'pod' command.
18
+ #
19
+ # You can also create subcommands of existing or new commands. Say you
20
+ # wanted to add a subcommand to `list` to show newly deprecated pods,
21
+ # (e.g. `pod list deprecated`), there are a few things that would need
22
+ # to change.
23
+ #
24
+ # - move this file to `lib/pod/command/list/deprecated.rb` and update
25
+ # the class to exist in the the Pod::Command::List namespace
26
+ # - change this class to extend from `List` instead of `Command`. This
27
+ # tells the plugin system that it is a subcommand of `list`.
28
+ # - edit `lib/cocoapods_plugins.rb` to require this file
29
+ #
30
+ # @todo Create a PR to add your plugin to CocoaPods/cocoapods.org
31
+ # in the `plugins.json` file, once your plugin is released.
32
+ #
33
+ class Bin < Command
34
+ include CBin::SourcesHelper
35
+ include CBin::SpecFilesHelper
36
+
37
+ self.abstract_command = true
38
+
39
+ self.default_subcommand = 'open'
40
+ self.summary = '组件二进制化插件.'
41
+ self.description = <<-DESC
42
+ 组件二进制化插件。利用源码私有源与二进制私有源实现对组件依赖类型的切换。
43
+ DESC
44
+
45
+ def initialize(argv)
46
+ require 'cocoapods-miBin/native'
47
+
48
+ @help = argv.flag?('help')
49
+ super
50
+ end
51
+
52
+ def validate!
53
+ super
54
+ # 这里由于 --help 是在 validate! 方法中提取的,会导致 --help 失效
55
+ # pod lib create 也有这个问题
56
+ banner! if @help
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,134 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cocoapods-miBin/native/podfile'
4
+ require 'cocoapods/command/gen'
5
+ require 'cocoapods/generate'
6
+ require 'cocoapods-miBin/helpers/framework_builder'
7
+
8
+ module Pod
9
+ class Command
10
+ class Bin < Command
11
+ class Archive < Bin
12
+ self.summary = '将组件归档为静态 framework.'
13
+ self.description = <<-DESC
14
+ 将组件归档为静态 framework,仅支持 iOS 平台
15
+ 此静态 framework 不包含依赖组件的 symbol
16
+ DESC
17
+
18
+ def self.options
19
+ [
20
+ ['--code-dependencies', '使用源码依赖'],
21
+ ['--allow-prerelease', '允许使用 prerelease 的版本'],
22
+ ['--no-clean', '保留构建中间产物'],
23
+ ['--no-zip', '不压缩静态 framework 为 zip']
24
+ ].concat(Pod::Command::Gen.options).concat(super).uniq
25
+ end
26
+
27
+ self.arguments = [
28
+ CLAide::Argument.new('NAME.podspec', false)
29
+ ]
30
+
31
+ def initialize(argv)
32
+ @code_dependencies = argv.flag?('code-dependencies')
33
+ @allow_prerelease = argv.flag?('allow-prerelease')
34
+ @clean = argv.flag?('clean', true)
35
+ @zip = argv.flag?('zip', true)
36
+ @sources = argv.option('sources') || []
37
+ @platform = Platform.new(:ios)
38
+ super
39
+
40
+ @additional_args = argv.remainder!
41
+ end
42
+
43
+ def run
44
+ @spec = Specification.from_file(spec_file)
45
+ generate_project
46
+ build_static_framework
47
+ zip_static_framework if @zip
48
+ clean_workspace if @clean
49
+ end
50
+
51
+ private
52
+
53
+ def generate_project
54
+ Podfile.execute_with_bin_plugin do
55
+ Podfile.execute_with_allow_prerelease(@allow_prerelease) do
56
+ Podfile.execute_with_use_binaries(!@code_dependencies) do
57
+ argvs = [
58
+ "--sources=#{sources_option(@code_dependencies, @sources)}",
59
+ "--gen-directory=#{gen_name}",
60
+ '--clean',
61
+ *@additional_args
62
+ ]
63
+
64
+ argvs << spec_file if spec_file
65
+
66
+ gen = Pod::Command::Gen.new(CLAide::ARGV.new(argvs))
67
+ gen.validate!
68
+ gen.run
69
+ end
70
+ end
71
+ end
72
+ end
73
+
74
+ def zip_static_framework
75
+ output_name = "#{binary_name}.zip"
76
+ unless File.exist?(binary_name)
77
+ raise Informative, "没有需要压缩的 framework 文件:#{binary_name}"
78
+ end
79
+
80
+ UI.puts "Compressing #{binary_name} into #{output_name}"
81
+
82
+ `zip --symlinks -r #{output_name} #{binary_name}`
83
+ end
84
+
85
+ def build_static_framework
86
+ source_dir = Dir.pwd
87
+ file_accessor = Sandbox::FileAccessor.new(Pathname.new('.').expand_path, @spec.consumer(@platform))
88
+ Dir.chdir(workspace_directory) do
89
+ builder = CBin::Framework::Builder.new(@spec, file_accessor, @platform, source_dir)
90
+ builder.build
91
+ end
92
+ end
93
+
94
+ def clean_workspace
95
+ UI.puts 'Cleaning workspace'
96
+
97
+ FileUtils.rm_rf(gen_name)
98
+ FileUtils.rm_rf(binary_name) if @zip
99
+ end
100
+
101
+ def gen_name
102
+ 'bin-archive'
103
+ end
104
+
105
+ def framework_name
106
+ "#{@spec.name}.framework"
107
+ end
108
+
109
+ def binary_name
110
+ "#{@spec.name}_binary"
111
+ end
112
+
113
+ def workspace_directory
114
+ File.expand_path("./#{gen_name}/#{@spec.name}")
115
+ end
116
+
117
+ def spec_file
118
+ @spec_file ||= begin
119
+ if @podspec
120
+ find_spec_file(@podspec)
121
+ else
122
+ if code_spec_files.empty?
123
+ raise Informative, '当前目录下没有找到可用源码 podspec.'
124
+ end
125
+
126
+ spec_file = code_spec_files.first
127
+ spec_file
128
+ end
129
+ end
130
+ end
131
+ end
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,71 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cocoapods-miBin/config/config_asker'
4
+
5
+ module Pod
6
+ class Command
7
+ class Bin < Command
8
+ class Init < Bin
9
+ self.summary = '初始化插件.'
10
+ self.description = <<-DESC
11
+ 创建 #{CBin.config.config_file} 文件,在其中保存插件需要的配置信息,
12
+ 如二进制私有源地址、源码私有源地址等。
13
+ DESC
14
+
15
+ def self.options
16
+ [
17
+ ['--bin-url=URL', '配置文件地址,直接从此地址下载配置文件']
18
+ ].concat(super)
19
+ end
20
+
21
+ def initialize(argv)
22
+ @bin_url = argv.option('bin-url')
23
+ super
24
+ end
25
+
26
+ def run
27
+ if @bin_url.nil?
28
+ config_with_asker
29
+ else
30
+ config_with_url(@bin_url)
31
+ end
32
+ end
33
+
34
+ private
35
+
36
+ def config_with_url(url)
37
+ require 'open-uri'
38
+
39
+ UI.puts "开始下载配置文件...\n"
40
+ file = open(url)
41
+ contents = YAML.safe_load(file.read)
42
+
43
+ UI.puts "开始同步配置文件...\n"
44
+ CBin.config.sync_config(contents.to_hash)
45
+ UI.puts "设置完成.\n".green
46
+ rescue Errno::ENOENT => e
47
+ raise Informative, "配置文件路径 #{url} 无效,请确认后重试."
48
+ end
49
+
50
+ def config_with_asker
51
+ asker = CBin::Config::Asker.new
52
+ asker.wellcome_message
53
+
54
+ config = {}
55
+ template_hash = CBin.config.template_hash
56
+ template_hash.each do |k, v|
57
+ default = begin
58
+ CBin.config.send(k)
59
+ rescue StandardError
60
+ nil
61
+ end
62
+ config[k] = asker.ask_with_answer(v[:description], default, v[:selection])
63
+ end
64
+
65
+ CBin.config.sync_config(config)
66
+ asker.done_message
67
+ end
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cocoapods-miBin/command/bin/lib/lint'
4
+
5
+ module Pod
6
+ class Command
7
+ class Bin < Command
8
+ class Lib < Bin
9
+ self.abstract_command = true
10
+ self.summary = '管理二进制 pod.'
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,69 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cocoapods-miBin/config/config'
4
+ require 'cocoapods-miBin/native/podfile'
5
+
6
+ module Pod
7
+ class Command
8
+ class Bin < Command
9
+ class Lib < Bin
10
+ class Lint < Lib
11
+ self.summary = 'lint 组件.'
12
+ self.description = <<-DESC
13
+ lint 二进制组件 / 源码组件
14
+ DESC
15
+
16
+ self.arguments = [
17
+ CLAide::Argument.new('NAME.podspec', false)
18
+ ]
19
+
20
+ # lib lint 不会下载 source,所以不能进行二进制 lint
21
+ # 要 lint 二进制版本,需要进行 spec lint,此 lint 会去下载 source
22
+ def self.options
23
+ [
24
+ ['--code-dependencies', '使用源码依赖进行 lint'],
25
+ ['--loose-options', '添加宽松的 options, 包括 --use-libraries (可能会造成 entry point (start) undefined)'],
26
+ ['--allow-prerelease', '允许使用 prerelease 的版本 lint']
27
+ ].concat(Pod::Command::Lib::Lint.options).concat(super).uniq
28
+ end
29
+
30
+ def initialize(argv)
31
+ @loose_options = argv.flag?('loose-options')
32
+ @code_dependencies = argv.flag?('code-dependencies')
33
+ @sources = argv.option('sources') || []
34
+ @allow_prerelease = argv.flag?('allow-prerelease')
35
+ @podspec = argv.shift_argument
36
+ super
37
+
38
+ @additional_args = argv.remainder!
39
+ end
40
+
41
+ def run
42
+ Podfile.execute_with_bin_plugin do
43
+ Podfile.execute_with_allow_prerelease(@allow_prerelease) do
44
+ Podfile.execute_with_use_binaries(!@code_dependencies) do
45
+ argvs = [
46
+ @podspec || code_spec_files.first,
47
+ "--sources=#{sources_option(@code_dependencies, @sources)}",
48
+ *@additional_args
49
+ ]
50
+
51
+ if @loose_options
52
+ argvs << '--allow-warnings'
53
+ if code_spec&.all_dependencies&.any?
54
+ argvs << '--use-libraries'
55
+ end
56
+ end
57
+
58
+ lint = Pod::Command::Lib::Lint.new(CLAide::ARGV.new(argvs))
59
+ lint.validate!
60
+ lint.run
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Pod
4
+ class Command
5
+ class Bin < Command
6
+ class List < Bin
7
+ self.summary = '展示二进制 pods .'
8
+
9
+ def self.options
10
+ [
11
+ ['--code', '展示源码 pods'],
12
+ ['--diff', '展示缺少二进制版本的源码 pods'],
13
+ ['--update', '展示前执行 `pod bin repo update`']
14
+ ].concat(super)
15
+ end
16
+
17
+ def initialize(argv)
18
+ @update = argv.flag?('update')
19
+ @code = argv.flag?('code')
20
+ @diff = argv.flag?('diff')
21
+ super
22
+ end
23
+
24
+ def run
25
+ update_if_necessary!
26
+
27
+ source = @code ? code_source : binary_source
28
+
29
+ sets = if @diff
30
+ binary_pod_set_names = binary_source.pod_sets.map(&:name)
31
+ sets = code_source.pod_sets.reject { |set| binary_pod_set_names.include?(set.name) }
32
+ else
33
+ source.pod_sets
34
+ end
35
+
36
+ sets.each { |set| UI.pod(set, :name_and_version) }
37
+ UI.puts "\n#{sets.count} pods were found"
38
+ end
39
+
40
+ def update_if_necessary!
41
+ if @update
42
+ UI.section("\nUpdating Spec Repositories\n".yellow) do
43
+ Pod::Command::Bin::Repo::Update.new(CLAide::ARGV.new([])).run
44
+ end
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end