cocoapods-hd 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,12 @@
1
+ # attr_accessor for class variable.
2
+ # usage:
3
+ #
4
+ # ```
5
+ # class Pod
6
+ # class_attr_accessor :is_prebuild_stage
7
+ # end
8
+ # ```
9
+ #
10
+ def class_attr_accessor(symbol)
11
+ self.class.send(:attr_accessor, symbol)
12
+ end
@@ -0,0 +1,35 @@
1
+ module CocoapodsHd
2
+ class Constant
3
+
4
+ def self.binary_url
5
+ 'http://gitlab.dushuclub.io/cocoapods/HDBinarySpecs.git'
6
+ end
7
+
8
+ def self.source_url
9
+ 'http://gitlab.dushuclub.io/cocoapods/HDSourceSpecs.git'
10
+ end
11
+
12
+ def self.spec_url
13
+ 'http://gitlab.dushuclub.io/cocoapods/Specs.git'
14
+ end
15
+
16
+ def self.binary_repo
17
+ path = File.join(Dir.home, ".cocoapods/repos/HDBinarySpecs")
18
+ path
19
+ end
20
+
21
+ def self.unused_binary_repo
22
+ path = File.join(Dir.home, ".cocoapods/repos/dushuclub-cocoapods-hdbinaryspecs")
23
+ path
24
+ end
25
+
26
+ def self.user_and_password
27
+ "fddsh:bookclub"
28
+ end
29
+
30
+ def self.ftp_url
31
+ "ftp://172.16.43.173/binary"
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,262 @@
1
+ require 'cocoapods'
2
+ require 'pathname'
3
+ require 'fileutils'
4
+
5
+ module CocoapodsHd
6
+ class SpecSourceCreator
7
+
8
+ attr_accessor :code_spec
9
+ attr_accessor :name
10
+ attr_accessor :spec
11
+ attr_accessor :filepath
12
+
13
+ def initialize(code_spec, name, filepath)
14
+ @code_spec = code_spec
15
+ @name = name
16
+ @platforms = ['ios']
17
+ @filepath = filepath
18
+ validate!
19
+ end
20
+
21
+ def validate!
22
+ raise Pod::Informative, '源码 podspec 不能为空 .' unless code_spec
23
+ end
24
+
25
+ def binary_source
26
+ {
27
+ http: "http://172.16.43.173/binary/#{@name}/#{@code_spec.version}/#{@name}.zip",
28
+ type: "zip"
29
+ }
30
+ end
31
+
32
+ def filename
33
+ @filename ||= "#{@name}.podspec.json"
34
+ end
35
+
36
+ def create
37
+ spec = create_from_code_spec
38
+ spec
39
+ end
40
+
41
+ def write_spec_file(file = filename)
42
+
43
+ create unless spec
44
+
45
+ File.open(file, 'w+') do |f|
46
+ f.write(spec.to_pretty_json)
47
+ end
48
+
49
+ @filename = file
50
+
51
+ end
52
+
53
+ def create_from_code_spec
54
+ @spec = code_spec.dup
55
+ # vendored_frameworks | resources | source | source_files | public_header_files
56
+ # license | resource_bundles | vendored_libraries
57
+
58
+ # vendored_frameworks
59
+ results = vendored_frameworks(@spec, @name, @filepath)
60
+ @spec.vendored_frameworks = results
61
+ @spec.description = "打包版本的commit:#{`git rev-parse HEAD`.strip}"
62
+ @spec.license = "MIT"
63
+
64
+ # source_files && public_header_files
65
+ @spec.source_files = framework_contents(results, '/Headers/*')
66
+ @spec.public_header_files = framework_contents(results, '/Headers/*')
67
+
68
+ # Source Location
69
+ @spec.source = binary_source
70
+ # Unused for binary
71
+ spec_hash = @spec.to_hash
72
+ # resources || resource_bundles
73
+ if @spec.to_hash.has_key?('resource') || @spec.to_hash.has_key?('resources')
74
+ spec_hash['resources'] = resources(@name)
75
+ elsif @spec.to_hash.has_key?('resource_bundles')
76
+ spec_hash['resources'] = resource_bundles
77
+ end
78
+
79
+ spec_hash.delete('exclude_files')
80
+ spec_hash.delete('preserve_paths')
81
+ # 这里不确定 vendored_libraries 指定的是动态/静态库
82
+ # 如果是静态库的话,需要移除,否则就不移除
83
+ # 最好是静态库都独立成 Pod ,cocoapods-package 打静态库去 collect 目标文件时好做过滤
84
+ # 这里统一只对命名后缀 .a 文件做处理
85
+ # spec_hash.delete('vendored_libraries')
86
+ # libraries 只能假设为动态库不做处理了,如果有例外,需要开发者自行处理
87
+ result_vendored_libraries = vendored_libraries(@spec, @filepath)
88
+ if result_vendored_libraries.empty?
89
+ spec_hash.delete('vendored_libraries')
90
+ else
91
+ spec_hash['vendored_libraries'] = result_vendored_libraries
92
+ end
93
+
94
+ # Filter platforms
95
+ platforms = spec_hash['platforms']
96
+ selected_platforms = platforms.select { |k, _v| @platforms.include?(k) }
97
+ spec_hash['platforms'] = selected_platforms.empty? ? platforms : selected_platforms
98
+
99
+ # Subspecs
100
+ if spec_hash.has_key?('subspecs')
101
+ subspecs = spec_hash['subspecs']
102
+ subspecs.each do |value|
103
+ # 删除resource_bundles
104
+ value.delete('resource_bundles')
105
+
106
+ # 添加public_header_files、vendored_frameworks、source_files
107
+ result_vendored_frameworks = subspec_vendored_frameworks(value, @name, @filepath)
108
+ value["vendored_frameworks"] = result_vendored_frameworks
109
+ value["public_header_files"] = subspec_public_header_files(@name)
110
+ value["source_files"] = subspec_source_files(@name)
111
+
112
+ result_vendored_libraries = subspec_vendored_libraries(value, @filepath)
113
+ if !result_vendored_libraries.empty?
114
+ value['vendored_libraries'] = result_vendored_libraries
115
+ end
116
+ end
117
+ end
118
+
119
+ @spec = Pod::Specification.from_hash(spec_hash)
120
+ @spec
121
+ end
122
+
123
+ def vendored_libraries(spec, path)
124
+ results = []
125
+ if spec.to_hash.has_key?('vendored_libraries')
126
+ hash_vendored_libraries = spec.to_hash['vendored_libraries']
127
+ if hash_vendored_libraries.class == String
128
+ final_path = path + hash_vendored_libraries
129
+ all_path = Dir[final_path]
130
+ all_path.each do |value|
131
+ name = getFileNameByFilePath(value)
132
+ results.push(name)
133
+ end
134
+ else
135
+ #数组
136
+ hash_vendored_libraries = spec.to_hash['vendored_libraries']
137
+ hash_vendored_libraries.each do |value|
138
+ final_path = path + value
139
+ all_path = Dir[final_path]
140
+ all_path.each do |value|
141
+ name = getFileNameByFilePath(value)
142
+ results.push(name)
143
+ end
144
+ end
145
+ end
146
+ end
147
+ results
148
+ end
149
+
150
+ def vendored_frameworks(spec, name, path)
151
+ origin_framework = "#{name}.framework"
152
+ results = [origin_framework]
153
+ if spec.to_hash.has_key?('vendored_frameworks')
154
+ hash_vendored_frameworks = spec.to_hash['vendored_frameworks']
155
+ if hash_vendored_frameworks.class == String
156
+ final_path = path + hash_vendored_frameworks
157
+ all_path = Dir[final_path]
158
+ all_path.each do |value|
159
+ name = getFileNameByFilePath(value)
160
+ results.push(name)
161
+ end
162
+ else
163
+ #数组
164
+ hash_vendored_frameworks.each do |value|
165
+ final_path = path + value
166
+ all_path = Dir[final_path]
167
+ all_path.each do |value|
168
+ name = getFileNameByFilePath(value)
169
+ results.push(name)
170
+ end
171
+ end
172
+ end
173
+ end
174
+ results
175
+ end
176
+
177
+ def subspec_vendored_frameworks(value, name, path)
178
+ origin_framework = "#{name}.framework"
179
+ results = [origin_framework]
180
+ if value.has_key?('vendored_frameworks')
181
+ hash_vendored_frameworks = value['vendored_frameworks']
182
+ if hash_vendored_frameworks.class == String
183
+ final_path = path + hash_vendored_frameworks
184
+ all_path = Dir[final_path]
185
+ all_path.each do |value|
186
+ name = getFileNameByFilePath(value)
187
+ results.push(name)
188
+ end
189
+ else
190
+ #数组
191
+ hash_vendored_frameworks = spec.to_hash['vendored_frameworks']
192
+ hash_vendored_frameworks.each do |value|
193
+ final_path = path + value
194
+ all_path = Dir[final_path]
195
+ all_path.each do |value|
196
+ name = getFileNameByFilePath(value)
197
+ results.push(name)
198
+ end
199
+ end
200
+ end
201
+ end
202
+ results
203
+ end
204
+
205
+ def subspec_vendored_libraries(value, path)
206
+ results = []
207
+ if value.has_key?('vendored_libraries')
208
+ hash_vendored_libraries = value['vendored_libraries']
209
+ if hash_vendored_libraries.class == String
210
+ final_path = path + hash_vendored_libraries
211
+ all_path = Dir[final_path]
212
+ all_path.each do |value|
213
+ name = getFileNameByFilePath(value)
214
+ results.push(name)
215
+ end
216
+ else
217
+ #数组
218
+ hash_vendored_libraries = spec.to_hash['vendored_libraries']
219
+ hash_vendored_libraries.each do |value|
220
+ final_path = path + value
221
+ all_path = Dir[final_path]
222
+ all_path.each do |value|
223
+ name = getFileNameByFilePath(value)
224
+ results.push(name)
225
+ end
226
+ end
227
+ end
228
+ end
229
+ results
230
+ end
231
+
232
+ def getFileNameByFilePath(path)
233
+ result = path.split('/')[-1]
234
+ result
235
+ end
236
+
237
+ def framework_contents(frameworks, name)
238
+ results = []
239
+ frameworks.each do |value|
240
+ results.push(value + name)
241
+ end
242
+ results
243
+ end
244
+
245
+ def subspec_public_header_files(name)
246
+ "#{name}.framework/Headers/*.h"
247
+ end
248
+
249
+ def subspec_source_files(name)
250
+ ["#{name}.framework/Headers/*"]
251
+ end
252
+
253
+ def resources(name)
254
+ ["#{name}.framework/*.bundle"]
255
+ end
256
+
257
+ def resource_bundles
258
+ ["*.bundle"]
259
+ end
260
+
261
+ end
262
+ end
@@ -0,0 +1,91 @@
1
+ require 'cocoapods'
2
+ require 'pathname'
3
+ require 'fileutils'
4
+ require 'cocoapods-hd/upload/constant'
5
+ require_relative 'spec_source_creator'
6
+ require 'net/ftp'
7
+
8
+ module CocoapodsHd
9
+ class UploadHelper
10
+
11
+ attr_accessor :code_spec, :name, :version, :file_path, :platforms
12
+
13
+ def initialize(code_spec = nil, file_path = nil)
14
+ @code_spec = code_spec
15
+ @platforms = ['ios']
16
+ @file_path = file_path
17
+ @version = code_spec.version
18
+ @name = code_spec.root.name
19
+
20
+ puts "基础信息: name: #{name} --- version: #{version} --- file_path: #{file_path} --- platforms: #{platforms} "
21
+
22
+ end
23
+
24
+ def spec_creator
25
+ spec_creator = SpecSourceCreator.new(code_spec, name, file_path)
26
+ spec_creator.create
27
+ spec_creator.write_spec_file
28
+ spec_creator.filename
29
+ end
30
+
31
+ def upload
32
+ # 上传zip包
33
+ upload_static_zip
34
+ # push binary repo podspec.json
35
+ push_binary_repo
36
+ end
37
+
38
+ def upload_static_zip
39
+ puts "开始上传zip --------- "
40
+
41
+ create_dir_command = "curl -u #{Constant.user_and_password} #{Constant.ftp_url}/#{@name}/#{@version.to_s}/ --ftp-create-dirs"
42
+ upload_zip_command = "curl -u #{Constant.user_and_password} #{Constant.ftp_url}/#{@name}/#{@version.to_s}/ -T #{file_path}/#{@name}.zip"
43
+
44
+ `#{create_dir_command}`
45
+ `#{upload_zip_command}`
46
+ # 查看curl返回结果
47
+ # create_dir_result = %x(#{create_dir_command})
48
+ # puts "create_dir_result 执行结果 : #{create_dir_result} --- "
49
+
50
+ STDERR.puts "zip upload success ".green
51
+ end
52
+
53
+ # 上传二进制 podspec
54
+ def push_binary_repo
55
+ # 创建目录 ps: AFNetworking/4.0.1
56
+ add_spec_to_repo
57
+
58
+ # push spec to origin gitlab
59
+ `git status -s`
60
+ `git add .`
61
+ `git commit -m '添加 binary #{@name} #{@version.to_s}'`
62
+ `git push origin master`
63
+ STDERR.puts "#{name}.podspec.json psuh success ".green
64
+
65
+ end
66
+
67
+ def add_spec_to_repo
68
+ podspec_name = "#{@name}.podspec.json"
69
+ podspec_json = File.join(Dir.pwd, podspec_name)
70
+
71
+ FileUtils.chdir(binary_repo_dir)
72
+ spec_path = File.join(@name, @version.to_s)
73
+
74
+ FileUtils.mkdir_p(spec_path) unless File.exist?(spec_path)
75
+
76
+ # 移动podspec.json到本地repo
77
+ FileUtils.move(podspec_json, spec_path)
78
+ end
79
+
80
+ # 获取 HDBinarySpecs 路径
81
+ def binary_repo_dir
82
+ unless File.directory?(Constant.binary_repo)
83
+ `pod repo add HDBinarySpecs #{Constant.binary_url}`
84
+ # 删除多余的repo
85
+ FileUtils.rm_rf(Constant.unused_binary_repo)
86
+ end
87
+ Constant.binary_repo
88
+ end
89
+
90
+ end
91
+ end
@@ -1,9 +1,9 @@
1
1
  require 'cocoapods-hd/command'
2
2
  require 'cocoapods'
3
3
 
4
- module Hd
5
- # 注册 pod install 钩子
6
- Pod::HooksManager.register('cocoapods-hd', :post_install) do |context|
7
- Pod::UI.puts 'hello world ---'
8
- end
9
- end
4
+ # module Hd
5
+ # # 注册 pod install 钩子
6
+ # Pod::HooksManager.register('cocoapods-hd', :post_install) do |context|
7
+ # Pod::UI.puts 'hello world ======== '
8
+ # end
9
+ # end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-hd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - xingyong
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-30 00:00:00.000000000 Z
11
+ date: 2021-06-30 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: fourflusher
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 2.3.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 2.3.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: xcpretty
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.3.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.3.0
13
41
  - !ruby/object:Gem::Dependency
14
42
  name: bundler
15
43
  requirement: !ruby/object:Gem::Requirement
@@ -38,7 +66,7 @@ dependencies:
38
66
  - - '='
39
67
  - !ruby/object:Gem::Version
40
68
  version: 13.0.3
41
- description: 组件化开发工具
69
+ description: component development tools
42
70
  email:
43
71
  - xingyong@dushu365.com
44
72
  executables: []
@@ -46,11 +74,27 @@ extensions: []
46
74
  extra_rdoc_files: []
47
75
  files:
48
76
  - lib/cocoapods-hd.rb
77
+ - lib/cocoapods-hd/Integration.rb
78
+ - lib/cocoapods-hd/build/build_framework.rb
49
79
  - lib/cocoapods-hd/command.rb
80
+ - lib/cocoapods-hd/command/binary.rb
50
81
  - lib/cocoapods-hd/command/hd.rb
51
82
  - lib/cocoapods-hd/command/tag.rb
52
83
  - lib/cocoapods-hd/gem_version.rb
84
+ - lib/cocoapods-hd/helper/feature_switches.rb
85
+ - lib/cocoapods-hd/helper/names.rb
86
+ - lib/cocoapods-hd/helper/passer.rb
87
+ - lib/cocoapods-hd/helper/podfile_options.rb
88
+ - lib/cocoapods-hd/helper/prebuild_sandbox.rb
89
+ - lib/cocoapods-hd/helper/target_checker.rb
90
+ - lib/cocoapods-hd/main.rb
91
+ - lib/cocoapods-hd/prebuild.rb
92
+ - lib/cocoapods-hd/resolver.rb
53
93
  - lib/cocoapods-hd/tag_util.rb
94
+ - lib/cocoapods-hd/tool/tool.rb
95
+ - lib/cocoapods-hd/upload/constant.rb
96
+ - lib/cocoapods-hd/upload/spec_source_creator.rb
97
+ - lib/cocoapods-hd/upload/upload_helper.rb
54
98
  - lib/cocoapods_plugin.rb
55
99
  homepage: https://juejin.cn/post/6931272510793383943
56
100
  licenses:
@@ -74,5 +118,5 @@ requirements: []
74
118
  rubygems_version: 3.1.4
75
119
  signing_key:
76
120
  specification_version: 4
77
- summary: 组件化开发工具,快速创建和删除tag
121
+ summary: component development tools create tag、delete tag
78
122
  test_files: []