cocoapods-external-pod-sorter 0.0.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 596f9acb3f6abd7aa7ff2ab44036b61e0f2c19dd
4
+ data.tar.gz: a76266f4e67d31264baecfb49a397bd6b2c55bbd
5
+ SHA512:
6
+ metadata.gz: 9f5cb463e00cf42613dda5c74895e13dc6bebbf451e38c0c73b592695da27df5ccde19a3b19e4af1313f87fb3e64eca6d6f38b10cdfe105950e40dc6debd5fb2
7
+ data.tar.gz: 8c6149ce8a57bacdf5bc42853f1c804e209a4d95dc152114d64c16f9014d2a4052d833d7e071a353c034135cbe9ba0968f010d0a80acda646d81849d5b8e73a3
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .DS_Store
2
+ pkg
3
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in cocoapods-external-pod-sorter.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'cocoapods'
8
+
9
+ gem 'mocha'
10
+ gem 'bacon'
11
+ gem 'mocha-on-bacon'
12
+ gem 'prettybacon'
13
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2018 tripleCC <triplec.linux@gmail.com>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,11 @@
1
+ # cocoapods-external-pod-sorter
2
+
3
+ A description of cocoapods-external-pod-sorter.
4
+
5
+ ## Installation
6
+
7
+ $ gem install cocoapods-external-pod-sorter
8
+
9
+ ## Usage
10
+
11
+ $ pod spec sorter POD_NAME
data/Rakefile ADDED
@@ -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,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cocoapods-external-pod-sorter/gem_version.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'cocoapods-external-pod-sorter'
8
+ spec.version = CocoapodsExternalPodSorter::VERSION
9
+ spec.authors = ['tripleCC']
10
+ spec.email = ['triplec.linux@gmail.com']
11
+ spec.description = %q{对 Podfile 中依赖 external 的组件进行分组.}
12
+ spec.summary = %q{对 Podfile 中依赖 external 的组件进行分组.}
13
+ spec.homepage = 'https://github.com/tripleCC/cocoapods-external-pod-sorter'
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_development_dependency 'bundler', '~> 1.3'
22
+ spec.add_development_dependency 'rake'
23
+ end
@@ -0,0 +1,2 @@
1
+ require 'cocoapods-external-pod-sorter/gem_version'
2
+ require 'cocoapods-external-pod-sorter/external_pod_sorter'
@@ -0,0 +1,15 @@
1
+ require 'cocoapods'
2
+
3
+ module Pod
4
+ class Podfile
5
+ def untagged_dependencies
6
+ main_target_definitions = target_definition_list.reject do |target_definition|
7
+ target_definition.name.end_with?('Tests')
8
+ end
9
+ untagged_dependencies = main_target_definitions.flat_map(&:dependencies).uniq.select do |dependency|
10
+ dependency.external? && dependency.external_source[:tag].nil?
11
+ end
12
+ untagged_dependencies
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require 'cocoapods'
2
+
3
+ module Pod
4
+ class Source
5
+ def newest_specs
6
+ pods.map do |pod|
7
+ versions = versions(pod)
8
+ if versions
9
+ version = versions.sort.last
10
+ spec = specification(pod, version)
11
+ end
12
+ end.compact
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,19 @@
1
+ require 'cocoapods'
2
+ require 'cocoapods-external-pod-sorter/cocoapods/source'
3
+
4
+ module Pod
5
+ class Source
6
+ class Manager
7
+ DEFAULT_SOURCE_URL = 'git@git.2dfire-inc.com:ios/cocoapods-spec.git'.freeze
8
+
9
+ def newest_specs_with_source_name_or_url(name_or_url)
10
+ source = source_with_name_or_url(name_or_url)
11
+ source.newest_specs if source
12
+ end
13
+
14
+ def default_source
15
+ source_with_name_or_url(DEFAULT_SOURCE_URL)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,39 @@
1
+ require 'cocoapods'
2
+
3
+ module Pod
4
+ class Specification
5
+ module RecursiveDependency
6
+ def recursive_dependencies(all_specs)
7
+ @recursive_dependencies ||= begin
8
+ resolve_recursive_dependencies(all_specs)
9
+ end
10
+ end
11
+
12
+ def direct_dependencies
13
+ @direct_dependencies ||= begin
14
+ direct_value('dependencies')
15
+ end
16
+ end
17
+
18
+ protected
19
+ def direct_value(name, platform = :ios)
20
+ subspec_consumers = recursive_subspecs.select { |s| s.supported_on_platform?(platform) }
21
+ .map { |s| s.consumer(platform) }
22
+ .uniq
23
+ value = (Array(consumer(platform)) + subspec_consumers).map { |c| c.send(name) }.flatten.uniq
24
+ value
25
+ end
26
+
27
+ def resolve_recursive_dependencies(specs)
28
+ direct_dependencies.map do |dep|
29
+ spec = specs.find { |s| s.name == dep.name }
30
+ next dep if spec.nil? || spec.direct_dependencies.empty?
31
+
32
+ (Array(dep) + spec.resolve_recursive_dependencies(specs)).flatten
33
+ end.compact.flatten.uniq
34
+ end
35
+ end
36
+
37
+ include Pod::Specification::RecursiveDependency
38
+ end
39
+ end
@@ -0,0 +1 @@
1
+ require 'cocoapods-external-pod-sorter/command/sorter'
@@ -0,0 +1,67 @@
1
+ require 'cocoapods-external-pod-sorter/external_pod_sorter'
2
+
3
+ module Pod
4
+ class Command
5
+ # This is an example of a cocoapods plugin adding a top-level subcommand
6
+ # to the 'pod' command.
7
+ #
8
+ # You can also create subcommands of existing or new commands. Say you
9
+ # wanted to add a subcommand to `list` to show newly deprecated pods,
10
+ # (e.g. `pod list deprecated`), there are a few things that would need
11
+ # to change.
12
+ #
13
+ # - move this file to `lib/pod/command/list/deprecated.rb` and update
14
+ # the class to exist in the the Pod::Command::List namespace
15
+ # - change this class to extend from `List` instead of `Command`. This
16
+ # tells the plugin system that it is a subcommand of `list`.
17
+ # - edit `lib/cocoapods_plugins.rb` to require this file
18
+ #
19
+ # @todo Create a PR to add your plugin to CocoaPods/cocoapods.org
20
+ # in the `plugins.json` file, once your plugin is released.
21
+ #
22
+ class Sort < Command
23
+ self.summary = '对 Podfile 中依赖 external 的组件进行分组.'
24
+
25
+ self.description = <<-DESC
26
+ cocoapods-external-pod-sorter 对 Podfile 中依赖 external 的组件进行分组.
27
+ DESC
28
+
29
+ def self.options
30
+ [
31
+ ['--project-directory', 'The path to the root of the project directory']
32
+ ].concat(super)
33
+ end
34
+
35
+ def initialize(argv)
36
+ @project_directory = argv.option('project-directory')
37
+ super
38
+ end
39
+
40
+ def validate!
41
+ super
42
+ podfile_empty = (@project_directory && Pathname.glob(File.join(@project_directory, 'Podfile')).empty?) ||
43
+ Pathname.glob('Podfile').empty?
44
+ help! 'No `Podfile` found in the project directory.' if podfile_empty
45
+ end
46
+
47
+ def run
48
+ config = Pod::Config.instance
49
+ config.installation_root = Pathname.new(@project_directory) if @project_directory
50
+ sorter = ExternalPodSorter.new(config)
51
+ sorter.sort
52
+ sorter.grouped_pods.each do |group|
53
+ group.each do |pod|
54
+ display = pod.name.dup
55
+ if pod.external_dependency_names.any?
56
+ pod.external_dependency_names.each do |name|
57
+ display << "\n- #{name}"
58
+ end
59
+ end
60
+ display << "\n\n"
61
+ puts display
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,73 @@
1
+ require 'cocoapods'
2
+ require 'cocoapods-external-pod-sorter/cocoapods/podfile'
3
+ require 'cocoapods-external-pod-sorter/cocoapods/sources_manager'
4
+ require 'cocoapods-external-pod-sorter/cocoapods/specification'
5
+ require 'cocoapods-external-pod-sorter/external_pod_sorter/pod_item'
6
+ require 'cocoapods-external-pod-sorter/cocoapods/source'
7
+
8
+ class ExternalPodSorter
9
+ attr_accessor :grouped_pods
10
+
11
+ def initialize(config = Pod::Config.instance)
12
+ @config = config
13
+ @untagged_dependencies = config.podfile.untagged_dependencies
14
+ end
15
+
16
+ public
17
+ def sort
18
+ podfile_specs = analyze_podfile_specs
19
+ @grouped_pods = group_pods_by_dependency_depth(@untagged_dependencies, podfile_specs)
20
+ @grouped_pods
21
+ end
22
+
23
+ private
24
+
25
+ def analyze_podfile_specs
26
+ analyzer = Pod::Installer::Analyzer.new(@config.sandbox, @config.podfile, @config.lockfile)
27
+ podfile_specs = @config.with_changes(skip_repo_update: true) do
28
+ # allow fetch ,初次install时,或者新增external source 时,由于Pods/Local Podspecs 是空,会抛出找不到specification异常
29
+ begin
30
+ analyzer.analyze(false).specs_by_target.values.flatten(1)
31
+ rescue
32
+ analyzer.analyze(true).specs_by_target.values.flatten(1)
33
+ end
34
+ end
35
+
36
+ podfile_specs
37
+ rescue
38
+ puts 'Can`t fetch specs from project directory, fetch from private source cache'.yellow
39
+ @config.sources_manager.default_source.newest_specs
40
+ end
41
+
42
+ def group_pods_by_dependency_depth(untagged_dependencies, podfile_specs)
43
+ result = []
44
+
45
+ untagged_dependency_names = untagged_dependencies.map(&:name)
46
+ untagged_specs = podfile_specs.select do |spec|
47
+ untagged_dependency_names.include?(spec.name)
48
+ end
49
+
50
+ while untagged_specs.length > 0
51
+ pods = []
52
+ untagged_specs.each do |spec|
53
+ dependency_names = spec.recursive_dependencies(podfile_specs).map { |dep| dep.name }
54
+ untagged_name = spec.name
55
+
56
+ if untagged_specs.select { |spec| dependency_names.include?(spec.name) }.empty?
57
+ pod = ExternalPodSorter::PodItem.new(untagged_name)
58
+ pod.spec = podfile_specs.find { |spec| spec.name == untagged_name }
59
+ pod.dependency = untagged_dependencies.find { |dep| dep.name == untagged_name }
60
+ pod.external_dependency_names = dependency_names.select { |name| untagged_dependency_names.include?(name) }
61
+ pods << pod
62
+ end
63
+ end
64
+ untagged_specs = untagged_specs.reject do |spec|
65
+ pods.select { |pod| pod.name == spec.name }.any?
66
+ end
67
+
68
+ result << pods
69
+ end
70
+
71
+ result
72
+ end
73
+ end
@@ -0,0 +1,20 @@
1
+ class ExternalPodSorter
2
+ class PodItem
3
+ attr_accessor :name
4
+ attr_accessor :external_dependency_names
5
+ attr_accessor :dependency
6
+ attr_accessor :spec
7
+
8
+ def initialize(name)
9
+ @name = name
10
+ end
11
+
12
+ def to_s
13
+ name
14
+ end
15
+
16
+ def inspect
17
+ name
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module CocoapodsExternalPodSorter
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1 @@
1
+ require 'cocoapods-external-pod-sorter/command'
@@ -0,0 +1,12 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ module Pod
4
+ describe Command::Sorter do
5
+ describe 'CLAide' do
6
+ it 'registers it self' do
7
+ Command.parse(%w{ sorter }).should.be.instance_of Command::Sorter
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -0,0 +1,50 @@
1
+ require 'pathname'
2
+ ROOT = Pathname.new(File.expand_path('../../', __FILE__))
3
+ $:.unshift((ROOT + 'lib').to_s)
4
+ $:.unshift((ROOT + 'spec').to_s)
5
+
6
+ require 'bundler/setup'
7
+ require 'bacon'
8
+ require 'mocha-on-bacon'
9
+ require 'pretty_bacon'
10
+ require 'pathname'
11
+ require 'cocoapods'
12
+
13
+ Mocha::Configuration.prevent(:stubbing_non_existent_method)
14
+
15
+ require 'cocoapods_plugin'
16
+
17
+ #-----------------------------------------------------------------------------#
18
+
19
+ module Pod
20
+
21
+ # Disable the wrapping so the output is deterministic in the tests.
22
+ #
23
+ UI.disable_wrap = true
24
+
25
+ # Redirects the messages to an internal store.
26
+ #
27
+ module UI
28
+ @output = ''
29
+ @warnings = ''
30
+
31
+ class << self
32
+ attr_accessor :output
33
+ attr_accessor :warnings
34
+
35
+ def puts(message = '')
36
+ @output << "#{message}\n"
37
+ end
38
+
39
+ def warn(message = '', actions = [])
40
+ @warnings << "#{message}\n"
41
+ end
42
+
43
+ def print(message)
44
+ @output << message
45
+ end
46
+ end
47
+ end
48
+ end
49
+
50
+ #-----------------------------------------------------------------------------#
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cocoapods-external-pod-sorter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - tripleCC
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-07-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: 对 Podfile 中依赖 external 的组件进行分组.
42
+ email:
43
+ - triplec.linux@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - cocoapods-external-pod-sorter.gemspec
54
+ - lib/cocoapods-external-pod-sorter.rb
55
+ - lib/cocoapods-external-pod-sorter/cocoapods/podfile.rb
56
+ - lib/cocoapods-external-pod-sorter/cocoapods/source.rb
57
+ - lib/cocoapods-external-pod-sorter/cocoapods/sources_manager.rb
58
+ - lib/cocoapods-external-pod-sorter/cocoapods/specification.rb
59
+ - lib/cocoapods-external-pod-sorter/command.rb
60
+ - lib/cocoapods-external-pod-sorter/command/sorter.rb
61
+ - lib/cocoapods-external-pod-sorter/external_pod_sorter.rb
62
+ - lib/cocoapods-external-pod-sorter/external_pod_sorter/pod_item.rb
63
+ - lib/cocoapods-external-pod-sorter/gem_version.rb
64
+ - lib/cocoapods_plugin.rb
65
+ - spec/command/sorter_spec.rb
66
+ - spec/spec_helper.rb
67
+ homepage: https://github.com/tripleCC/cocoapods-external-pod-sorter
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.6.14
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: 对 Podfile 中依赖 external 的组件进行分组.
91
+ test_files:
92
+ - spec/command/sorter_spec.rb
93
+ - spec/spec_helper.rb