cocoapods-soul-component-plugin 0.0.8 → 0.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2973ba2951120c6f1fcc995d160ba9021ba167826dc8c3e3cc9636bb4f2aa993
4
- data.tar.gz: 78ec8ef8b8d1905530ac31c7fe498f1ecfe1948979c420d7dfb5b6ac559b96fc
3
+ metadata.gz: 80e8752bcf3e29fe0c8375f18b08be5f0d03ff7c5eb9e4ee673baf53704ff1b0
4
+ data.tar.gz: 2e052340dc280c917ad61a14af622c2cedbc25b5802fc97290052a07dc6bcf99
5
5
  SHA512:
6
- metadata.gz: 0e884aec7137fb65168db58fee703f8d8b34edb35945e12d982d1ec405201ea67f7f857ea3d40bd8283684437c039e7b95eda6ab192ae5498c89b8f88420239a
7
- data.tar.gz: e2174829dc3590418da0daab2c2f04979da30ca2afb51f17a423cbd47221bfaeedbb13450944678ced82d414a7e02c6a07054c767b3af242d926fbaaeb0c4e61
6
+ metadata.gz: 54077c1784559216a6403be52c660516e40c4620348dfbdaecfa3265efc7430f12d0a821b5b5606efa8519c63ceb663798695cdf7a992594f128a061459edcdf
7
+ data.tar.gz: d00ace53cfd644d4a260cbfe6029d3948da91d06cc3b7f06d8c0367f51f66a5f4b94dda99e9e79a7c0d57dc18ba28470158b59a8fdbaadc18f8922e262841a1f
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'cocoapods'
2
4
  require 'fileutils'
3
5
  require 'json'
@@ -10,9 +12,15 @@ module Pod
10
12
  module Downloader
11
13
  class Git < Base
12
14
  def download_deep
13
- clone(false,false )
15
+ clone(false, false)
14
16
  checkout_commit if options[:commit]
15
17
  end
18
+
19
+ def self.check_if_has_auth_clone(url)
20
+ cmd = "git ls-remote #{url} --exit-code"
21
+ stdout, stderr, status = Open3.capture3(cmd)
22
+ status.success?
23
+ end
16
24
  end
17
25
  end
18
26
 
@@ -24,7 +32,6 @@ module Pod
24
32
  self.description = <<-DESC
25
33
  Install components through devops/components.json
26
34
  DESC
27
- self.arguments = []
28
35
 
29
36
  def run
30
37
  # do nothing
@@ -35,7 +42,20 @@ module Pod
35
42
  end
36
43
 
37
44
  module CocoapodsSoulComponentPlugin
38
- $components = []
45
+ @@components = []
46
+ @@use_source = false
47
+
48
+ def self.use_source=(t_use_source)
49
+ @@use_source = t_use_source
50
+ end
51
+
52
+ def self.use_source
53
+ @@use_source
54
+ end
55
+
56
+ def self.components
57
+ @@components
58
+ end
39
59
 
40
60
  class Soul_Component
41
61
  attr_accessor :name, :local, :submodule, :version, :git, :branch, :path, :commit
@@ -50,6 +70,12 @@ module CocoapodsSoulComponentPlugin
50
70
  @path = path
51
71
  @commit = commit
52
72
  end
73
+
74
+ def to_hash
75
+ instance_variables.map do |var|
76
+ [var[1..-1].to_sym, instance_variable_get(var)]
77
+ end.to_h
78
+ end
53
79
  end
54
80
 
55
81
  def self.use_components
@@ -68,6 +94,10 @@ module CocoapodsSoulComponentPlugin
68
94
  "#{root_path}/devops/component.json"
69
95
  end
70
96
 
97
+ def self.component_user_file_path
98
+ "#{root_path}/devops/component_user.json"
99
+ end
100
+
71
101
  Pod::HooksManager.register('cocoapods-soul-component-plugin', :pre_install) do |_context|
72
102
  Pod::UI.puts '插件 pre_install'
73
103
  end
@@ -85,7 +115,7 @@ module CocoapodsSoulComponentPlugin
85
115
  group = project.main_group
86
116
  group.set_source_tree('SOURCE_ROOT')
87
117
  # 向group中添加 文件引用
88
- file_ref = group.new_reference(self.component_file_path)
118
+ file_ref = group.new_reference(component_file_path)
89
119
  # podfile_local排序
90
120
  podfile_local_group = group.children.last
91
121
  group.children.pop
@@ -93,49 +123,93 @@ module CocoapodsSoulComponentPlugin
93
123
  project.save
94
124
  end
95
125
 
96
- def self.pre_run
97
- Pod::UI.puts "当前版本:#{CocoapodsSoulComponentPlugin::VERSION}".green
98
- json = File.read(self.component_file_path)
126
+ def self.generateComponents
127
+ components = []
128
+ json = File.read(component_file_path)
99
129
  obj = JSON.parse(json)
100
- dependencies = obj['dependencies']
101
130
 
131
+ dependencies_user = nil
132
+ if File.exist?(component_user_file_path)
133
+ json_user = File.read(component_user_file_path)
134
+ obj_user = JSON.parse(json_user)
135
+ dependencies_user = obj_user['dependencies']
136
+ end
137
+
138
+ dependencies = obj['dependencies']
102
139
  dependencies.each do |each|
103
- $components.push(Soul_Component.new(each[0], each[1]['local'], each[1]['submodule'], each[1]['version'], each[1]['git'], each[1]['branch'], each[1]['path'],each[1]['commit']))
140
+ component = Soul_Component.new(each[0], each[1]['local'], each[1]['submodule'], each[1]['version'], each[1]['git'],
141
+ each[1]['branch'], each[1]['path'], each[1]['commit'])
142
+ if dependencies_user && dependencies_user[component.name]
143
+ component.local = dependencies_user[component.name]['local']
144
+ component.submodule = dependencies_user[component.name]['submodule'] if dependencies_user[component.name]['submodule']
145
+ component.version = dependencies_user[component.name]['version']
146
+ component.git = dependencies_user[component.name]['git'] if dependencies_user[component.name]['git']
147
+ component.branch = dependencies_user[component.name]['branch']
148
+ component.path = dependencies_user[component.name]['path']
149
+ component.commit = dependencies_user[component.name]['commit']
150
+ Pod::UI.puts "使用用户配置覆盖。参数:#{component.to_hash}".green
151
+ end
152
+ if @@use_source
153
+ component.local = true
154
+ if Pod::Downloader::Git.check_if_has_auth_clone(component.git) == false
155
+ component.local = false
156
+ Pod::UI.puts "本地依赖 #{component.name} 切换失败,使用 binary 。参数:#{component.to_hash}".red
157
+ end
158
+ end
159
+ components.push(component)
160
+ end
161
+ components
162
+ end
163
+
164
+ def self.checkValidComponents
165
+ isValid = true
166
+ @@components.each do |each|
167
+ if each.name.nil? || each.git.nil? || each.local.nil? || each.submodule.nil!
168
+ Pod::UI.puts "缺少必要参数,name/git/local/submodule为必要参数:#{each.to_hash}".red
169
+ isValid = false
170
+ end
104
171
  end
172
+ isValid
173
+ end
105
174
 
106
- $components.each do |each|
107
- if each.path == nil
175
+ def self.pre_run
176
+ @@components = generateComponents
177
+ if checkValidComponents == false
178
+ Pod::UI.puts '参数异常,退出'.red
179
+ exit(1)
180
+ end
181
+
182
+ @@components.each do |each|
183
+ if each.path.nil?
108
184
  if each.submodule == false
109
185
  if each.local == true
110
186
  local_path = each.name
111
187
 
112
- if each.commit != nil
188
+ if !each.commit.nil?
113
189
  local_path += '-'
114
190
  local_path += each.commit.to_s
115
- elsif each.branch != nil
191
+ elsif !each.branch.nil?
116
192
  local_path += '-'
117
193
  local_path += each.branch.to_s
118
- elsif each.version != nil
194
+ elsif !each.version.nil?
119
195
  local_path += '-'
120
196
  local_path += each.version.to_s
121
197
  end
122
- target_path = "#{root_path}/LocalPods/#{local_path}1"
198
+ target_path = "#{root_path}/LocalPods/#{local_path}"
123
199
  each.path = target_path
124
200
 
125
201
  if File.exist?(target_path) == false
126
- options = { git: each.git, commit: each.commit, tag: each.version, branch:each.branch }
202
+ options = { git: each.git, commit: each.commit, tag: each.version, branch: each.branch }
127
203
  options = Pod::Downloader.preprocess_options(options)
128
204
  downloader = Pod::Downloader.for_target(target_path, options)
205
+ Pod::UI.puts "本地依赖 #{each.name} 不存在,即将进行下载 。参数:#{options}".green
129
206
  downloader.download_deep
130
- Pod::UI.puts "本地 #{each.name} 不存在,进行 clone 。参数:#{options}".green
131
207
  else
132
- Pod::UI.puts "本地 #{each.name} 已存在,不进行变更,如需更新请删除。位置:#{target_path}".yellow
208
+ Pod::UI.puts "本地依赖 #{each.name} 已存在,不进行变更,如需更新请删除重新 install。位置:#{target_path}".yellow
133
209
  end
134
210
  end
135
- else
136
- if each.local == true
137
- each.path = "SOPods/#{each.name}"
138
- end
211
+ elsif each.local == true
212
+ each.path = "SOPods/#{each.name}"
139
213
  end
140
214
  end
141
215
  end
@@ -146,8 +220,21 @@ end
146
220
  module Pod
147
221
  class Command
148
222
  class Install < Command
223
+ def self.options
224
+ [
225
+ ['--source', 'Use source']
226
+ ].concat(super)
227
+ end
228
+
229
+ def initialize(argv)
230
+ CocoapodsSoulComponentPlugin.use_source = argv.flag?('source')
231
+ super
232
+ end
233
+
149
234
  alias old_run run
235
+
150
236
  def run
237
+ Pod::UI.puts "当前版本:#{CocoapodsSoulComponentPlugin::VERSION}".green
151
238
  CocoapodsSoulComponentPlugin.pre_run if CocoapodsSoulComponentPlugin.use_components
152
239
  old_run
153
240
  CocoapodsSoulComponentPlugin.post_run if CocoapodsSoulComponentPlugin.use_components
@@ -159,7 +246,7 @@ module Pod
159
246
  alias old_initialize initialize
160
247
 
161
248
  def initialize(name = nil, *requirements)
162
- if requirements == nil
249
+ if requirements.nil?
163
250
  old_initialize(name)
164
251
  return
165
252
  end
@@ -168,14 +255,14 @@ module Pod
168
255
  # puts name, requirements
169
256
  # end
170
257
 
171
- $components.each do |each|
172
- if each.name == name
173
- if each.local == true
174
- requirements = [{ :name => each.name, :path => each.path }]
175
- else
176
- requirements = [each.version]
177
- end
178
- end
258
+ CocoapodsSoulComponentPlugin.components.each do |each|
259
+ next unless each.name == name
260
+
261
+ requirements = if each.local == true
262
+ [{ name: each.name, path: each.path }]
263
+ else
264
+ [each.version]
265
+ end
179
266
  end
180
267
 
181
268
  old_initialize(name, *requirements)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module CocoapodsSoulComponentPlugin
3
- VERSION = '0.0.8'
3
+ VERSION = '0.0.12'
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-soul-component-plugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - fang
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-18 00:00:00.000000000 Z
11
+ date: 2021-12-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler