Class: Pod::GDUploader

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods-gd/uploader.rb

Instance Method Summary collapse

Constructor Details

#initialize(spec, upload_spec_name, upload_local_path, spec_sources) ⇒ GDUploader

Returns a new instance of GDUploader.



5
6
7
8
9
10
11
12
13
14
# 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

Instance Method Details

#add_file(start_path, file_path, zip) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# 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) ⇒ Object

压缩文件方法



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 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

#buildObject



16
17
18
19
# 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_pushObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
# 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_repoObject



36
37
38
39
40
41
42
43
# 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