require 'cocoapods' require 'cocoapods-core/lockfile' YK = 'yeah'+'ka' COMPONENT_TYPE = ['基础组件', 'UI组件', '通用业务组件', '业务模块', '其它'] FOUNDATION_COMPONENT_NAMES = ['基础组件', 'UI组件', '通用业务组件', '业务模块', '其它'] UI_COMPONENT_NAMES = [''] COMMON_BUSINESS_COMPONENT_NAMES = [''] UNCATEGORIZE_COMPONENT_NAMES = [''] SPECIFICATION_FILTER_KEYS = ['summary', 'homepage', 'authors', "source"] module YkCommand class DependencyResult def initialize(specifications, pod_lock) @specifications = specifications @pod_lock = pod_lock @result = [] end def find_info_in_lokfile removed_subspecs_dep_list = [] @pod_lock.pod_names.each do |pn| removed_subspecs_dep_list = removed_subspecs_dep_list.push(pn.split('/')[0]).uniq end #去重后的 依赖 名字 数组 removed_subspecs_dep_list.each do |pod_name| map = {} version = @pod_lock.version(pod_name).version spec_repo_name = @pod_lock.spec_repo(pod_name) is_local_dependency = is_pod_from_local pod_name is_yk_dependency = is_yk_dependency pod_name is_install_from_git_commit = !@pod_lock.checkout_options_for_pod_named(pod_name).nil? dep_attribute_in_pod_file = find_info_in_specifications pod_name pp "#{pod_name} #{spec_repo_name} #{version} local:#{is_local_dependency} ,yeahka:#{is_yk_dependency},git_commit: #{is_install_from_git_commit}" map["name"] = pod_name map["version"] = version map["is_local_dependency"] = is_local_dependency map["is_yk_dependency"] = is_yk_dependency map["is_install_from_git_commit"] = is_install_from_git_commit.nil? dep_attribute_in_pod_file.each do |k, v| if SPECIFICATION_FILTER_KEYS.include?(k) map[k] = v end end @result.push map end end def result_json find_info_in_lokfile @result.to_json end def is_yk_dependency(name) tag = false @pod_lock.dependencies.each do |dep| next unless dep.name == name && !dep.external_source.nil? dep.external_source.each do |k, v| tag = if dep.external_source.include?(:git) dep.external_source[:git].include?(YK) end end end tag end def is_pod_from_local(name) tag = false @pod_lock.dependencies.each do |dep| next unless dep.name == name && !dep.external_source.nil? tag = dep.external_source.include?(:path) end tag end def find_info_in_specifications(name) map = {} @specifications.each do |sp| next unless sp.name == name map = sp.attributes_hash end map end # def podfile_dependencies(podfile) # res = [] # podfile.root_target_definitions.each do |td| # children_definitions = td.recursive_children # children_definitions.each do |cd| # dependencies_hash_array = cd.send(:get_hash_value, 'dependencies') # next if dependencies_hash_array.nil? || dependencies_hash_array.count.zero? # # dependencies_hash_array.each do |item| # next if item.class.name != 'Hash' # # item.each do |name, _| # res.push name # end # end # end # end # res # end # # def find_dependencies(name, map, res, dependencies_map, root_name) # return unless map[name] # # map[name].each do |k| # find_dependencies(k.name, map, res, dependencies_map, root_name) # dependency = dependencies_map[k.name.split('/')[0]] # res.push dependency.name if dependency && dependency.name != root_name # end # res # end # # def subspecs_with_name(spec, subspecs_short_names) # subspecs_short_names.map do |name| # spec.subspecs.find { |ss| ss.name.include? name } # end # end # # end end