cocoapods-bb-PodAssistant 0.1.6 → 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (22) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cocoapods-bb-PodAssistant/command/stable/init.rb +30 -0
  3. data/lib/cocoapods-bb-PodAssistant/command/stable/install.rb +38 -0
  4. data/lib/cocoapods-bb-PodAssistant/command/stable/sync.rb +32 -0
  5. data/lib/cocoapods-bb-PodAssistant/command/stable/update.rb +61 -0
  6. data/lib/cocoapods-bb-PodAssistant/command/stable.rb +51 -0
  7. data/lib/cocoapods-bb-PodAssistant/command.rb +6 -7
  8. data/lib/cocoapods-bb-PodAssistant/config/cache_path.rb +7 -1
  9. data/lib/cocoapods-bb-PodAssistant/config/source_manager.rb +48 -20
  10. data/lib/cocoapods-bb-PodAssistant/gem_version.rb +1 -1
  11. data/lib/cocoapods-bb-PodAssistant/helpers/git_cmd_helper.rb +5 -1
  12. data/lib/cocoapods-bb-PodAssistant/helpers/pod_module_helper.rb +44 -7
  13. data/lib/cocoapods-bb-PodAssistant/helpers/stable_env_helper.rb +115 -18
  14. data/lib/cocoapods-bb-PodAssistant/source_provider_hook.rb +3 -4
  15. metadata +12 -9
  16. data/lib/cocoapods-bb-PodAssistant/command/PodAssistant.rb +0 -44
  17. data/lib/cocoapods-bb-PodAssistant/command/stable/stable.rb +0 -168
  18. /data/lib/cocoapods-bb-PodAssistant/{command → babybus}/linkline/target-linkline.rb +0 -0
  19. /data/lib/cocoapods-bb-PodAssistant/{command → babybus}/linkline/targetValidator-linkline.rb +0 -0
  20. /data/lib/cocoapods-bb-PodAssistant/{command → babybus}/linkline/targetdefinition-linkline.rb +0 -0
  21. /data/lib/cocoapods-bb-PodAssistant/{command → babybus}/stable/podfile-linkline.rb +0 -0
  22. /data/lib/cocoapods-bb-PodAssistant/command/{linkline/linkline.rb → linkline.rb} +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a4d73bccc2529481814cc586c3d0cb46b863c986741859ac8d399f1a8962ed1c
4
- data.tar.gz: d96718876d58008ffa7e846cae38e68d46358fe3e88effd7477b669b514ede12
3
+ metadata.gz: 95c6d433814654744108bb1b8d1051ac00b37dff52e8d0c73fbb03bbb7d67d52
4
+ data.tar.gz: d804e3f603a8ed9e8612fb4edf6c5ed19ae543d2328dfaf92bf335664f0da421
5
5
  SHA512:
6
- metadata.gz: 979d7c8365b57c364e953ebe616d55be2c40c5547a72d42089db504123d9188bfe8920ede679ec412128e41cca44feaec052d32d1163c60b7434d022be2dfba4
7
- data.tar.gz: c86d930fdd7cc595ea411b235ce98b18e8c105665b178a05938f9f4e942a20530bb83a5ac2dabb6a530022d0f82f2373adf6951d55984d2473b15d52d93e2a0f
6
+ metadata.gz: 75858bf2163338409042d5e4be54e38d6c08a8ea93df77341870af4a0425bd1dc9a1b8a905376775b958318b554b537d4a0b9ad0f822f92d67ed53b82d0ccf04
7
+ data.tar.gz: 8216d2c5d5df66e7ff8526ae9394ba0a11c1391ac3f6c835e997458417aacab84d3372b346f9caaa565f087679448d094719c5b80ad48c29aeb04de1ed4691d6
@@ -0,0 +1,30 @@
1
+ require 'cocoapods-bb-PodAssistant/config/source_manager'
2
+
3
+ module Pod
4
+ class Command
5
+ class Stable < Command
6
+ class Init < Stable
7
+
8
+ self.summary = '[初始化项目yml配置] Generate a Stable yml config file from a Podfile.lock'
9
+
10
+ self.description = <<-DESC
11
+ 通过项目`Podfile.lock`文件,生成`stable_specs_lock.yml`配置文件
12
+ DESC
13
+
14
+ def initialize(argv)
15
+ super
16
+ end
17
+
18
+ def run
19
+ # verify_podfile_exists!
20
+ source_manager = BB::SourceManager.new()
21
+ puts "[PodAssistant] 开始配置生成当前项目yml文件".yellow
22
+ # 生成本地yml配置
23
+ source_manager.generate_localStable
24
+ puts "[PodAssistant] `pod stable init` complete!".green
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,38 @@
1
+ require 'cocoapods-bb-PodAssistant/config/source_manager'
2
+
3
+ module Pod
4
+ class Command
5
+ class Stable < Command
6
+ class Install < Stable
7
+ self.summary = '[命令同执行`pod install操作`] Install project dependencies according to versions from a Podfile.lock'
8
+
9
+ self.description = <<-DESC
10
+ Downloads all dependencies defined in `Podfile` and creates an Xcode
11
+ Pods library project in `./Pods`.
12
+
13
+ The Xcode project file should be specified in your `Podfile` like this:
14
+
15
+ project 'path/to/XcodeProject.xcodeproj'
16
+
17
+ If no project is specified, then a search for an Xcode project will
18
+ be made. If more than one Xcode project is found, the command will
19
+ raise an error.
20
+
21
+ This will configure the project to reference the Pods static library,
22
+ add a build configuration file, and add a post build script to copy
23
+ Pod resources.
24
+
25
+ This may return one of several error codes if it encounters problems.
26
+ * `1` Generic error code
27
+ * `31` Spec not found (i.e out-of-date source repos, mistyped Pod name etc...)
28
+ DESC
29
+
30
+ def run
31
+ puts "[PodAssistant] 开始执行 $ pod stable install".yellow
32
+ system "pod install"
33
+ puts "[PodAssistant] `pod stable install` complete!".green
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,32 @@
1
+ require 'cocoapods-bb-PodAssistant/config/source_manager'
2
+ require 'cocoapods-bb-PodAssistant/helpers/git_cmd_helper'
3
+ require 'cocoapods-bb-PodAssistant/helpers/stable_env_helper'
4
+ require 'cocoapods'
5
+
6
+ module Pod
7
+ class Command
8
+ class Stable < Command
9
+ class Sync < Stable
10
+
11
+ self.summary = '[同步远端yml配置] sync a Stable yml config file'
12
+
13
+ self.description = <<-DESC
14
+ 同步远端stable yml配置文件,并对本地文件进行合并操作
15
+ DESC
16
+
17
+ def initialize(argv)
18
+ super
19
+ end
20
+
21
+ def run
22
+ puts "开始合并远端stable yml数据".yellow
23
+ # 数据合并
24
+ source_manager = BB::SourceManager.new()
25
+ source_manager.merge_stable_data
26
+ puts "[PodAssistant] `pod stable sync` complete! Please execute the [pod install/ pod update] command".green
27
+ end
28
+
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,61 @@
1
+ require 'cocoapods-bb-PodAssistant/config/source_manager'
2
+
3
+ module Pod
4
+ class Command
5
+ class Stable < Command
6
+ class Update < Stable
7
+ self.summary = '[命令同执行`pod update操作`] Update outdated project dependencies and create new ' \
8
+ 'Podfile.lock'
9
+
10
+ self.description = <<-DESC
11
+ Updates the Pods identified by the specified `POD_NAMES`, which is a
12
+ space-delimited list of pod names. If no `POD_NAMES` are specified, it
13
+ updates all the Pods, ignoring the contents of the Podfile.lock. This
14
+ command is reserved for the update of dependencies; pod install should
15
+ be used to install changes to the Podfile.
16
+ DESC
17
+
18
+ self.arguments = [
19
+ CLAide::Argument.new('POD_NAMES', false, true),
20
+ ]
21
+
22
+ def self.options
23
+ [
24
+ ['--sync', '立即同步远端yml配置,更新组件信息'],
25
+ ].concat(super)
26
+ end
27
+
28
+ def initialize(argv)
29
+ @pods = argv.arguments!
30
+ @sync = argv.flag?('sync')
31
+ super
32
+ end
33
+
34
+ def run
35
+ puts "[PodAssistant] 开始执行 $ pod stable update".yellow
36
+ # system "git checkout Podfile.lock"
37
+ source_manager = BB::SourceManager.new()
38
+ # verify_podfile_exists! # 系统提供api验证podfile是否ok
39
+ if @sync
40
+ puts "[PodAssistant] 需要同步组件信息#{@pods}".green
41
+ source_manager.merge_stable_data(@pods)
42
+ end
43
+ podStartTime = Time.new
44
+ if @pods.any?
45
+ pods_str = @pods.join(" ")
46
+ system "pod update #{pods_str}"
47
+ else
48
+ system "pod update"
49
+ end
50
+ podEndTime = Time.new
51
+ # 获取时间差
52
+ time = podEndTime - podStartTime
53
+ puts "[PodAssistant] pod update操作总耗时【#{time.to_s.send(:red)}秒】start:#{podStartTime} end:#{podEndTime}".green
54
+
55
+ source_manager.update_local_stable_from_podmodules(@pods)
56
+ puts "[PodAssistant] `pod stable update` complete!".green
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,51 @@
1
+ require 'cocoapods-bb-PodAssistant/config/source_manager'
2
+ require 'cocoapods-bb-PodAssistant/config/cache_path'
3
+ require 'cocoapods-bb-PodAssistant/helpers'
4
+
5
+ require 'cocoapods-bb-PodAssistant/command/stable/init'
6
+ require 'cocoapods-bb-PodAssistant/command/stable/install'
7
+ require 'cocoapods-bb-PodAssistant/command/stable/update'
8
+ require 'cocoapods-bb-PodAssistant/command/stable/sync'
9
+
10
+ module Pod
11
+
12
+ # class StableOptions
13
+ # # define business specs,defalut is stable_specs
14
+ # option :business_specs, "stable_specs"
15
+
16
+ # # define custom lockSpecs tag
17
+ # option :tag, ""
18
+
19
+ # # define custom lockSpecs branch
20
+ # option :branch, ""
21
+ # end
22
+
23
+ class Command
24
+ class Stable < Command
25
+ self.abstract_command = true
26
+
27
+ self.summary = '拉取稳定Podfile.lock配置'
28
+ self.description = <<-DESC
29
+ 拉取稳定lock配置插件。利用版本比对进行更新配置实现对组件版本控制管理。
30
+ DESC
31
+
32
+ self.default_subcommand = 'init'
33
+
34
+ #-----------------------------------------------------------------------#
35
+
36
+ extend Executable
37
+ executable :git
38
+
39
+ def validate!
40
+ super
41
+ banner! if @help
42
+ end
43
+
44
+ def run
45
+ puts "[PodAssistant] `pod stable` 帮助文档请查看�".yellow
46
+ # banner!
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -1,9 +1,8 @@
1
- require 'cocoapods-bb-PodAssistant/command/PodAssistant'
2
1
  #stable
3
- require 'cocoapods-bb-PodAssistant/command/stable/stable'
4
- require 'cocoapods-bb-PodAssistant/command/stable/podfile-linkline'
2
+ require 'cocoapods-bb-PodAssistant/command/stable'
3
+ require 'cocoapods-bb-PodAssistant/babybus/stable/podfile-linkline'
5
4
  #linkline
6
- require 'cocoapods-bb-PodAssistant/command/linkline/linkline'
7
- require 'cocoapods-bb-PodAssistant/command/linkline/target-linkline'
8
- require 'cocoapods-bb-PodAssistant/command/linkline/targetdefinition-linkline'
9
- require 'cocoapods-bb-PodAssistant/command/linkline/targetValidator-linkline'
5
+ require 'cocoapods-bb-PodAssistant/command/linkline'
6
+ require 'cocoapods-bb-PodAssistant/babybus/linkline/target-linkline'
7
+ require 'cocoapods-bb-PodAssistant/babybus/linkline/targetdefinition-linkline'
8
+ require 'cocoapods-bb-PodAssistant/babybus/linkline/targetValidator-linkline'
@@ -1,4 +1,5 @@
1
1
  require 'cocoapods-bb-PodAssistant/config/stable_source'
2
+ require 'cocoapods-bb-PodAssistant/helpers/pod_utils'
2
3
 
3
4
  module BB
4
5
  class Cache
@@ -7,10 +8,15 @@ module BB
7
8
  stable_source = StableSource.stable_default_source
8
9
  end
9
10
  @stable_source = stable_source
11
+ @bundleId = BB::PodUtils.getProjectBundleIdentifier
12
+ if @bundleId.nil?
13
+ @bundleId = 'stable'
14
+ end
10
15
  end
11
16
 
12
17
  def cachePath()
13
- File.join(File.expand_path('~/.cache'), 'cocoapods-bb-PodAssistant','stable',@stable_source.split('/').last.chomp('.git').to_s)
18
+ # 缓存路径采用bundle包名区分,解决多产品同时打包问题
19
+ File.join(File.expand_path('~/.cache'), 'cocoapods-bb-PodAssistant',@bundleId,@stable_source.split('/').last.chomp('.git').to_s)
14
20
  end
15
21
  end
16
22
  end
@@ -2,12 +2,15 @@ require 'cocoapods-bb-PodAssistant/helpers'
2
2
  require 'cocoapods-bb-PodAssistant/config/stable_specs'
3
3
  require 'cocoapods-bb-PodAssistant/helpers/stable_manager_helper'
4
4
  require 'cocoapods-core'
5
+ require 'cocoapods-bb-PodAssistant/helpers/stable_env_helper'
5
6
 
6
7
  # 数据源管理
7
8
  module BB
8
9
  class SourceManager
9
- def initialize(businessSpecName = nil)
10
- @businessSpecName = businessSpecName
10
+ def initialize()
11
+ env = BB::StableEnv.new()
12
+ # puts "SourceManager env:#{env}".red
13
+ @businessSpecName = env.business_stable
11
14
  @stableMgr = BB::StableManager.new()
12
15
  end
13
16
 
@@ -91,10 +94,10 @@ module BB
91
94
  localSpec.writeData(local_stable_yaml, stable_lock)
92
95
  end
93
96
 
94
- # 合并stable数据
95
- def merge_stable_data()
97
+ # 合并stable数据,参数,支持传入更新某几个数据
98
+ def merge_stable_data(update_pods=[])
96
99
  #4、show origin_stable_lock diff with local_stable_lock
97
- new_stable_spec = compare_specs(fetch_local_stable_datas, fetch_origin_stable_datas)
100
+ new_stable_spec = compare_specs(fetch_local_stable_datas, fetch_origin_stable_datas, update_pods)
98
101
 
99
102
  #5、rewirte local_stable_lock with origin_stable_lock
100
103
  update_localstable_datas(new_stable_spec)
@@ -120,8 +123,8 @@ module BB
120
123
  return result
121
124
  end
122
125
 
123
- # compare specs 参数1:本地,参数2:远端
124
- def compare_specs(local_specs, common_specs)
126
+ # compare specs 参数1:本地,参数2:远端,参数3:指定更新pod库
127
+ def compare_specs(local_specs, common_specs, update_pods=[])
125
128
  added_projects = []
126
129
  updated_projects = []
127
130
  rollbacked_projects = []
@@ -144,15 +147,15 @@ module BB
144
147
  elsif local_version != version
145
148
  # puts "merge name:#{name} local_version:#{local_version} route_version:#{version}".red
146
149
  # 版本不一致
147
- if (version.is_a? String) && (local_version.is_a? String)
148
- end
149
- if versionGreat(version, local_version)
150
- updated_projects << "【#{name}】 (#{local_version}) -> (#{version.to_s.send(:yellow)})"
151
- else
152
- rollbacked_projects << "【#{name}】 (#{version.to_s.send(:red)}) <- (#{local_version})"
153
- end
154
150
  podCoreName = subspec_podname(name)
155
- need_update_pod_lists[podCoreName] = version
151
+ if (update_pods.length == 0) || (update_pods.include?(podCoreName))
152
+ if versionGreat(version, local_version)
153
+ updated_projects << "【#{name}】 (#{local_version}) -> (#{version.to_s.send(:yellow)})"
154
+ else
155
+ rollbacked_projects << "【#{name}】 (#{version.to_s.send(:red)}) <- (#{local_version})"
156
+ end
157
+ need_update_pod_lists[podCoreName] = version
158
+ end
156
159
  end
157
160
  end
158
161
  # 解决subspec组件同步更新版本信息
@@ -173,16 +176,20 @@ module BB
173
176
  end
174
177
  local_exist_ver = new_specs[name]
175
178
  if local_exist_ver.nil?
176
- new_specs[name] = version
177
- added_projects << "【#{name}】 (#{version.to_s.send(:green)})"
179
+ if (update_pods.length == 0) || (update_pods.include?(name))
180
+ new_specs[name] = version
181
+ added_projects << "【#{name}】 (#{version.to_s.send(:green)})"
182
+ end
178
183
  end
179
184
  if array.is_a?(Array)
180
185
  array.each do |name|
181
186
  name = name.to_s
182
187
  local_exist_ver = new_specs[name]
183
188
  if local_exist_ver.nil?
184
- new_specs[name] = version
185
- added_projects << "【#{name}】 (#{version.to_s.send(:green)})"
189
+ if (update_pods.length == 0) || (update_pods.include?(name))
190
+ new_specs[name] = version
191
+ added_projects << "【#{name}】 (#{version.to_s.send(:green)})"
192
+ end
186
193
  end
187
194
  end
188
195
  end
@@ -190,7 +197,6 @@ module BB
190
197
  # step.3 匹配组件移除
191
198
  removedata.each do |name|
192
199
  name = name.to_s
193
- # local_exist_ver = new_specs[name]
194
200
  version = listdata[name]
195
201
  if version
196
202
  deleted_projects << "【#{name}】 (#{"delete".send(:red)}) <- (#{version})"
@@ -242,6 +248,8 @@ module BB
242
248
  lockfile = podfile_lock
243
249
  local_specs = {}
244
250
  dependencies = lockfile.dependencies
251
+ pod_names = lockfile.pod_names
252
+ # dependencies依赖数据
245
253
  dependencies.each do | dependency |
246
254
  pod_name = dependency.name
247
255
  if has_include_subspec(pod_name)
@@ -249,6 +257,7 @@ module BB
249
257
  else
250
258
  podCoreName = pod_name
251
259
  end
260
+ # puts "podCoreName:#{podCoreName} pod_name:#{pod_name}".red
252
261
  if dependency.external_source.is_a? Hash
253
262
  # 指向分支
254
263
  external_source = dependency.external_source
@@ -271,6 +280,25 @@ module BB
271
280
  end
272
281
  end
273
282
  end
283
+ # 被依赖数据
284
+ pod_names.each do | pod_name |
285
+ if has_include_subspec(pod_name)
286
+ podCoreName = subspec_podname(pod_name)
287
+ else
288
+ podCoreName = pod_name
289
+ end
290
+ pod = local_specs[podCoreName]
291
+ # puts "podCoreName:#{podCoreName} pod:#{pod}".green
292
+ if pod.nil?
293
+ # 指向标签版本
294
+ version = lockfile.version(pod_name).to_s
295
+ if !version.empty? && !local_specs.has_key?(podCoreName)
296
+ local_specs[podCoreName] = version
297
+ # puts "[标签] #{podCoreName} => (#{version})".yellow
298
+ end
299
+ end
300
+ end
301
+
274
302
  # Pod::UI.puts "yml配置数据:#{local_specs}"
275
303
  if local_specs.length > 0
276
304
  update_localstable_datas(local_specs)
@@ -1,3 +1,3 @@
1
1
  module CocoapodsBbPodassistant
2
- VERSION = "0.1.6"
2
+ VERSION = "0.1.8"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  # cache stable
2
+ require 'cocoapods'
2
3
 
3
4
  ######################################## Git Command ########################################
4
5
  def configGitPath(gitPath)
@@ -66,7 +67,10 @@ def git_branch_exists?(branch)
66
67
  end
67
68
 
68
69
  def git_clone(source, path)
69
- puts "git clone source:#{source} path:#{path}"
70
+ puts "git clone source:#{source} path:#{path}".yellow
71
+ if !File.directory?(path)
72
+ Dir.mkdir(path)
73
+ end
70
74
  UI.section("Cloning `#{source}` into `#{path}`.") do
71
75
  Dir.chdir(path) { git! ['clone', source] } #origin git command
72
76
  end
@@ -158,16 +158,20 @@ module BB
158
158
  need_update_pod_data={}
159
159
  stable_hash = local_stable_data
160
160
  podfile_hash.each do |podName,podfile_pod|
161
+ if podfile_pod.count == 0
162
+ puts "❌ podfile组件配置异常,请确认:method => REMOTE_VERSION是否配置\n组件信息如下:\n#{podName} => #{podfile_pod}".red
163
+ exit
164
+ end
161
165
  podCoreName = @source_manager.subspec_podname(podName)
162
166
  if (podName == podCoreName) || @source_manager.has_pod_subspec(podName, podCoreName)
163
167
  pod = stable_hash[podCoreName]
164
168
  if pod.nil? # stbale没有受版本控制
165
169
  need_update_pod_data[podName] = podfile_pod
166
170
  else
167
- # puts "[stable]podCoreName:#{podCoreName}(#{pod}) VS [podfile] podName:#{podName}(#{podfile_pod})".yellow
168
- if podName == "BBWriteReview/World"
169
- puts "[stable]podCoreName:#{podCoreName}(#{pod}) VS [podfile] podName:#{podName}(#{podfile_pod})".yellow
170
- end
171
+ # if podCoreName == 'BBGameModule'
172
+ # succ = (pod == podfile_pod) ? true : false
173
+ # puts "[stable]podCoreName:#{podCoreName}(#{pod}) VS [podfile] podName:#{podName}(#{podfile_pod}) succ:#{succ}".green
174
+ # end
171
175
  if pod == podfile_pod
172
176
  if podName != podCoreName
173
177
  need_update_pod_data[podName] = podfile_pod
@@ -206,9 +210,42 @@ module BB
206
210
  need_update_pod_data[podName] = pod
207
211
  end
208
212
  else
209
- if podName != podCoreName
210
- # puts "[PodAssistant] '#{podName}', '#{pod.send(:red)}' 以stable配置为主."
211
- need_update_pod_data[podName] = pod
213
+ is_podfile_data = false
214
+ newPod = nil
215
+ if pod.is_a? (Hash)
216
+ stable_branch = pod[:branch]
217
+ stable_git = pod[:git]
218
+ if stable_git.nil?
219
+ stable_git = pod[:git_format]
220
+ end
221
+ if (stable_branch && !stable_branch.empty?) || (stable_git && !stable_git.empty?)
222
+ puts "[PodAssistant] '#{podName}', '#{podfile_pod}' 以podfile配置为主[分支=>标签]."
223
+ newPod = podfile_pod
224
+ is_podfile_data = true
225
+ else
226
+ newPod = pod
227
+ end
228
+ elsif pod.is_a? (String)
229
+ if pod.include?(':branch') || pod.include?(':git') || pod.include?(':git_format')
230
+ puts "[PodAssistant] '#{podName}', '#{podfile_pod}' 以podfile配置为主[分支=>标签]."
231
+ newPod = podfile_pod
232
+ is_podfile_data = true
233
+ else
234
+ newPod = pod
235
+ end
236
+ else
237
+ newPod = podfile_pod
238
+ is_podfile_data = true
239
+ end
240
+ if is_podfile_data == true
241
+ need_update_pod_data[podCoreName] = newPod
242
+ if podName != podCoreName
243
+ need_update_pod_data[podName] = newPod
244
+ end
245
+ else
246
+ if podName != podCoreName
247
+ need_update_pod_data[podName] = newPod
248
+ end
212
249
  end
213
250
  end
214
251
  end
@@ -1,36 +1,133 @@
1
- require 'cocoapods-bb-PodAssistant/helpers/git_cmd_helper'
2
1
  require 'cocoapods-bb-PodAssistant/config/stable_source'
3
2
 
4
3
  module BB
5
- class StableEnv
6
- def initialize(stable_source = nil, stable_branch = nil, stable_tag = nil)
7
- if stable_source.nil?
8
- stable_source = StableSource.stable_default_source
9
- end
10
- @stable_source = stable_source
11
- @stable_branch = stable_branch
12
- @stable_tag = stable_tag
13
-
4
+ class StableEnv
5
+ def initialize()
14
6
  @cache = BB::Cache.new()
15
7
  configGitPath(@cache.cachePath)
8
+ # 自动加载stable环境
9
+ loadStaleEnv
10
+ if verify_stable_env_exists == false
11
+ puts "[PodAssistant] ❌工程没有配置stable环境".red
12
+ else
13
+ fetch_stale_git # 自动拉取远端git仓库数据
14
+ end
16
15
  end
17
16
 
18
17
  # stable 环境,执行pod stable
19
18
  def loadStaleEnv
20
-
19
+ unless File.exist?(File.join(Pathname.pwd, "Podfile"))
20
+ err_msg = "- Error: #{File.join(Pathname.pwd, "Podfile")} is not exit"
21
+ Pod::UI.puts "#{err_msg}".send(:red)
22
+ exit -9001
23
+ end
24
+
25
+ #获取podfile 内容
26
+ #1、删除所有注释行,避免干扰
27
+ #2、正则匹配,筛选出stable 方法
28
+ #3、执行stable 方法,获取配置
29
+ podfileContent = File.read(File.join(Pathname.pwd, "Podfile"))
30
+ podfileContent_vaild = podfileContent.lines.reject { |line| line.strip.start_with?("#") }.join
31
+ stableCommand = podfileContent_vaild.match(/^\s*stable!\s*'([^']+)'(?:,\s*(\w+):\s*'([^']+)')*/m)
32
+ unless stableCommand
33
+ puts "- Error: not stable define in the podfile! you can define to podfile:".red
34
+ puts "stable! 'https://git.babybus.co/babybus/ios/Specs/stable-specs.git', specs:'<业务线stbale名称-可选>', tag:'<标签-可选>', branch:'<分支-可选>'".green
35
+ exit -9002
36
+ end
37
+ eval(stableCommand.to_s)
21
38
  end
22
39
 
23
- # 开发环境,执行pod install/update
24
- def loadDeveloperEnv
40
+ # 拉取stable仓库代码 hook开发环境,执行pod install/update
41
+ def system_clone_stable_git
25
42
  cachePath = @cache.cachePath
26
- puts "hook [pod install/update] sync stable git=>#{cachePath}"
27
- if Dir.exist?(File.join(cachePath))
28
- `cd #{cachePath}; git switch main; git pull --all`
29
- else
43
+ puts "hook [pod install/update] fetch stable git=>#{cachePath}"
44
+ if !Dir.exist?(File.join(cachePath))
30
45
  clonePath = File.dirname(cachePath)
31
46
  FileUtils.mkdir_p clonePath
32
- `git clone #{@stable_source} #{cachePath}`
47
+ system "git clone #{@stable_source} #{cachePath}"
48
+ end
49
+ if verify_branch_exists
50
+ if stable_tag || stable_branch
51
+ if stable_branch
52
+ system "cd #{cachePath}; git checkout #{stable_branch}; git reset --hard origin/#{stable_branch}"
53
+ end
54
+ if stable_tag
55
+ system "cd #{cachePath}; git checkout #{stable_tag};"
56
+ end
57
+ else
58
+ result =`git symbolic-ref refs/remotes/origin/HEAD`
59
+ protechBranch = result.split("/").last.strip || default_branch
60
+ system "cd #{cachePath}; git checkout #{protechBranch}; git reset --hard origin/#{protechBranch}"
61
+ end
62
+ else
63
+ puts "❌ stable配置无效分支信息source:#{@stable_source} branch:#{stable_branch}".red
64
+ exit
65
+ end
66
+ end
67
+ def fetch_stale_git
68
+ system_clone_stable_git
69
+ end
70
+
71
+ # ========podfile 约定函数规则,切勿修改
72
+ #help load podfile option
73
+ def stable!(source, options = {})
74
+ @stable_source = source
75
+ if options.has_key?(:specs)
76
+ @businessSpec = options[:specs]
77
+ end
78
+ @stable_tag = options[:tag] if options.has_key?(:tag)
79
+ @stable_branch = options[:branch] if options.has_key?(:branch)
80
+ puts "###stable env => [stable公共源]:#{source} [业务线源名称]:#{@businessSpec} branch:#{@stable_branch} tag:#{@stable_tag}".green
81
+ end
82
+
83
+ def stable_source
84
+ return @stable_source
85
+ end
86
+ def default_branch
87
+ return "main"
88
+ end
89
+ def stable_branch
90
+ if @stable_branch.nil?
91
+ return default_branch
92
+ end
93
+ return @stable_branch
94
+ end
95
+ def stable_tag
96
+ return @stable_tag
97
+ end
98
+ def business_stable
99
+ return @businessSpec
100
+ end
101
+ # 验证stable环境是否存在
102
+ def verify_stable_env_exists
103
+ return @stable_source.empty? ? false : true
104
+ end
105
+ # tag是否存在
106
+ def verify_tag_exists
107
+ tag = stable_tag
108
+ if tag
109
+ cachePath = @cache.cachePath
110
+ # result = system "cd #{cachePath}; git tag"
111
+ result = `cd #{cachePath}; git tag`
112
+ puts "verify_tag_exists:#{result}".red
113
+ return result.split("\n").include?(tag)
114
+ end
115
+ return false
116
+ end
117
+ # 分支是否存在
118
+ def verify_branch_exists
119
+ branch = stable_branch
120
+ if branch
121
+ cachePath = @cache.cachePath
122
+ # result = system "cd #{cachePath}; git tag"
123
+ branchs = `cd #{cachePath}; git branch -a`
124
+ if branchs
125
+ branchs = branchs.split("\n")
126
+ return branchs.include?(branch) || branchs.include?(' remotes/origin/' + branch) || branchs.include?('remotes/origin/' + branch)
33
127
  end
128
+ puts "verify_branch_exists:#{branchs}".red
129
+ end
130
+ return false
34
131
  end
35
132
  end
36
133
  end
@@ -42,6 +42,7 @@ end
42
42
 
43
43
  $podStartTime = 0
44
44
  $podEndTime = 0
45
+ $source_manager = nil
45
46
 
46
47
  module BB
47
48
 
@@ -49,8 +50,7 @@ module BB
49
50
  begin
50
51
  $podStartTime = Time.new
51
52
  puts "[PodAssistant] plugin hook pre_install".yellow
52
- env = BB::StableEnv.new()
53
- env.loadDeveloperEnv
53
+ $source_manager = BB::SourceManager.new() # 自动拉取远端git仓库数据
54
54
  if $pluginIsVerbose == true
55
55
  # home路径下是否存在.AllPodsTimeAndSize.csv的隐藏文件
56
56
  if File.exist?("#{Dir.home}/.AllPodsTimeAndSize.csv")
@@ -68,9 +68,8 @@ module BB
68
68
  end
69
69
  Pod::HooksManager.register("cocoapods-bb-PodAssistant", :post_install) do |installer|
70
70
  begin
71
- source_manager = BB::SourceManager.new(@businessSpec)
72
71
  # 生成本地yml配置
73
- source_manager.generate_localStable
72
+ $source_manager.generate_localStable
74
73
  $podEndTime = Time.new
75
74
  puts "[PodAssistant] plugin hook post_install".yellow
76
75
  puts "[PodAssistant] pod库下载耗时 GitCloneAllSize: #{$gitAllSize} M GitCloneAllTime: #{$cloneAllTime} S CDNDownloadAllSize: #{$pluginCurrentZipAllSize} M CDNAllTime: #{$downloadAllTime} S CDNDownloadAllTime: #{$cdnDownloadAllTime} S CDNUnzipAllTime: #{$cdnUnZipAllTime} S"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-bb-PodAssistant
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - humin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-10-13 00:00:00.000000000 Z
11
+ date: 2023-10-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cocoapods-core
@@ -79,14 +79,17 @@ files:
79
79
  - lib/cocoapods-bb-PodAssistant/babybus/business/babybus_install_environment.rb
80
80
  - lib/cocoapods-bb-PodAssistant/babybus/helpers/babybus_info_plist_helper.rb
81
81
  - lib/cocoapods-bb-PodAssistant/babybus/installer/post_install_hooks.rb
82
+ - lib/cocoapods-bb-PodAssistant/babybus/linkline/target-linkline.rb
83
+ - lib/cocoapods-bb-PodAssistant/babybus/linkline/targetValidator-linkline.rb
84
+ - lib/cocoapods-bb-PodAssistant/babybus/linkline/targetdefinition-linkline.rb
85
+ - lib/cocoapods-bb-PodAssistant/babybus/stable/podfile-linkline.rb
82
86
  - lib/cocoapods-bb-PodAssistant/command.rb
83
- - lib/cocoapods-bb-PodAssistant/command/PodAssistant.rb
84
- - lib/cocoapods-bb-PodAssistant/command/linkline/linkline.rb
85
- - lib/cocoapods-bb-PodAssistant/command/linkline/target-linkline.rb
86
- - lib/cocoapods-bb-PodAssistant/command/linkline/targetValidator-linkline.rb
87
- - lib/cocoapods-bb-PodAssistant/command/linkline/targetdefinition-linkline.rb
88
- - lib/cocoapods-bb-PodAssistant/command/stable/podfile-linkline.rb
89
- - lib/cocoapods-bb-PodAssistant/command/stable/stable.rb
87
+ - lib/cocoapods-bb-PodAssistant/command/linkline.rb
88
+ - lib/cocoapods-bb-PodAssistant/command/stable.rb
89
+ - lib/cocoapods-bb-PodAssistant/command/stable/init.rb
90
+ - lib/cocoapods-bb-PodAssistant/command/stable/install.rb
91
+ - lib/cocoapods-bb-PodAssistant/command/stable/sync.rb
92
+ - lib/cocoapods-bb-PodAssistant/command/stable/update.rb
90
93
  - lib/cocoapods-bb-PodAssistant/config/cache_path.rb
91
94
  - lib/cocoapods-bb-PodAssistant/config/source_manager.rb
92
95
  - lib/cocoapods-bb-PodAssistant/config/stable_source.rb
@@ -1,44 +0,0 @@
1
- module Pod
2
- class Command
3
- # This is an example of a cocoapods plugin adding a top-level subcommand
4
- # to the 'pod' command.
5
- #
6
- # You can also create subcommands of existing or new commands. Say you
7
- # wanted to add a subcommand to `list` to show newly deprecated pods,
8
- # (e.g. `pod list deprecated`), there are a few things that would need
9
- # to change.
10
- #
11
- # - move this file to `lib/pod/command/list/deprecated.rb` and update
12
- # the class to exist in the the Pod::Command::List namespace
13
- # - change this class to extend from `List` instead of `Command`. This
14
- # tells the plugin system that it is a subcommand of `list`.
15
- # - edit `lib/cocoapods_plugins.rb` to require this file
16
- #
17
- # @todo Create a PR to add your plugin to CocoaPods/cocoapods.org
18
- # in the `plugins.json` file, once your plugin is released.
19
- #
20
- class Podassistant < Command
21
- self.summary = 'Short description of cocoapods-bb-PodAssistant.'
22
-
23
- self.description = <<-DESC
24
- Longer description of cocoapods-bb-PodAssistant.
25
- DESC
26
-
27
- # self.arguments = 'NAME'
28
-
29
- def initialize(argv)
30
- # @name = argv.shift_argument
31
- super
32
- end
33
-
34
- def validate!
35
- super
36
- # help! 'A Pod name is required.' unless @name
37
- end
38
-
39
- def run
40
- UI.puts "Add your implementation for the cocoapods-bb-PodAssistant plugin in #{__FILE__}"
41
- end
42
- end
43
- end
44
- end
@@ -1,168 +0,0 @@
1
- require 'cocoapods-bb-PodAssistant/config/source_manager'
2
- require 'cocoapods-bb-PodAssistant/config/cache_path'
3
- require 'cocoapods-bb-PodAssistant/helpers'
4
-
5
- module Pod
6
-
7
- # class StableOptions
8
- # # define business specs,defalut is stable_specs
9
- # option :business_specs, "stable_specs"
10
-
11
- # # define custom lockSpecs tag
12
- # option :tag, ""
13
-
14
- # # define custom lockSpecs branch
15
- # option :branch, ""
16
- # end
17
-
18
- class Command
19
- class Stable < Command
20
- require 'fileutils'
21
- require 'cocoapods/executable.rb'
22
- extend Executable
23
- executable :git
24
-
25
- self.summary = '拉取稳定lock配置'
26
- self.description = <<-DESC
27
- 拉取稳定lock配置插件。利用版本比对进行更新配置实现对组件版本控制管理。
28
- DESC
29
-
30
- self.arguments = [
31
- CLAide::Argument.new('Podfile', false)
32
- ]
33
- def self.options
34
- [
35
- ['--init', '初始化项目yml配置,根据当前项目Podfile.lock生成'],
36
- ['--sync', '同步远端yml配置,更新项目yml配置'],
37
- ['--install', '命令同执行`pod install操作`'],
38
- ['--update', '命令同执行`pod update操作`'],
39
- ['--update-pod', '命令同执行`pod update <组件>操作`,更新yml配置组件版本信息,多个组件使用`,`或者`空格`隔开,注意⚠️ 使用`空格`需要使用双引号'],
40
- ].concat(super)
41
- end
42
-
43
- def initialize(argv)
44
- @names = argv.arguments! unless argv.arguments.empty?
45
- @help = argv.flag?('help')
46
- @init = argv.flag?('init')
47
- @sync = argv.flag?('sync')
48
- # install操作
49
- @install = argv.flag?('install')
50
- @update = argv.flag?('update')
51
- # update组件数据支持多个使用`,`或者`空格`隔开
52
- update_pods = argv.option('update-pod','')
53
- if !update_pods.empty?
54
- if update_pods.include?(' ')
55
- @update_pods = update_pods.split(' ') unless update_pods.nil?
56
- else update_pods.include?(',')
57
- @update_pods = update_pods.split(',') unless update_pods.nil?
58
- end
59
- end
60
- super
61
- end
62
- def validate!
63
- super
64
- banner! if @help
65
- end
66
-
67
- #help load podfile option
68
- def stable!(source, options = {})
69
- @ll_stable_source = source
70
- if options.has_key?(:specs)
71
- @businessSpec = options[:specs]
72
- puts "当前业务使用源=>#{@businessSpec}"
73
- end
74
- @ll_stable_tag = options[:tag] if options.has_key?(:tag)
75
- @ll_stable_branch = options[:branch] if options.has_key?(:branch)
76
- @cache = BB::Cache.new()
77
- configGitPath(@cache.cachePath)
78
- end
79
-
80
- ######################################## Main ########################################
81
-
82
- def run
83
- # begin
84
- source_manager = BB::SourceManager.new(@businessSpec)
85
- if @init
86
- puts "[PodAssistant] 开始配置生成当前项目yml文件".yellow
87
- # 生成本地yml配置
88
- source_manager.generate_localStable
89
- puts "[PodAssistant] `pod stable --init` complete!".green
90
- elsif @install
91
- puts "[PodAssistant] 执行 $ pod install".yellow
92
- system "pod install"
93
- puts "[PodAssistant] `pod stable --install` complete!".green
94
- elsif @update
95
- puts "[PodAssistant] 执行 $ pod update".yellow
96
- system "pod update"
97
- puts "[PodAssistant] `pod stable --update` complete!".green
98
- elsif @update_pods
99
- # 更新单个组件
100
- puts "更新pod组件#{@update_pods} count:#{@update_pods.count}".yellow
101
- source_manager.update_podmodules(@update_pods)
102
- podnames = @update_pods.join(" ")
103
- puts "[PodAssistant] 执行 $ pod update #{podnames}".yellow
104
- system "pod update #{podnames}"
105
- source_manager.update_local_stable_from_podmodules(@update_pods)
106
- podnames = @update_pods.join(",")
107
- puts "[PodAssistant] `pod stable --update-pod=#{podnames}` complete!".green
108
- elsif @sync
109
- puts "开始合并远端lock数据".yellow
110
- ll_load_stable
111
- #2、clone origin lock spec to cache dir
112
- ll_cloneStable
113
- #3、fetch newest code
114
- ll_fetch_stale_git
115
- # 数据合并
116
- source_manager.merge_stable_data
117
- puts "[PodAssistant] `pod stable` complete! Please execute the [pod install/ pod update] command".green
118
- else
119
- puts "[PodAssistant] `pod stable` 帮助文档请查看👇".yellow
120
- banner!
121
- end
122
- # rescue => exception
123
- # puts "[pod stable] error(已捕获): #{exception}".red
124
- # end
125
-
126
- end
127
-
128
- private
129
- ######################################## API ########################################
130
- def ll_load_stable
131
- unless File.exist?(File.join(Pathname.pwd, "Podfile"))
132
- err_msg = "- Error: #{File.join(Pathname.pwd, "Podfile")} is not exit"
133
- Pod::UI.puts "#{err_msg}".send(:red)
134
- exit -9001
135
- end
136
-
137
- #获取podfile 内容
138
- #1、删除所有注释行,避免干扰
139
- #2、正则匹配,筛选出stable 方法
140
- #3、执行stable 方法,获取配置
141
- podfileContent = File.read(File.join(Pathname.pwd, "Podfile"))
142
- podfileContent_vaild = podfileContent.lines.reject { |line| line.strip.start_with?("#") }.join
143
- stableCommand = podfileContent_vaild.match(/^\s*stable!\s*'([^']+)'(?:,\s*(\w+):\s*'([^']+)')*/m)
144
- unless stableCommand
145
- err_msg = "- Error: not stable define in the podfile! you can define like【stable! 'https://git.babybus.co/babybus/ios/Specs/stable-specs.git', specs:'global_stable_specs'】in podfile"
146
- Pod::UI.puts "#{err_msg}".send(:red)
147
- exit -9002
148
- end
149
- eval(stableCommand.to_s)
150
- end
151
- def ll_cloneStable
152
- cachePath = @cache.cachePath
153
- unless Dir.exist?(File.join(cachePath))
154
- clonePath = File.dirname(cachePath)
155
- FileUtils.mkdir_p clonePath
156
- git_clone(@stable_source,clonePath)
157
- end
158
- end
159
-
160
- def ll_fetch_stale_git
161
- git_reset
162
- git_fetch
163
- git_checkout_and_pull(@stable_source, @stable_branch, @stable_tag)
164
- end
165
-
166
- end
167
- end
168
- end