luna-binary-uploader 0.1.16 → 0.1.20

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,7 +14,12 @@ module Luna
14
14
  attr_accessor :version, :state
15
15
  attr_accessor :podFilePath
16
16
  attr_accessor :lockfile
17
-
17
+ attr_reader :bin_dev
18
+ attr_reader :binary_repo_url
19
+ attr_reader :binary_upload_url
20
+ attr_reader :binary_download_url
21
+ attr_reader :download_file_type
22
+
18
23
  def initialize()
19
24
  end
20
25
 
@@ -22,7 +27,7 @@ module Luna
22
27
  sources = Pod::Config.instance.sources_manager.all
23
28
  repoPath = nil
24
29
  sources.each { |item|
25
- if item.url == CBin.config.binary_repo_url
30
+ if item.url == Common.instance.binary_repo_url
26
31
  repoPath = item.repo
27
32
  end
28
33
  }
@@ -95,7 +100,7 @@ module Luna
95
100
  end
96
101
 
97
102
  def request_result_hash
98
- command = "curl #{CBin.config.binary_upload_url}"
103
+ command = "curl #{Common.instance.binary_upload_url}"
99
104
  p command
100
105
  result = %x(#{command})
101
106
  request_result_hash = JSON.parse(result)
@@ -105,31 +110,151 @@ module Luna
105
110
 
106
111
  def createNeedFrameworkMapper
107
112
  spec_repo_binary = {}
108
- Pod::UserInterface.puts "二进制repo地址 : #{CBin.config.binary_repo_url}".yellow
109
- Luna::Binary::Common.instance.use_framework_list.each { |item|
113
+ puts "二进制repo地址 : #{Common.instance.binary_repo_url}".yellow
114
+ use_framework_list.each { |item|
110
115
  name = item.split('/').first
111
116
  if spec_repo_binary[name] == nil
112
117
  spec_repo_binary[name] = lockfile.version(name).version
113
118
  end
114
119
  }
120
+ p "use_framework_list: #{spec_repo_binary}"
115
121
  return spec_repo_binary
116
122
  end
117
123
 
118
- def use_framework_list
119
- list = []
120
- File.open(Dir.pwd+"/Podfile", 'r:utf-8') do |f|
121
- f.each_line do |item|
122
- if item[":dev_env_use_binary"]
123
- matchs = item.match(/\'(?<=').*?(?=')\'/)
124
- if matchs != nil
125
- list << matchs[0].gsub("'", "")
124
+ def use_framework_list
125
+ list = []
126
+ File.open(Dir.pwd+"/Podfile", 'r:utf-8') do |f|
127
+ f.each_line do |item|
128
+ if item[":dev_env_use_binary"]
129
+ matchs = item.match(/\'(?<=').*?(?=')\'/)
130
+ if matchs != nil
131
+ list << matchs[0].gsub("'", "")
132
+ end
133
+ end
134
+ end
135
+ end
136
+ return list
137
+ end
138
+
139
+ def create_upload_lockitem(lockItem, moduleName, binary_path)
140
+ if lockItem.external_source == nil
141
+ uploader = uploadLintPodSpec(moduleName, lockItem.specific_version, binary_path)
142
+ if uploader != nil
143
+ return uploader
144
+ end
145
+ else
146
+ p lockItem.external_source
147
+ gitURL = lockItem.external_source['git'.parameterize.underscore.to_sym]
148
+ tag = lockItem.external_source['tag'.parameterize.underscore.to_sym]
149
+ path = lockItem.external_source['path'.parameterize.underscore.to_sym]
150
+ p "#{moduleName} git: #{gitURL} tag: #{tag} path: #{path}"
151
+ if path
152
+ pathArr = Dir.glob("#{Dir.pwd}/#{path}/**/#{moduleName}.podspec")
153
+ if pathArr
154
+ uploader = Uploader::SingleUploader.new(moduleName, "", "", binary_path)
155
+ uploader.local_path = pathArr.first
156
+ return uploader
157
+ end
158
+
159
+ elsif gitURL && tag && !moduleName["/"]
160
+ uploader = Uploader::SingleUploader.new(moduleName, gitURL, tag, binary_path)
161
+ return uploader
162
+ end
163
+ end
164
+ end
165
+
166
+ def upload_lockitem(dependencies_mapper, moduleName, binary_path, is_refresh = false)
167
+ if dependencies_mapper[moduleName]
168
+ lockContent = lockfile.dependencies_to_lock_pod_named(moduleName)
169
+ if lockContent #dependencies 应该拿不到所有的spec的依赖,我理解只能拿到podfile里面标明的,词典碰到dependency 没有bonmot的情况
170
+ lockContent.each { |lockItem|
171
+ begin
172
+ loader = create_upload_lockitem(lockItem, moduleName, binary_path)
173
+ if is_refresh
174
+ loader.refresh_specification_work
175
+ else
176
+ loader.specificationWork
126
177
  end
178
+ return loader
179
+ rescue => exception
180
+ raise exception
181
+ ensure
182
+
127
183
  end
128
- end
184
+ }
185
+ end
186
+ else
187
+ begin
188
+ uploader = uploadLintPodSpec(moduleName, lockfile.version(moduleName), binary_path)
189
+ if uploader != nil
190
+ if is_refresh
191
+ uploader.refresh_specification_work
192
+ else
193
+ uploader.specificationWork
194
+ end
195
+ return uploader
196
+ end
197
+ rescue => exception
198
+ raise exception
199
+ ensure
200
+
129
201
  end
130
- p "use_framework_list: #{list}"
131
- return list
132
202
  end
203
+ end
204
+
205
+ def uploadLintPodSpec(moduleName, specificVersion, binaryPath)
206
+ set = findLintPodspec(moduleName)
207
+ if set
208
+ pathArr = set.specification_paths_for_version(specificVersion)
209
+ if pathArr.length > 0
210
+ uploader = Uploader::SingleUploader.new(moduleName, "", "", binaryPath)
211
+ uploader.specification=Pod::Specification.from_file(pathArr.first)
212
+ # uploader.specificationWork
213
+ end
214
+ end
215
+ return uploader
216
+ end
217
+
218
+ def dependenciesMapper
219
+ return lockfile.dependencies.map { |item| [item.name.split("/").first, item]}.to_h
220
+ end
221
+
222
+ def bin_dev
223
+ if @bin_dev == nil
224
+ @bin_dev = YAML.load_file("#{Pod::Config.instance.home_dir}/bin_dev.yml")
225
+ end
226
+ return @bin_dev
227
+ end
228
+
229
+ def binary_repo_url
230
+ if @binary_repo_url == nil
231
+ @binary_repo_url = bin_dev["binary_repo_url"]
232
+ end
233
+ return @binary_repo_url
234
+ end
235
+
236
+ def binary_upload_url
237
+ if @binary_upload_url == nil
238
+ cut_string = "/%s/%s/zip"
239
+ @binary_upload_url = binary_download_url[0,binary_download_url.length - cut_string.length]
240
+ end
241
+ return @binary_upload_url
242
+ end
243
+
244
+ def binary_download_url
245
+ if @binary_download_url == nil
246
+ @binary_download_url = bin_dev["binary_download_url"]
247
+ end
248
+ return @binary_download_url
249
+ end
250
+
251
+ def download_file_type
252
+ if @download_file_type == nil
253
+ @download_file_type = bin_dev["download_file_type"]
254
+ end
255
+ return @download_file_type
256
+ end
257
+
133
258
  end
134
259
  end
135
260
  end
@@ -33,15 +33,15 @@ module Luna
33
33
  end
34
34
 
35
35
  def deleteRepo
36
- command = "cd #{Luna::Binary::Common.instance.repoPath}; git stash;git checkout master;git pull origin master;"
36
+ command = "cd #{Common.instance.repoPath}; git stash;git checkout master;git pull origin master;"
37
37
  system command
38
- Luna::Binary::Common.instance.deleteDirectory("#{Luna::Binary::Common.instance.repoPath}/#{name}/#{version}")
39
- commandADD = "cd #{Luna::Binary::Common.instance.repoPath};git add .; git commit -m 'DEL::#{name}-#{version} by LBU'; git push -f origin master"
38
+ Common.instance.deleteDirectory("#{Common.instance.repoPath}/#{name}/#{version}")
39
+ commandADD = "cd #{Common.instance.repoPath};git add .; git commit -m 'DEL::#{name}-#{version} by LBU'; git push -f origin master"
40
40
  system commandADD
41
41
  end
42
42
 
43
43
  def deleteBinaryFramework
44
- command = "curl -X 'DELETE' #{CBin.config.binary_upload_url}/#{name}/#{version}"
44
+ command = "curl -X 'DELETE' #{Common.instance.binary_upload_url}/#{name}/#{version}"
45
45
  p command
46
46
  system command
47
47
  end
@@ -0,0 +1,25 @@
1
+ require "luna/binary/uploader/version"
2
+ require "cocoapods"
3
+ require 'cocoapods-imy-bin/native/sources_manager'
4
+ require 'cocoapods-imy-bin/config/config'
5
+ require 'cocoapods-imy-bin'
6
+ require 'json'
7
+ require 'luna/binary/common/common'
8
+
9
+ module Luna
10
+ module Binary
11
+ class Init
12
+ attr_reader :url
13
+ def initialize(url)
14
+ @url = url
15
+ run
16
+ end
17
+
18
+ def run
19
+ Common.instance.command("curl -o #{Pod::Config.instance.home_dir}/bin_dev.yml #{url}")
20
+ Common.instance.command("pod repo add z-ios-framework-spec-repo #{Common.instance.binary_repo_url}")
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,38 @@
1
+ require "luna/binary/uploader/version"
2
+ require "cocoapods"
3
+ require 'cocoapods-imy-bin/native/sources_manager'
4
+ require 'cocoapods-imy-bin/config/config'
5
+ require 'cocoapods-imy-bin'
6
+ require 'json'
7
+ require 'luna/binary/common/common'
8
+
9
+ module Luna
10
+ module Binary
11
+ class Install
12
+ attr_reader :is_open
13
+ def initialize(is_open)
14
+ @is_open = is_open
15
+ run
16
+ end
17
+
18
+ def run
19
+ buffer = ""
20
+ podfile_path = Dir.pwd + "/Podfile"
21
+ IO.foreach(podfile_path) { |line|
22
+ if line.match(/@use_luna_frameworks =/) || line.match(/@use_luna_frameworks=/)
23
+ buffer += "@use_luna_frameworks = #{is_open}\n"
24
+ else
25
+ buffer += line
26
+ end
27
+ }
28
+ File.open(podfile_path, "w") { |source_file|
29
+ source_file.write buffer
30
+ }
31
+
32
+ Common.instance.command("rm -rf #{Dir.pwd}/Pods")
33
+ Common.instance.command("pod install")
34
+
35
+ end
36
+ end
37
+ end
38
+ end
@@ -9,55 +9,64 @@ module Luna
9
9
  attr_accessor :request_result_hash
10
10
 
11
11
  def run
12
- spec_repo_binary = createNeedFrameworkMapper
13
- rootPath = "#{Luna::Binary::Common.instance.tempLunaUploaderPath}/refresh"
14
- Luna::Binary::Common.instance.deleteDirectory("#{rootPath}")
15
- system "mkdir -p #{rootPath};"
12
+ spec_repo_binary = Common.instance.createNeedFrameworkMapper
13
+ dependencies_mapper = Common.instance.dependenciesMapper
16
14
  failList = []
15
+ successList = []
17
16
  spec_repo_binary.each { |k,v|
18
17
  if request_result_hash[k] != nil && request_result_hash[k].include?(v)
19
18
  begin
20
- pathArr = Dir.glob("#{binary_path}/**/#{k.sub("-","_")}.framework")
21
- if pathArr != nil
22
- Pod::UserInterface.puts "#{pathArr.first} #{k}".yellow
23
- srcPath = File.dirname(pathArr.first)
24
- system "cp -r #{srcPath} #{rootPath};"
25
- File.rename("#{rootPath}/#{File.basename(srcPath)}", "#{rootPath}/#{k}")
26
- zipCommand = "cd #{rootPath};zip -r #{k}.zip #{k}"
27
- p zipCommand
28
- system zipCommand
29
- Luna::Binary::Delete.new(k,v).deleteBinaryFramework
30
- command = "cd #{rootPath};curl #{CBin.config.binary_upload_url} -F \"name=#{k}\" -F \"version=#{v}\" -F \"annotate=#{k}_#{v}_log\" -F \"file=@#{k}.zip\""
31
- p command
32
- system command
33
- end
19
+ puts "#{k} #{v}".yellow
20
+
21
+ uploader = Common.instance.upload_lockitem(dependencies_mapper,k ,binary_path, true)
22
+ if uploader != nil
23
+ Delete.new(k,v).delete
24
+ puts "#{k} #{v} 重新制作上传".yellow
25
+ uploader.upload
26
+ successList << "#{k} #{v}"
27
+ else
28
+ failList << "#{k} #{v} 失败,请确保在非二进制状态下"
29
+ end
30
+
34
31
  rescue => exception
35
- p exception
36
- failList << "#{k} #{exception}"
37
- else
32
+ failList << "#{k} #{v} exception:#{exception}"
33
+ ensure
38
34
 
39
- end
35
+ end
40
36
  else
41
- failList << "name: #{k}"
37
+ failList << "name: #{k} #{v} 在服务不存在"
42
38
  end
43
39
  }
44
- p "exception:#{failList}"
40
+ puts "-=-=-=-=-=-=-=-=重新上传的名单-=-=-=-=-=-=-=-=".yellow
41
+ successList.each { |item|
42
+ puts item.green
43
+ }
44
+
45
+ puts "-=-=-=-=-=-=-=-=失败的名单-=-=-=-=-=-=-=-=".yellow if failList.length > 0
46
+ failList.each { |item|
47
+ puts item.red
48
+ }
49
+ end
50
+
51
+ def in_framework_service(dependencies_mapper, name, version)
52
+ dependency = dependencies_mapper[name]
53
+ if lockfile.dependencies_mappe
54
+ else
55
+
56
+ end
45
57
  end
46
58
 
47
59
  def lockfile
48
- return Luna::Binary::Common.instance.lockfile
60
+ return Common.instance.lockfile
49
61
  end
50
62
 
51
63
  def request_result_hash
52
64
  if @request_result_hash == nil
53
- @request_result_hash = Luna::Binary::Common.instance.request_result_hash
65
+ @request_result_hash = Common.instance.request_result_hash
54
66
  end
55
67
  return @request_result_hash
56
68
  end
57
-
58
- def createNeedFrameworkMapper
59
- return Luna::Binary::Common.instance.createNeedFrameworkMapper
60
- end
69
+
61
70
  end
62
71
  end
63
72
  end
@@ -9,109 +9,49 @@ module Luna
9
9
  attr_accessor :request_result_hash
10
10
 
11
11
  def run
12
- spec_repo_binary = createNeedFrameworkMapper
13
- rootPath = "#{Luna::Binary::Common.instance.tempLunaUploaderPath}/update"
14
- Luna::Binary::Common.instance.deleteDirectory("#{rootPath}")
15
- system "mkdir -p #{rootPath};"
12
+ spec_repo_binary = Common.instance.createNeedFrameworkMapper
16
13
  failList = []
17
14
  successList = []
18
- dependenciesMapper = lockfile.dependencies.map { |item| [item.name, item]}.to_h
15
+ dependenciesMapper = Common.instance.dependenciesMapper
19
16
  spec_repo_binary.each { |k,v|
20
17
  if request_result_hash[k] == nil || request_result_hash[k].include?(v) == false
21
- moduleName = k
22
- if dependenciesMapper[moduleName]
23
- lockContent = lockfile.dependencies_to_lock_pod_named(moduleName)
24
- if lockContent #dependencies 应该拿不到所有的spec的依赖,我理解只能拿到podfile里面标明的,词典碰到dependency 没有bonmot的情况
25
- lockContent.each { |lockItem|
26
- begin
27
- if lockItem.external_source == nil
28
- uploader = uploadLintPodSpec(moduleName, lockItem.specific_version, binary_path)
29
- if uploader != nil
30
- successList << uploader
31
- end
32
- else
33
- p lockItem.external_source
34
- gitURL = lockItem.external_source['git'.parameterize.underscore.to_sym]
35
- tag = lockItem.external_source['tag'.parameterize.underscore.to_sym]
36
- path = lockItem.external_source['path'.parameterize.underscore.to_sym]
37
- p "#{moduleName} git: #{gitURL} tag: #{tag} path: #{path}"
38
- if path
39
- pathArr = Dir.glob("#{Dir.pwd}/#{path}/**/#{moduleName}.podspec")
40
- if pathArr
41
- uploader = Luna::Binary::Uploader::SingleUploader.new(moduleName, "", "", binary_path)
42
- uploader.specification=Pod::Specification.from_file(pathArr.first)
43
- uploader.specificationWork
44
- successList<<uploader
45
- end
46
-
47
- elsif gitURL && tag && !moduleName["/"]
48
- uploader = Luna::Binary::Uploader::SingleUploader.new(moduleName, gitURL, tag, binary_path)
49
- uploader.specificationWork
50
- successList << uploader
51
- end
52
- end
53
- rescue => exception
54
- # raise exception
55
- ensure
56
-
57
- end
58
- }
59
- end
60
- else
61
- begin
62
- uploader = uploadLintPodSpec(moduleName, lockfile.version(moduleName), binary_path)
63
- if uploader != nil
64
- successList << uploader
65
- end
66
- rescue => exception
67
-
68
- ensure
69
-
18
+ begin
19
+ uploader = Common.instance.upload_lockitem(dependenciesMapper, k, binary_path)
20
+ if uploader != nil
21
+ successList << uploader
22
+ else
23
+ failList << "#{k} #{v} 失败,请确保在非二进制状态下"
70
24
  end
25
+
26
+ rescue => exception
27
+ failList << "#{k} exception: #{exception}"
28
+ ensure
29
+
71
30
  end
72
31
  else
73
32
  failList << "已存在name: #{k}"
74
33
  end
75
34
  }
76
-
35
+ puts "-=-=-=-=-=-=-=-=framework制作中-=-=-=-=-=-=-=-=-=-=".yellow
77
36
  successList.each { |item|
78
- Pod::UserInterface.puts "#{item} 制作中".yellow
37
+ puts "#{item} 制作中".yellow
79
38
  item.upload
80
39
  }
81
- p "exception:#{failList}"
82
- end
83
40
 
84
- def lockfile
85
- return Luna::Binary::Common.instance.lockfile
86
- end
41
+ puts "-=-=-=-=-=-=-=-=update 失败名单-=-=-=-=-=-=-=-=-=-=".yellow if failList.length > 0
42
+ failList.each {|item|
43
+ puts item.red
44
+ }
87
45
 
88
- def findLintPodspec(moduleName)
89
- return Luna::Binary::Common.instance.findLintPodspec(moduleName)
90
- end
91
-
92
- def uploadLintPodSpec(moduleName, specificVersion, binaryPath)
93
- set = findLintPodspec(moduleName)
94
- if set
95
- pathArr = set.specification_paths_for_version(specificVersion)
96
- if pathArr.length > 0
97
- uploader = Luna::Binary::Uploader::SingleUploader.new(moduleName, "", "", binaryPath)
98
- uploader.specification=Pod::Specification.from_file(pathArr.first)
99
- uploader.specificationWork
100
- end
101
- end
102
- return uploader
103
46
  end
104
47
 
105
48
  def request_result_hash
106
49
  if @request_result_hash == nil
107
- @request_result_hash = Luna::Binary::Common.instance.request_result_hash
50
+ @request_result_hash = Common.instance.request_result_hash
108
51
  end
109
52
  return @request_result_hash
110
53
  end
111
-
112
- def createNeedFrameworkMapper
113
- return Luna::Binary::Common.instance.createNeedFrameworkMapper
114
- end
54
+
115
55
  end
116
56
  end
117
57
  end
@@ -1,7 +1,7 @@
1
1
  module Luna
2
2
  module Binary
3
3
  module Uploader
4
- VERSION = "0.1.16"
4
+ VERSION = "0.1.20"
5
5
  end
6
6
  end
7
7
  end