cocoapods-bb-PodAssistant 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +48 -0
- data/lib/cocoapods-bb-PodAssistant/babybus/business/babybus_install_environment.rb +129 -0
- data/lib/cocoapods-bb-PodAssistant/babybus/helpers/babybus_info_plist_helper.rb +92 -0
- data/lib/cocoapods-bb-PodAssistant/babybus/installer/post_install_hooks.rb +111 -0
- data/lib/cocoapods-bb-PodAssistant/command/PodAssistant.rb +44 -0
- data/lib/cocoapods-bb-PodAssistant/command/linkline/linkline.rb +68 -0
- data/lib/cocoapods-bb-PodAssistant/command/linkline/target-linkline.rb +9 -0
- data/lib/cocoapods-bb-PodAssistant/command/linkline/targetValidator-linkline.rb +25 -0
- data/lib/cocoapods-bb-PodAssistant/command/linkline/targetdefinition-linkline.rb +37 -0
- data/lib/cocoapods-bb-PodAssistant/command/stable/podfile-linkline.rb +9 -0
- data/lib/cocoapods-bb-PodAssistant/command/stable/stable.rb +168 -0
- data/lib/cocoapods-bb-PodAssistant/command.rb +9 -0
- data/lib/cocoapods-bb-PodAssistant/config/cache_path.rb +16 -0
- data/lib/cocoapods-bb-PodAssistant/config/source_manager.rb +389 -0
- data/lib/cocoapods-bb-PodAssistant/config/stable_source.rb +7 -0
- data/lib/cocoapods-bb-PodAssistant/config/stable_specs.rb +27 -0
- data/lib/cocoapods-bb-PodAssistant/gem_version.rb +3 -0
- data/lib/cocoapods-bb-PodAssistant/helpers/git_cmd_helper.rb +73 -0
- data/lib/cocoapods-bb-PodAssistant/helpers/pod_module_helper.rb +246 -0
- data/lib/cocoapods-bb-PodAssistant/helpers/pod_utils.rb +128 -0
- data/lib/cocoapods-bb-PodAssistant/helpers/stable_env_helper.rb +36 -0
- data/lib/cocoapods-bb-PodAssistant/helpers/stable_manager_helper.rb +85 -0
- data/lib/cocoapods-bb-PodAssistant/helpers/yaml_files_helper.rb +72 -0
- data/lib/cocoapods-bb-PodAssistant/helpers.rb +6 -0
- data/lib/cocoapods-bb-PodAssistant/podfile.rb +392 -0
- data/lib/cocoapods-bb-PodAssistant/source_provider_hook.rb +335 -0
- data/lib/cocoapods-bb-PodAssistant.rb +1 -0
- data/lib/cocoapods_plugin.rb +9 -0
- data/spec/command/PodAssistant_spec.rb +12 -0
- data/spec/spec_helper.rb +50 -0
- metadata +132 -0
@@ -0,0 +1,168 @@
|
|
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!".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
|
@@ -0,0 +1,9 @@
|
|
1
|
+
require 'cocoapods-bb-PodAssistant/command/PodAssistant'
|
2
|
+
#stable
|
3
|
+
require 'cocoapods-bb-PodAssistant/command/stable/stable'
|
4
|
+
require 'cocoapods-bb-PodAssistant/command/stable/podfile-linkline'
|
5
|
+
#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'
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'cocoapods-bb-PodAssistant/config/stable_source'
|
2
|
+
|
3
|
+
module BB
|
4
|
+
class Cache
|
5
|
+
def initialize(stable_source = nil)
|
6
|
+
if stable_source.nil?
|
7
|
+
stable_source = StableSource.stable_default_source
|
8
|
+
end
|
9
|
+
@stable_source = stable_source
|
10
|
+
end
|
11
|
+
|
12
|
+
def cachePath()
|
13
|
+
File.join(File.expand_path('~/.cache'), 'cocoapods-bb-PodAssistant','stable',@stable_source.split('/').last.chomp('.git').to_s)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,389 @@
|
|
1
|
+
require 'cocoapods-bb-PodAssistant/helpers'
|
2
|
+
require 'cocoapods-bb-PodAssistant/config/stable_specs'
|
3
|
+
require 'cocoapods-bb-PodAssistant/helpers/stable_manager_helper'
|
4
|
+
require 'cocoapods-core'
|
5
|
+
|
6
|
+
# 数据源管理
|
7
|
+
module BB
|
8
|
+
class SourceManager
|
9
|
+
def initialize(businessSpecName = nil)
|
10
|
+
@businessSpecName = businessSpecName
|
11
|
+
@stableMgr = BB::StableManager.new()
|
12
|
+
end
|
13
|
+
|
14
|
+
# 公共源路径(远端)
|
15
|
+
def public_stable_yaml
|
16
|
+
return @stableMgr.public_stable_yaml
|
17
|
+
end
|
18
|
+
|
19
|
+
# 业务源路径(远端)
|
20
|
+
def business_stable_yaml
|
21
|
+
return @stableMgr.business_stable_yaml(@businessSpecName)
|
22
|
+
end
|
23
|
+
|
24
|
+
# 本地源路径
|
25
|
+
def local_stable_yaml
|
26
|
+
return @stableMgr.local_stable_yaml
|
27
|
+
end
|
28
|
+
|
29
|
+
# 产品线本地lock数据
|
30
|
+
def fetch_local_stable_datas
|
31
|
+
localSpec = BB::StableSpecs.new()
|
32
|
+
return localSpec.readData(local_stable_yaml)
|
33
|
+
end
|
34
|
+
|
35
|
+
# 远端公共lock数据
|
36
|
+
def fetch_origin_stable_datas
|
37
|
+
# 策略:公共数据包含通用数据 + 业务线数据
|
38
|
+
pubSpec = BB::StableSpecs.new()
|
39
|
+
common_data = pubSpec.readData(public_stable_yaml)
|
40
|
+
# 业务线数据
|
41
|
+
business_config_file = business_stable_yaml
|
42
|
+
if business_config_file
|
43
|
+
if File.exist?(business_config_file)
|
44
|
+
busimessSpec = BB::StableSpecs.new()
|
45
|
+
busimess_data = busimessSpec.readData(business_config_file)
|
46
|
+
else
|
47
|
+
puts "业务线公共配置文件#{business_config_file}不存在,请确认!!!". send(:yellow)
|
48
|
+
exit
|
49
|
+
end
|
50
|
+
end
|
51
|
+
if busimess_data
|
52
|
+
# 数据合并操作(策略:业务线公共盖通用数据,理论不存在该情况)
|
53
|
+
newData = common_data
|
54
|
+
listdata = newData[YAML_CONFIG_LIST_KEY]
|
55
|
+
removedata = newData[YAML_CONFIG_REMOVE_KEY]
|
56
|
+
dependenciesdata = newData[YAML_CONFIG_DEPENDENCIES_KEY]
|
57
|
+
busimess_data.each do | key, val|
|
58
|
+
if key == YAML_CONFIG_LIST_KEY
|
59
|
+
if val.is_a?(Hash)
|
60
|
+
val.each do |list_name,list_ver|
|
61
|
+
listdata[list_name] = list_ver
|
62
|
+
end
|
63
|
+
end
|
64
|
+
elsif key == YAML_CONFIG_REMOVE_KEY
|
65
|
+
if val.is_a?(Array)
|
66
|
+
val.each do |remove_name|
|
67
|
+
removedata.push(remove_name)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
elsif key == YAML_CONFIG_DEPENDENCIES_KEY
|
71
|
+
if val.is_a?(Hash)
|
72
|
+
val.each do |dependencies_name,dependencies_val|
|
73
|
+
dependenciesdata[dependencies_name] = dependencies_val
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
return newData
|
79
|
+
end
|
80
|
+
return common_data
|
81
|
+
end
|
82
|
+
|
83
|
+
# 更新本地lock数据
|
84
|
+
def update_localstable_datas(stable_lock)
|
85
|
+
localSpec = BB::StableSpecs.new()
|
86
|
+
localSpec.writeData(local_stable_yaml, stable_lock)
|
87
|
+
end
|
88
|
+
|
89
|
+
# 合并stable数据
|
90
|
+
def merge_stable_data()
|
91
|
+
#4、show origin_stable_lock diff with local_stable_lock
|
92
|
+
new_stable_spec = compare_specs(fetch_local_stable_datas, fetch_origin_stable_datas)
|
93
|
+
|
94
|
+
#5、rewirte local_stable_lock with origin_stable_lock
|
95
|
+
update_localstable_datas(new_stable_spec)
|
96
|
+
end
|
97
|
+
|
98
|
+
######################################## Help ########################################
|
99
|
+
# compare tags (>=)
|
100
|
+
def versionGreatOrEqual(tag1, tag2)
|
101
|
+
if (tag1.is_a? String) && (tag2.is_a? String) && tag1.to_i >= tag2.to_i
|
102
|
+
return true
|
103
|
+
else
|
104
|
+
return false
|
105
|
+
end
|
106
|
+
return true
|
107
|
+
end
|
108
|
+
|
109
|
+
# compare tags (>)
|
110
|
+
def versionGreat(tag1, tag2)
|
111
|
+
result = versionGreatOrEqual(tag1,tag2)
|
112
|
+
if result == true && tag1 == tag2
|
113
|
+
return false
|
114
|
+
end
|
115
|
+
return result
|
116
|
+
end
|
117
|
+
|
118
|
+
# compare specs 参数1:本地,参数2:远端
|
119
|
+
def compare_specs(local_specs, common_specs)
|
120
|
+
added_projects = []
|
121
|
+
updated_projects = []
|
122
|
+
rollbacked_projects = []
|
123
|
+
deleted_projects = []
|
124
|
+
new_specs = local_specs
|
125
|
+
|
126
|
+
listdata = common_specs[YAML_CONFIG_LIST_KEY]
|
127
|
+
removedata = common_specs[YAML_CONFIG_REMOVE_KEY]
|
128
|
+
dependenciesdata = common_specs[YAML_CONFIG_DEPENDENCIES_KEY]
|
129
|
+
|
130
|
+
# puts "local_specs:#{local_specs}".send(:green)
|
131
|
+
# puts "common_specs:#{common_specs}".send(:green)
|
132
|
+
need_update_pod_lists={}
|
133
|
+
# step.1 匹配组件版本信息
|
134
|
+
listdata.each do |name, version|
|
135
|
+
name = name.to_s
|
136
|
+
local_version = local_specs[name]
|
137
|
+
if local_version.nil?
|
138
|
+
# 本地不存在这个数据
|
139
|
+
elsif local_version != version
|
140
|
+
# puts "merge name:#{name} local_version:#{local_version} route_version:#{version}".red
|
141
|
+
# 版本不一致
|
142
|
+
if (version.is_a? String) && (local_version.is_a? String)
|
143
|
+
end
|
144
|
+
if versionGreat(version, local_version)
|
145
|
+
updated_projects << "【#{name}】 (#{local_version}) -> (#{version.to_s.send(:yellow)})"
|
146
|
+
else
|
147
|
+
rollbacked_projects << "【#{name}】 (#{version.to_s.send(:red)}) <- (#{local_version})"
|
148
|
+
end
|
149
|
+
podCoreName = subspec_podname(name)
|
150
|
+
need_update_pod_lists[podCoreName] = version
|
151
|
+
end
|
152
|
+
end
|
153
|
+
# 解决subspec组件同步更新版本信息
|
154
|
+
need_update_pod_lists.each do |podCoreName, version|
|
155
|
+
new_specs.keys.each do |podName|
|
156
|
+
if (podName == podCoreName) || has_pod_subspec(podName, podCoreName)
|
157
|
+
new_specs[podName] = version
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
# step.2 匹配组件新增
|
162
|
+
dependenciesdata.each do |name, array|
|
163
|
+
name = name.to_s
|
164
|
+
version = listdata[name]
|
165
|
+
unless version
|
166
|
+
puts "公共库缺少[#{name}]版本依赖 cls:#{listdata.class} listdata:#{listdata}".send(:red)
|
167
|
+
exit
|
168
|
+
end
|
169
|
+
local_exist_ver = new_specs[name]
|
170
|
+
if local_exist_ver.nil?
|
171
|
+
new_specs[name] = version
|
172
|
+
added_projects << "【#{name}】 (#{version.to_s.send(:green)})"
|
173
|
+
end
|
174
|
+
if array.is_a?(Array)
|
175
|
+
array.each do |name|
|
176
|
+
name = name.to_s
|
177
|
+
local_exist_ver = new_specs[name]
|
178
|
+
if local_exist_ver.nil?
|
179
|
+
new_specs[name] = version
|
180
|
+
added_projects << "【#{name}】 (#{version.to_s.send(:green)})"
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
end
|
185
|
+
# step.3 匹配组件移除
|
186
|
+
removedata.each do |name|
|
187
|
+
name = name.to_s
|
188
|
+
# local_exist_ver = new_specs[name]
|
189
|
+
version = listdata[name]
|
190
|
+
if version
|
191
|
+
deleted_projects << "【#{name}】 (#{"delete".send(:red)}) <- (#{version})"
|
192
|
+
end
|
193
|
+
new_specs.delete(name)
|
194
|
+
end
|
195
|
+
showMergeLog(added_projects, updated_projects, rollbacked_projects, deleted_projects)
|
196
|
+
# puts "new_specs:#{new_specs}".send(:red)
|
197
|
+
return new_specs
|
198
|
+
end
|
199
|
+
|
200
|
+
def showMergeLog(added, updated, rollbacked, deleted)
|
201
|
+
#31m: 红色 32m:绿色 33m:黄色 34m:蓝色
|
202
|
+
#puts "\e[34m#{string}\e[0m"
|
203
|
+
if added.any?
|
204
|
+
puts "新增了以下项目:".send(:green)
|
205
|
+
puts added.join("\n")
|
206
|
+
end
|
207
|
+
|
208
|
+
if updated.any?
|
209
|
+
puts "更新了以下项目:". send(:yellow)
|
210
|
+
puts updated.join("\n")
|
211
|
+
end
|
212
|
+
|
213
|
+
if rollbacked.any?
|
214
|
+
puts "回滚了以下项目:".send(:red)
|
215
|
+
puts rollbacked.join("\n")
|
216
|
+
end
|
217
|
+
|
218
|
+
if deleted.any?
|
219
|
+
puts "移除了以下项目:".send(:red)
|
220
|
+
puts deleted.join("\n")
|
221
|
+
end
|
222
|
+
|
223
|
+
unless added.any? || updated.any? || added.any? || deleted.any?
|
224
|
+
puts "已经是最新版本数据".send(:green)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
private def podfile_lock
|
228
|
+
lock = File.join(Pathname.pwd,"Podfile.lock")
|
229
|
+
raise "podfile.lock,不存在,请先pod install/update" unless File.exist?(lock)
|
230
|
+
lockfile ||= Pod::Lockfile.from_file(Pathname.new(lock))
|
231
|
+
return lockfile
|
232
|
+
end
|
233
|
+
|
234
|
+
def generate_localStable
|
235
|
+
lockfile = podfile_lock
|
236
|
+
local_specs = {}
|
237
|
+
# step.1 获取分支指向信息
|
238
|
+
dependencies = lockfile.dependencies
|
239
|
+
dependencies.each do | dependency |
|
240
|
+
if dependency.external_source.is_a? Hash
|
241
|
+
name = dependency.name
|
242
|
+
external_source = dependency.external_source
|
243
|
+
podCoreName = subspec_podname(name)
|
244
|
+
# checkout_options = lockfile.checkout_options_for_pod_named(podCoreName)
|
245
|
+
# if checkout_options.is_a? Hash
|
246
|
+
# commit = checkout_options[:commit]
|
247
|
+
# external_source[:commit] = commit
|
248
|
+
# puts "name:#{podCoreName} checkout_options:#{checkout_options} commit:#{commit}"
|
249
|
+
# end
|
250
|
+
if podCoreName != name
|
251
|
+
# local_specs.delete(podCoreName)
|
252
|
+
local_specs[podCoreName] = external_source
|
253
|
+
if (!has_include_core_subspec(name)) # 过滤core数据
|
254
|
+
local_specs[name] = external_source
|
255
|
+
Pod::UI.puts "[分支] #{name} => (#{external_source})"
|
256
|
+
end
|
257
|
+
else
|
258
|
+
local_specs[name] = external_source
|
259
|
+
Pod::UI.puts "[分支] #{name} => (#{external_source})"
|
260
|
+
end
|
261
|
+
end
|
262
|
+
end
|
263
|
+
# step.2 获取pods标签信息,如果存在分支优先使用分支信息
|
264
|
+
lockfile.pod_names.each do |pod_name|
|
265
|
+
version = lockfile.version(pod_name)
|
266
|
+
podCoreName = subspec_podname(pod_name)
|
267
|
+
if local_specs.has_key?(podCoreName)
|
268
|
+
if podCoreName != pod_name
|
269
|
+
if (!has_include_core_subspec(pod_name)) # 过滤core数据
|
270
|
+
# Pod::UI.puts "step.2 #{pod_name} => (#{local_specs[podCoreName]})"
|
271
|
+
local_specs[pod_name] = local_specs[podCoreName]
|
272
|
+
end
|
273
|
+
end
|
274
|
+
else
|
275
|
+
if (!has_include_core_subspec(pod_name)) # 过滤core数据
|
276
|
+
ver = version.to_s
|
277
|
+
local_specs[pod_name] = ver
|
278
|
+
Pod::UI.puts "[标签] #{pod_name} => (#{ver})"
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
282
|
+
# Pod::UI.puts "yml配置数据:#{local_specs}"
|
283
|
+
if local_specs.length > 0
|
284
|
+
update_localstable_datas(local_specs)
|
285
|
+
Pod::UI.puts "Generating yml配置文件=> #{local_stable_yaml} 更新成功".green
|
286
|
+
end
|
287
|
+
end
|
288
|
+
# pod库是否包含core subspec
|
289
|
+
def has_include_core_subspec(pod_name)
|
290
|
+
if has_include_subspec(pod_name)
|
291
|
+
subPodName = pod_name.include?('/') ? pod_name.split('/').last.strip : pod_name
|
292
|
+
if (subPodName == "Core") || (subPodName == "Main") # 过滤core数据
|
293
|
+
return true
|
294
|
+
end
|
295
|
+
end
|
296
|
+
return false
|
297
|
+
end
|
298
|
+
# pod库是否包含subspec
|
299
|
+
def has_include_subspec(pod_name)
|
300
|
+
podCoreName = subspec_podname(pod_name)
|
301
|
+
if podCoreName != pod_name
|
302
|
+
return true
|
303
|
+
end
|
304
|
+
return false
|
305
|
+
end
|
306
|
+
# subspec pod库名称
|
307
|
+
def subspec_podname(pod_name)
|
308
|
+
return pod_name.include?('/') ? pod_name.split('/').first.strip : pod_name
|
309
|
+
end
|
310
|
+
# 是否pod subspec库
|
311
|
+
def has_pod_subspec(podName, podCoreName)
|
312
|
+
return (has_include_subspec(podName) && podName.include?("#{podCoreName}/"))
|
313
|
+
end
|
314
|
+
|
315
|
+
# 更新单个pod组件
|
316
|
+
def update_podmodules(pod_lists)
|
317
|
+
local_stable_data = fetch_local_stable_datas # 本地stable配置
|
318
|
+
need_update_pod_lists = podCoreNames_from_podmodules(pod_lists)
|
319
|
+
is_resave_stable_data = false
|
320
|
+
need_update_pod_lists.each do |podCoreName|
|
321
|
+
local_stable_data.keys.each do |podName|
|
322
|
+
if (podName == podCoreName) || has_pod_subspec(podName, podCoreName)
|
323
|
+
pod = local_stable_data[podName]
|
324
|
+
if pod.is_a?(String)
|
325
|
+
version = pod.lstrip # 去除首字母空格
|
326
|
+
initial_str = version[0..0] # 第一个字母
|
327
|
+
# 项目配置固定版本,以本项目为主
|
328
|
+
is_fixed_version = initial_str.include?('=') ? true : false # 固定版本 pod 'A','= x.x.x'
|
329
|
+
is_lessthan_version = version.include?('<') ? true : false # 限制《最高》组件版本 pod 'A','< x.x.x' 或者 pod 'A','<= x.x.x'
|
330
|
+
is_greaterthan_version = version.include?('>') ? true : false # 限制《最低》组件版本 pod 'A','> x.x.x' 或者 pod 'A','>= x.x.x'
|
331
|
+
is_fuzzy_version = version.include?('~>') ? true : false # 固定版本 pod 'A','~> x.x.x'
|
332
|
+
is_fuzzy_versionV2 = (!is_fixed_version && !is_lessthan_version && !is_greaterthan_version && !is_fuzzy_version) ? true : false # 固定版本 pod 'A','x.x.x'
|
333
|
+
if (is_fuzzy_versionV2 == true)
|
334
|
+
local_stable_data[podName] = ">= #{version}"
|
335
|
+
is_resave_stable_data = true
|
336
|
+
end
|
337
|
+
end
|
338
|
+
end
|
339
|
+
end
|
340
|
+
end
|
341
|
+
if is_resave_stable_data == true
|
342
|
+
puts "[PodAssistant] 更新本地stable数据".yellow
|
343
|
+
update_localstable_datas(local_stable_data)
|
344
|
+
end
|
345
|
+
end
|
346
|
+
# 更新local stable组件
|
347
|
+
def update_local_stable_from_podmodules(pod_lists)
|
348
|
+
local_stable_data = fetch_local_stable_datas # 本地stable配置
|
349
|
+
need_update_pod_lists = podCoreNames_from_podmodules(pod_lists)
|
350
|
+
lockfile = podfile_lock
|
351
|
+
pod_names = lockfile.pod_names # lock标签数据
|
352
|
+
is_resave_stable_data = false
|
353
|
+
need_update_pod_lists.each do |podCoreName|
|
354
|
+
local_stable_data.keys.each do |podName|
|
355
|
+
if (podName == podCoreName) || has_pod_subspec(podName, podCoreName)
|
356
|
+
pod = local_stable_data[podName]
|
357
|
+
if pod.is_a?(String)
|
358
|
+
version = pod.lstrip # 去除首字母空格
|
359
|
+
initial_str = version[0..0] # 第一个字母
|
360
|
+
is_greaterthan_version = version.include?('>') ? true : false # 限制《最低》组件版本 pod 'A','> x.x.x' 或者 pod 'A','>= x.x.x'
|
361
|
+
if (is_greaterthan_version == true)
|
362
|
+
version = lockfile.version(podCoreName).to_s
|
363
|
+
if !version.empty?
|
364
|
+
local_stable_data[podName] = version
|
365
|
+
is_resave_stable_data = true
|
366
|
+
puts "update pod #{podName} (#{version})".green
|
367
|
+
end
|
368
|
+
end
|
369
|
+
end
|
370
|
+
end
|
371
|
+
end
|
372
|
+
end
|
373
|
+
if is_resave_stable_data == true
|
374
|
+
puts "[PodAssistant] 更新本地stable数据".yellow
|
375
|
+
update_localstable_datas(local_stable_data)
|
376
|
+
end
|
377
|
+
end
|
378
|
+
private def podCoreNames_from_podmodules(pod_lists)
|
379
|
+
need_update_pod_lists = []
|
380
|
+
pod_lists.each do |podName|
|
381
|
+
podCoreName = subspec_podname(podName)
|
382
|
+
if !need_update_pod_lists.include?(podCoreName)
|
383
|
+
need_update_pod_lists.push(podCoreName)
|
384
|
+
end
|
385
|
+
end
|
386
|
+
return need_update_pod_lists
|
387
|
+
end
|
388
|
+
end
|
389
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'cocoapods-bb-PodAssistant/helpers'
|
2
|
+
|
3
|
+
# 公共spec配置库
|
4
|
+
# 业务线公共spec配置库
|
5
|
+
# 本地spec配置库 = 公共spec+业务线spec合并数据
|
6
|
+
# 数据格式 json {key,val}
|
7
|
+
module BB
|
8
|
+
class StableSpecs
|
9
|
+
def readData(yml_path)
|
10
|
+
return YamlFilesHelper.read_stable_lock_yaml(yml_path)
|
11
|
+
end
|
12
|
+
def writeData(yml_path, data)
|
13
|
+
YamlFilesHelper.save_stable_lock_yaml(yml_path, data)
|
14
|
+
end
|
15
|
+
# podfile 更新配置文件使用(通用)
|
16
|
+
def update_stable_lock(yml_path, pod_targets)
|
17
|
+
YamlFilesHelper.save_stable_podlock(yml_path, pod_targets)
|
18
|
+
puts "[成功] 更新ymal配置文件#{yml_path}".green
|
19
|
+
end
|
20
|
+
# 更新podfile配置文件使用(项目)
|
21
|
+
def update_local_stable_lock(yml_path, pod_targets)
|
22
|
+
YamlFilesHelper.save_local_stable_podlock(yml_path, pod_targets)
|
23
|
+
puts "[成功] 更新ymal配置文件#{yml_path}".green
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|