cocoapods-soul-component-plugin 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17ca100ec2abac1731f0880fbc3eab77c3bcae0ebf0a85573f8d165dfdd928b4
4
- data.tar.gz: 3e63e527cf6bd1b66bdf4c86cbe2b62dd81b6c9ce5e21e3e8c5a892511885309
3
+ metadata.gz: 4fe112b7a0c2576a90976d2ad3893dff3ebf8043b1426f61273282ae1d0344b8
4
+ data.tar.gz: 78f2bc8841a4005661a077c460dc4714a548a37cc00f1e57f438dc46cf227a61
5
5
  SHA512:
6
- metadata.gz: 9df3393644ecf49435921ba68cd96128c888cb83065c479f1473bb1d5d6cabc2e6793dcefe75fed6c7394544975730e4db8bd62082f05978a27b50173644a3a0
7
- data.tar.gz: 58455b25be1648957bf8561cba12477c5b41878c856ea71e0531613f4c261afb7681dcac45f37b613d5c91c187d1a39157b36389ad91d9df1ebe74861f55b33c
6
+ metadata.gz: fc7abff4f40879636d4e611dd7a61992cdd7a3acbb51d14d29659934eff48c1b8ecb073efe29fc5c567ab8724941b7e2b66b131ab5b7900a9b4a6658df575f73
7
+ data.tar.gz: b25d96af0cb3455fbb40c6f0ad3f2c4f934f0ea23bc60d9449748b492b3211ab64c36960405bbc38f31b577b6c20bc138bba392ba75177bd95c3db1d61549ef2
@@ -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
@@ -85,7 +111,7 @@ module CocoapodsSoulComponentPlugin
85
111
  group = project.main_group
86
112
  group.set_source_tree('SOURCE_ROOT')
87
113
  # 向group中添加 文件引用
88
- file_ref = group.new_reference(self.component_file_path)
114
+ file_ref = group.new_reference(component_file_path)
89
115
  # podfile_local排序
90
116
  podfile_local_group = group.children.last
91
117
  group.children.pop
@@ -94,28 +120,36 @@ module CocoapodsSoulComponentPlugin
94
120
  end
95
121
 
96
122
  def self.pre_run
97
- Pod::UI.puts "当前版本:#{CocoapodsSoulComponentPlugin::VERSION}".green
98
- json = File.read(self.component_file_path)
123
+ json = File.read(component_file_path)
99
124
  obj = JSON.parse(json)
100
125
  dependencies = obj['dependencies']
101
126
 
102
127
  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']))
128
+ component = Soul_Component.new(each[0], each[1]['local'], each[1]['submodule'], each[1]['version'], each[1]['git'],
129
+ each[1]['branch'], each[1]['path'], each[1]['commit'])
130
+ if @@use_source
131
+ component.local = true
132
+ if Pod::Downloader::Git.check_if_has_auth_clone(component.git) == false
133
+ component.local = false
134
+ Pod::UI.puts "本地依赖 #{component.name} 切换失败,使用 binary 。参数:#{component.to_hash}".red
135
+ end
136
+ end
137
+ @@components.push(component)
104
138
  end
105
139
 
106
- $components.each do |each|
107
- if each.path == nil
140
+ @@components.each do |each|
141
+ if each.path.nil?
108
142
  if each.submodule == false
109
143
  if each.local == true
110
144
  local_path = each.name
111
145
 
112
- if each.commit != nil
146
+ if !each.commit.nil?
113
147
  local_path += '-'
114
148
  local_path += each.commit.to_s
115
- elsif each.branch != nil
149
+ elsif !each.branch.nil?
116
150
  local_path += '-'
117
151
  local_path += each.branch.to_s
118
- elsif each.version != nil
152
+ elsif !each.version.nil?
119
153
  local_path += '-'
120
154
  local_path += each.version.to_s
121
155
  end
@@ -123,7 +157,7 @@ module CocoapodsSoulComponentPlugin
123
157
  each.path = target_path
124
158
 
125
159
  if File.exist?(target_path) == false
126
- options = { git: each.git, commit: each.commit, tag: each.version, branch:each.branch }
160
+ options = { git: each.git, commit: each.commit, tag: each.version, branch: each.branch }
127
161
  options = Pod::Downloader.preprocess_options(options)
128
162
  downloader = Pod::Downloader.for_target(target_path, options)
129
163
  Pod::UI.puts "本地依赖 #{each.name} 不存在,即将进行下载 。参数:#{options}".green
@@ -132,10 +166,8 @@ module CocoapodsSoulComponentPlugin
132
166
  Pod::UI.puts "本地依赖 #{each.name} 已存在,不进行变更,如需更新请删除重新 install。位置:#{target_path}".yellow
133
167
  end
134
168
  end
135
- else
136
- if each.local == true
137
- each.path = "SOPods/#{each.name}"
138
- end
169
+ elsif each.local == true
170
+ each.path = "SOPods/#{each.name}"
139
171
  end
140
172
  end
141
173
  end
@@ -146,8 +178,21 @@ end
146
178
  module Pod
147
179
  class Command
148
180
  class Install < Command
181
+ def self.options
182
+ [
183
+ ['--source', 'Use source']
184
+ ].concat(super)
185
+ end
186
+
187
+ def initialize(argv)
188
+ CocoapodsSoulComponentPlugin.use_source = argv.flag?('source')
189
+ super
190
+ end
191
+
149
192
  alias old_run run
193
+
150
194
  def run
195
+ Pod::UI.puts "当前版本:#{CocoapodsSoulComponentPlugin::VERSION}".green
151
196
  CocoapodsSoulComponentPlugin.pre_run if CocoapodsSoulComponentPlugin.use_components
152
197
  old_run
153
198
  CocoapodsSoulComponentPlugin.post_run if CocoapodsSoulComponentPlugin.use_components
@@ -159,7 +204,7 @@ module Pod
159
204
  alias old_initialize initialize
160
205
 
161
206
  def initialize(name = nil, *requirements)
162
- if requirements == nil
207
+ if requirements.nil?
163
208
  old_initialize(name)
164
209
  return
165
210
  end
@@ -168,14 +213,14 @@ module Pod
168
213
  # puts name, requirements
169
214
  # end
170
215
 
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
216
+ CocoapodsSoulComponentPlugin.components.each do |each|
217
+ next unless each.name == name
218
+
219
+ requirements = if each.local == true
220
+ [{ name: each.name, path: each.path }]
221
+ else
222
+ [each.version]
223
+ end
179
224
  end
180
225
 
181
226
  old_initialize(name, *requirements)
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module CocoapodsSoulComponentPlugin
3
- VERSION = '0.0.10'
3
+ VERSION = '0.0.11'
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.10
4
+ version: 0.0.11
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-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler