class Pod::GDUploader

Public Class Methods

new(spec, upload_spec_name, upload_local_path, spec_sources) click to toggle source
# File lib/cocoapods-gd/uploader.rb, line 5
def initialize(spec, upload_spec_name, upload_local_path, spec_sources)
        @spec = spec
        @work_dir = Dir.pwd
        @upload_spec_name = upload_spec_name
        @upload_local_path = upload_local_path
        @spec_sources = spec_sources
        build
        git_push
        push_repo
end

Public Instance Methods

add_file(start_path,file_path,zip) click to toggle source
# File lib/cocoapods-gd/uploader.rb, line 47
def add_file(start_path,file_path,zip)   
if File.directory?(file_path)  
        zip.mkdir(file_path)  
        Dir.foreach(file_path) do |filename|  
                      add_file("#{start_path}/#{filename}","#{file_path}/#{filename}",zip) unless filename=="." or filename==".."  
        end  
else  
        zip.add(start_path,file_path)  
end  
end
add_to_zip_file(zip_file_name,file_path) click to toggle source

压缩文件方法

# File lib/cocoapods-gd/uploader.rb, line 46
def add_to_zip_file(zip_file_name,file_path)   
       def add_file(start_path,file_path,zip)   
       if File.directory?(file_path)  
               zip.mkdir(file_path)  
               Dir.foreach(file_path) do |filename|  
                             add_file("#{start_path}/#{filename}","#{file_path}/#{filename}",zip) unless filename=="." or filename==".."  
               end  
       else  
               zip.add(start_path,file_path)  
       end  
       end  
  
       if File.exist?(zip_file_name)   
       File.delete(zip_file_name)  
       end  
   
       chdir,tardir = File.split(file_path)  
       Dir.chdir(chdir) do   
       Zip::File.open(zip_file_name,Zip::File::CREATE) do |zipfile|   
               add_file(tardir,tardir,zipfile)  
       end  
       end   
end
build() click to toggle source
# File lib/cocoapods-gd/uploader.rb, line 16
def build
        filename = "#{@spec.name}-#{@spec.version}"
        add_to_zip_file("#{Dir.pwd}/#{filename}/#{filename}.zip", "#{Dir.pwd}/#{filename}")
end
git_push() click to toggle source
# File lib/cocoapods-gd/uploader.rb, line 21
def git_push
        filename = "#{@spec.name}-#{@spec.version}"
        framworks_path = @upload_local_path
        zip_path = "#{framworks_path}/#{@spec.name}"
FileUtils.mkdir_p(zip_path) unless File.exists?(zip_path)
FileUtils.cp("#{Dir.pwd}/#{filename}/#{filename}.zip", "#{zip_path}")
Dir.chdir(framworks_path)
git_add_command = "git add ."
git_output = `#{git_add_command}`.lines.to_a
commit_add_command = "git commit -s -m 'add #{filename} framework'"
commit_output = `#{commit_add_command}`.lines.to_a
push_add_command = "git push origin master"
push_commit_output = `#{push_add_command}`.lines.to_a
end
push_repo() click to toggle source
# File lib/cocoapods-gd/uploader.rb, line 36
def push_repo
        filename = "#{@spec.name}-#{@spec.version}"
        UI.puts("准备发布 #{@work_dir}/#{filename}")
        Dir.chdir("#{@work_dir}/#{filename}")
        source = @spec_sources.join(",")
       command = "pod repo push #{@upload_spec_name} #{@work_dir}/#{filename}/#{@spec.name}.podspec --allow-warnings --use-libraries --use-modular-headers --verbose --skip-import-validation --sources=#{source}"
output = `#{command}`.lines.to_a
end