require 'set' module Pod class SpecBuilder def initialize(spec, source, embedded, dynamic) @spec = spec name = spec.attributes_hash['name'] version = spec.attributes_hash['version'] @source = source.nil? ? "{ :http => 'https://10.0.0.0/staticpods/#{name}/#{name}-#{version}.zip' }" : source @embedded = embedded @dynamic = dynamic @platform = nil end def framework_path if @embedded @spec.name + '.embeddedframework' + '/' + @spec.name + '.framework' else @spec.name + '.framework' end end def spec_platform(platform) fwk_base = platform.name.to_s + '/' + framework_path spec = < 0 subspecs.each do |subspec| subspec = JSON.parse(subspec) if !subspec next end df = subspec[type] if df if df.class == String all_frame.add(df) elsif df.class == Array all_frame.merge(df) end end plat = subspec['ios'] if plat if plat.class == Hash plat_f = plat[type] if plat_f if plat_f.class == String all_frame.add(plat_f) elsif plat_f.class == Array all_frame.merge(plat_f) end end end end end end spec_json = JSON.parse(get_spec_json) dfm = spec_json[type] if dfm if dfm.class == String all_frame.add(dfm) elsif dfm.class == Array all_frame.merge(dfm) end end if !dfm return all_frame end plat = dfm['ios'] if plat if plat.class == Hash plat_f = plat[type] if plat_f if plat_f.class == String all_frame.add(plat_f) elsif plat_f.class == Array all_frame.merge(plat_f) end end end end # puts "get all type --> #{type} value --> #{all_frame}" return all_frame end def get_spec_json return @spec.to_pretty_json end def get_resource return get_spec_json.include?('resource_bundles') || get_spec_json.include?('resource') || get_spec_json.include?('resources') || get_spec_json.include?('resource_bundle') end def process_platform_hash case value = @spec.attributes_hash['platforms'] when String { value => nil } when Array result = {} value.each do |a_value| result[a_value] = nil end result when Hash value else {} end end def get_platform platform_str = '' platform = process_platform_hash if platform if platform['ios'] platform_str = " s.platform = :ios, '#{platform['ios']}' \n" else platform_str = " s.platform = :ios" end end platform_str end def get_all_dependenices(plat) depen = @spec.all_dependencies(plat) depen = depen.map {|den| den.name} depen = depen.select {|de| !de.include?('/')} depen end def spec_metadata spec = spec_header spec += get_platform frames = get_all_type('frameworks') if frames.length > 0 spec += ' s.frameworks = ' frames.each do |val| spec += "'#{val}'," end spec = spec.delete_suffix(',') spec += "\n" end framework = get_all_type('framework') if framework.length > 0 framework.each do |val| spec += " s.framework = #{val}\n" end end libs = get_all_type('libraries') if libs.length > 0 spec += " s.libraries = " libs.each do |val| spec += "'#{val}'," end spec = spec.delete_suffix(',') spec += "\n" end library = get_all_type('library') if library.length > 0 library.each do |val| spec += " s.library = #{val} \n" end end dependices = get_all_dependenices(@platform) if dependices.length > 0 dependices.each do |val| spec += " s.dependency '#{val}'" end spec += "\n" end res = get_resource if res spec += " s.resources = 'ios/#{framework_path}/Resources/#{@spec.name}.bundle' \n" end spec end def spec_close "end\n" end private def spec_header spec = "Pod::Spec.new do |s|\n" %w(name version summary license authors homepage description social_media_url documentation_url requires_arc deployment_target xcconfig).each do |attribute| value = @spec.attributes_hash[attribute] next if value.nil? value = value.dump if value.class == String spec += " s.#{attribute} = #{value}\n" end spec + " s.source = #{@source}\n\n" end end end