Class: Pod::Command::Dep
- Inherits:
-
Pod::Command
- Object
- Pod::Command
- Pod::Command::Dep
- Includes:
- Command::ProjectDirectory
- Defined in:
- lib/cocoapods-dep/command/dep.rb
Constant Summary collapse
- OUTFILE =
输出依赖文件
'dep_analyze_out.lock'- CHANGE_DEPENDENCIES =
[ "GCTTravel", "GCTUIKit", "GCTIOSUtils", "GCTAccount", "GCTQuickLogin", "GCTHTTPServer", "GCTWiFiConnection", "GCTStatistic", "GCTShareKit", "GCTMine", "GCTReservation", 'GCTCitiesAndStations', 'GCTMapKitV2', 'GCTSharedTravel', 'GCTPromotionCenter', 'GCTAudio', 'GCTCinema', 'GCTMediaPlayer', 'GCTVideo', 'GCTAdvert', 'GCTCoupon' ].map(&:freeze).freeze
- CHANGE_DEPENDENCIES_PRIORITY =
{ "GCTTravel"=> 1000, "GCTUIKit"=> 1000, "GCTIOSUtils"=> 1000, "GCTAccount"=> 1000, "GCTQuickLogin"=> 1000, "GCTHTTPServer"=> 1000, "GCTWiFiConnection"=> 1000, "GCTStatistic"=> 1000, "GCTShareKit"=> 1000, "GCTMine"=> 1000, "GCTReservation"=> 1000, 'GCTCitiesAndStations'=> 1000, 'GCTMapKitV2'=> 1000, 'GCTSharedTravel'=> 1000, 'GCTPromotionCenter'=> 1000, 'GCTAudio'=> 1000, 'GCTCinema'=> 1000, 'GCTMediaPlayer'=> 1000, 'GCTVideo'=> 1000, 'GCTAdvert'=> 1000, 'GCTCoupon'=> 1000 }
Class Method Summary collapse
Instance Method Summary collapse
- #arr_ele_cutout(arr) ⇒ Object
- #dependencies ⇒ Object
- #generate_pods_data(specs) ⇒ Object
-
#initialize(argv) ⇒ Dep
constructor
A new instance of Dep.
- #podfile ⇒ Object
- #read_change_dependencies_from_file(path) ⇒ Object
- #run ⇒ Object
- #sandbox ⇒ Object
- #validate! ⇒ Object
- #write_to_disk(path, content) ⇒ Object
- #yaml_write ⇒ Object
Constructor Details
#initialize(argv) ⇒ Dep
Returns a new instance of Dep.
27 28 29 30 |
# File 'lib/cocoapods-dep/command/dep.rb', line 27 def initialize(argv) @podspec_name = argv.shift_argument super end |
Class Method Details
.arguments ⇒ Object
21 22 23 24 25 |
# File 'lib/cocoapods-dep/command/dep.rb', line 21 def self.arguments [ CLAide::Argument.new('PODSPEC', false) ].concat(super) end |
.options ⇒ Object
17 18 19 |
# File 'lib/cocoapods-dep/command/dep.rb', line 17 def self. [].concat(super) end |
Instance Method Details
#arr_ele_cutout(arr) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/cocoapods-dep/command/dep.rb', line 54 def arr_ele_cutout(arr) arr.map do |ele| if ele.to_s.include? '/' ele.to_s[0, ele.index('/')] else ele end end end |
#dependencies ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/cocoapods-dep/command/dep.rb', line 64 def dependencies @dependencies ||= begin analyzer = Installer::Analyzer.new( sandbox, podfile, @podspec ? nil : config.lockfile ) specs = config.with_changes(skip_repo_update: true) do analyzer.analyze(@podspec).specs_by_target.values.flatten(1) end generate_pods_data(specs) end end |
#generate_pods_data(specs) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/cocoapods-dep/command/dep.rb', line 80 def generate_pods_data(specs) pods_and_deps_merged = specs.reduce({}) do |result, spec| name = spec.name result[name] ||= [] result[name].concat(spec.all_dependencies.map(&:name)) result end pod_and_deps = pods_and_deps_merged.map do |name, deps| deps.empty? ? name : { name => YAMLHelper.sorted_array(deps.uniq) } end YAMLHelper.sorted_array(pod_and_deps) end |
#podfile ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/cocoapods-dep/command/dep.rb', line 94 def podfile @podfile ||= begin if podspec = @podspec platform = podspec.available_platforms.first platform_name, platform_version = platform.name, platform.deployment_target.to_s sources = SourcesManager.all.map(&:url) pp sources Podfile.new do install! :cocoapods, integrate_targets: false sources.each { |s| source s } platform platform_name, platform_version pod podspec.name, podspec: podspec.defined_in_file end else verify_podfile_exists! config.podfile end end end |
#read_change_dependencies_from_file(path) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/cocoapods-dep/command/dep.rb', line 133 def read_change_dependencies_from_file(path) yaml_file = YAML.load(File.open(path)) lines = Array.new() change_dependencies = Array.new() CHANGE_DEPENDENCIES.each do |spec_name| spec_dependency_hash = Hash.new() spec_name_key = spec_name spec_dependencies = Array.new() yaml_file.each do |line| if line.class == Hash line.each { |key, value| if key.to_s.include? spec_name.to_s or key.to_s.include? spec_name.to_s + '/' spec_dependencies = spec_dependencies + value end } end end spec_dependency_hash[spec_name_key] = arr_ele_cutout(spec_dependencies) change_dependencies << spec_dependency_hash end dependencies_priority = Hash.new() change_dependencies.each do |dependency| dependency.each { |key, value| temp_arr = value & CHANGE_DEPENDENCIES if temp_arr.include? key temp_arr.delete(key) end dependencies_priority[key] = temp_arr } end temp_change_dependencies_priority = Hash.new() while temp_change_dependencies_priority != CHANGE_DEPENDENCIES_PRIORITY do temp_change_dependencies_priority = CHANGE_DEPENDENCIES_PRIORITY.clone dependencies_priority.each { |key, value| if value.length > 0 priority = CHANGE_DEPENDENCIES_PRIORITY[key] value.each do |pod_name| if priority >= CHANGE_DEPENDENCIES_PRIORITY[pod_name] priority = CHANGE_DEPENDENCIES_PRIORITY[pod_name] - 1 end end CHANGE_DEPENDENCIES_PRIORITY[key] = priority end } end pp CHANGE_DEPENDENCIES_PRIORITY write_to_disk(config.installation_root.to_s + '/' + OUTFILE, CHANGE_DEPENDENCIES_PRIORITY.to_yaml) end |
#run ⇒ Object
48 49 50 51 52 |
# File 'lib/cocoapods-dep/command/dep.rb', line 48 def run puts "开始分析依赖".green yaml_write puts "分析依赖完成,请查看 <-- #{Dir.pwd}/#{OUTFILE} -->文件".green end |
#sandbox ⇒ Object
114 115 116 117 118 119 120 121 |
# File 'lib/cocoapods-dep/command/dep.rb', line 114 def sandbox if @podspec require 'tmpdir' Sandbox.new(Dir.mktmpdir) else config.sandbox end end |
#validate! ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cocoapods-dep/command/dep.rb', line 32 def validate! super if @podspec_name require 'pathname' path = Pathname.new(@podspec_name) if path.exist? @podspec = Specification.from_file(path) else @podspec = SourcesManager. search(Dependency.new(@podspec_name)). specification. subspec_by_name(@podspec_name) end end end |
#write_to_disk(path, content) ⇒ Object
129 130 131 |
# File 'lib/cocoapods-dep/command/dep.rb', line 129 def write_to_disk(path, content) File.open(path, 'w') { |f| f.write(content.to_yaml) } end |
#yaml_write ⇒ Object
123 124 125 126 127 |
# File 'lib/cocoapods-dep/command/dep.rb', line 123 def yaml_write lock_path = config.installation_root.to_s + '/dependencies.lock' write_to_disk(lock_path, dependencies) read_change_dependencies_from_file(lock_path) end |