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 = [] @local_pods = [] @yk_git_source_pods = [] @other_git_source_pods = [] @pod_lock.dependencies.each do |dep| next unless !dep.external_source.nil? if dep.external_source.include?(:path) @local_pods.push dep.name end if dep.external_source.include?(:git) if dep.external_source[:git].include?(YK) @yk_git_source_pods.push dep.name else @other_git_source_pods.push dep.name end end end 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 = @local_pods.include? pod_name is_install_from_git_commit = @yk_git_source_pods.include? pod_name dep_attribute_in_pod_file = find_info_in_specifications pod_name # pp "#{pod_name} #{spec_repo_name} #{version} local:#{is_local_dependency} ,git_commit: #{is_install_from_git_commit}" map["name"] = pod_name map["version"] = version map["is_local_dependency"] = is_local_dependency map["is_install_from_git_commit"] = is_install_from_git_commit 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_pod_from_local(name) # local_pods = [] # @pod_lock.dependencies.each do |dep| # next unless dep.name == name && !dep.external_source.nil? # if dep.external_source.include?(:path) # local_pods.push dep.name # end # # end # local_pods.include? name # 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