lg_pod_plugin 1.0.3 → 1.0.4

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.
data/lib/lg_pod_plugin.rb CHANGED
@@ -1,75 +1,23 @@
1
1
  require 'git'
2
2
  require 'sqlite3'
3
+ require 'cocoapods-downloader'
4
+ require 'cocoapods-core/podfile/target_definition'
5
+
3
6
  require "lg_pod_plugin/version"
4
- require 'cocoapods/user_interface'
7
+ require_relative 'lg_pod_plugin/log'
8
+ require_relative 'lg_pod_plugin/install'
9
+ require_relative 'lg_pod_plugin/request'
5
10
  require_relative 'lg_pod_plugin/database'
6
11
  require_relative 'lg_pod_plugin/download'
7
12
  require_relative 'lg_pod_plugin/git_util'
8
- require_relative 'lg_pod_plugin/pod_spec'
9
- require_relative 'lg_pod_plugin/install'
10
- require 'cocoapods-core/podfile/target_definition'
11
13
 
12
14
  module LgPodPlugin
13
15
 
14
- class String
15
- # colorization
16
- def colorize(color_code)
17
- "\e[#{color_code}m#{self}\e[0m"
18
- end
19
-
20
- def red
21
- colorize(31)
22
- end
23
-
24
- def green
25
- colorize(32)
26
- end
27
-
28
- def yellow
29
- colorize(33)
30
- end
31
-
32
- def blue
33
- colorize(34)
34
- end
35
-
36
- def pink
37
- colorize(35)
38
- end
39
-
40
- def light_blue
41
- colorize(36)
42
- end
43
- end
44
-
45
16
  class Error < StandardError; end
46
17
 
47
- def self.log_red(msg)
48
- Pod::CoreUI.puts msg.red
49
- end
50
-
51
- def self.log_blue(msg)
52
- Pod::CoreUI.puts msg.blue
53
- end
54
-
55
- def self.log_green(msg)
56
- Pod::CoreUI.puts msg.green
57
- end
58
-
59
- def self.log_yellow(msg)
60
- Pod::CoreUI.puts msg.yellow
61
- end
62
-
63
- def self.log(msg)
64
- Pod::CoreUI.puts msg
65
- end
66
-
67
18
  public
68
19
  # 对 Profile 方法进行拓展
69
20
  def pod(name, *requirements)
70
21
  Installer.new(self, name, requirements)
71
22
  end
72
-
73
-
74
23
  end
75
-
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lg_pod_plugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - dongzb01
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-16 00:00:00.000000000 Z
11
+ date: 2022-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: claide
@@ -120,13 +120,15 @@ files:
120
120
  - lib/command/cache.rb
121
121
  - lib/command/command.rb
122
122
  - lib/lg_pod_plugin.rb
123
- - lib/lg_pod_plugin/cache.rb
124
123
  - lib/lg_pod_plugin/database.rb
125
124
  - lib/lg_pod_plugin/download.rb
126
125
  - lib/lg_pod_plugin/file_path.rb
127
126
  - lib/lg_pod_plugin/git_util.rb
128
127
  - lib/lg_pod_plugin/install.rb
129
- - lib/lg_pod_plugin/pod_spec.rb
128
+ - lib/lg_pod_plugin/l_cache.rb
129
+ - lib/lg_pod_plugin/log.rb
130
+ - lib/lg_pod_plugin/request.rb
131
+ - lib/lg_pod_plugin/string.rb
130
132
  - lib/lg_pod_plugin/version.rb
131
133
  homepage: https://gitee.com/fmdb_beantech_admin/lg_pod_plugin
132
134
  licenses:
@@ -1,226 +0,0 @@
1
- require 'git'
2
- require 'cocoapods/downloader'
3
- require 'cocoapods/downloader/cache'
4
- require 'cocoapods/downloader/response'
5
- require 'cocoapods/downloader/request'
6
-
7
- module LgPodPlugin
8
-
9
- class CachePodInfo
10
- # attr_accessor :sha
11
- # attr_accessor :tag
12
- # attr_accessor :name
13
- # attr_accessor :path
14
- # attr_accessor :branch
15
- # attr_accessor :timestamp
16
- REQUIRED_ATTRS ||= %i[sha tag name path branch timestamp].freeze
17
- attr_accessor(*REQUIRED_ATTRS)
18
- def initialize
19
- super
20
- end
21
-
22
- end
23
-
24
- class Cache
25
-
26
- def initialize
27
- super
28
- end
29
-
30
- #判断缓存是否存在且有效命中缓存
31
- def find_pod_cache(name ,git, branch, is_update)
32
- last_commit = nil
33
- if is_update
34
- last_commit = GitUtil.git_ls_remote_refs(git, branch)
35
- else
36
- local_pod_path = self.get_download_path(name, git, branch)
37
- if Dir.exist?(local_pod_path)
38
- local_git = Git.open(Pathname("#{local_pod_path}"))
39
- last_commit = local_git.log(1).to_s
40
- else
41
- last_commit = GitUtil.git_ls_remote_refs(git, branch)
42
- end
43
- end
44
- unless last_commit
45
- return [true , nil]
46
- end
47
- request = Cache.download_request(name, {:git => git, :commit => last_commit})
48
- destination = Cache.path_for_pod(request, {})
49
- cache_pod_spec = Cache.path_for_spec(request, {})
50
- if File.exist?(destination) && File.exist?(cache_pod_spec)
51
- [false , last_commit]
52
- else
53
- [true , last_commit]
54
- end
55
- end
56
-
57
- def clean_old_cache(name, git, commit)
58
- request = Cache.download_request(name, {:git => git, :commit => commit})
59
- destination = Cache.path_for_pod(request, {})
60
- cache_pod_spec = Cache.path_for_spec(request, {})
61
- if File.exist?(destination)
62
- FileUtils.rm_rf(destination)
63
- end
64
- if File.exist?(cache_pod_spec)
65
- FileUtils.rm_rf(cache_pod_spec)
66
- end
67
- end
68
-
69
- def self.root_path
70
- path = File.join(Dir.home, "Library/Caches/CocoaPods/Pods")
71
- Pathname(path)
72
- end
73
-
74
- def self.download_request(name, params)
75
- Pod::Downloader::Request.new(spec: nil, released: false, name: name, params: params)
76
- end
77
-
78
- def self.path_for_pod(request, slug_opts = {})
79
- root = self.root_path
80
- root + request.slug(**slug_opts)
81
- end
82
-
83
- def self.path_for_spec(request, slug_opts = {})
84
- root = self.root_path
85
- path = root + 'Specs' + request.slug(**slug_opts)
86
- Pathname.new(path.to_path + '.podspec.json')
87
- end
88
-
89
- def self.cached_spec(request)
90
- path = path_for_spec(request)
91
- path.file? && Specification.from_file(path)
92
- rescue JSON::ParserError
93
- nil
94
- end
95
-
96
- def self.get_local_spec(request, target)
97
- result = Pod::Downloader::Response.new
98
- result.location = target
99
- if request.released_pod?
100
- result.spec = request.spec
101
- local_specs = { request.name => request.spec }
102
- return [request, local_specs]
103
- else
104
- local_specs = {}
105
- podspecs = Pod::Sandbox::PodspecFinder.new(target).podspecs
106
- podspecs[request.name] = request.spec if request.spec
107
- podspecs.each do |name, spec|
108
- if request.name == name
109
- result.spec = spec
110
- local_specs[request.name] = spec
111
- end
112
- end
113
- end
114
-
115
- [result, local_specs]
116
- end
117
-
118
- def self.group_sub_specs_by_platform(spec)
119
- specs_by_platform = {}
120
- [spec, *spec.recursive_subspecs].each do |ss|
121
- ss.available_platforms.each do |platform|
122
- specs_by_platform[platform] ||= []
123
- specs_by_platform[platform] << ss
124
- end
125
- end
126
- specs_by_platform
127
- end
128
-
129
- def self.copy_and_clean(source, destination, spec)
130
- specs_by_platform = group_sub_specs_by_platform(spec)
131
- destination.parent.mkpath
132
- self.write_lock(destination) do
133
- FileUtils.rm_rf(destination)
134
- FileUtils.cp_r(source, destination)
135
- Pod::Installer::PodSourcePreparer.new(spec, destination).prepare!
136
- Pod::Sandbox::PodDirCleaner.new(destination, specs_by_platform).clean!
137
- end
138
- end
139
-
140
- def self.write_lock(location, &block)
141
- self.lock(location, File::LOCK_EX, &block)
142
- end
143
-
144
- def self.lock(location, lock_type)
145
- raise ArgumentError, 'no block given' unless block_given?
146
- lockfile = "#{location}.lock"
147
- f = nil
148
- loop do
149
- f.close if f
150
- f = File.open(lockfile, File::CREAT, 0o644)
151
- f.flock(lock_type)
152
- break if self.valid_lock?(f, lockfile)
153
- end
154
- begin
155
- yield location
156
- ensure
157
- if lock_type == File::LOCK_SH
158
- f.flock(File::LOCK_EX)
159
- File.delete(lockfile) if self.valid_lock?(f, lockfile)
160
- else
161
- File.delete(lockfile)
162
- end
163
- f.close
164
- end
165
- end
166
-
167
- def self.valid_lock?(file, filename)
168
- file.stat.ino == File.stat(filename).ino
169
- rescue Errno::ENOENT
170
- false
171
- end
172
-
173
- def self.write_spec(spec, path)
174
- path.dirname.mkpath
175
- Pod::Downloader::Cache.write_lock(path) do
176
- path.open('w') { |f| f.write spec.to_pretty_json }
177
- end
178
- end
179
-
180
- # 拷贝 pod 缓存文件到 sandbox
181
- def self.cache_pod(name, target, is_update, options = {})
182
- request = Cache.download_request(name, options)
183
- result, pods_pecs = get_local_spec(request, target)
184
- result.location = nil
185
- pods_pecs.each do |s_name, s_spec|
186
- destination = path_for_pod(request, {})
187
- if !File.exist?(destination) || is_update
188
- LgPodPlugin.log_green "Copying #{name} from `#{target}` to `#{destination}` "
189
- copy_and_clean(target, destination, s_spec)
190
- end
191
- cache_pod_spec = path_for_spec(request, {})
192
- if !File.exist?(cache_pod_spec) || is_update
193
- write_spec(s_spec, cache_pod_spec)
194
- end
195
- if request.name == s_name
196
- result.location = destination
197
- end
198
-
199
- end
200
-
201
- end
202
-
203
- # 根据下载参数生产缓存的路径
204
- def get_download_path(name, git, branch)
205
- request = Cache.download_request(name, {:git => git, :branch => branch})
206
- self.slug(name, request.params, nil )
207
- end
208
-
209
- # 根据下载参数生产缓存目录
210
- def slug(name, params, spec)
211
- path = FileManager.download_pod_path(name).to_path
212
- checksum = spec&.checksum && '-' << spec.checksum[0, 5]
213
- opts = params.to_a.sort_by(&:first).map { |k, v| "#{k}=#{v}" }.join('-')
214
- digest = Digest::MD5.hexdigest(opts)
215
- if digest
216
- path += "/#{digest}"
217
- end
218
- if checksum
219
- path += "/#{checksum}"
220
- end
221
- path
222
- end
223
-
224
- end
225
-
226
- end
@@ -1,66 +0,0 @@
1
- module LgPodPlugin
2
-
3
- class Spec
4
-
5
- REQUIRED_ATTRS ||= %i[install name git commit tag path branch].freeze
6
- attr_accessor(*REQUIRED_ATTRS)
7
- OPTIONAL_ATTRS ||= %i[depth configurations modular_headers subspecs inhibit_warnings testspecs].freeze
8
- attr_accessor(*OPTIONAL_ATTRS)
9
- def initialize(defined_in_file = nil, &block)
10
- if block
11
- instance_eval(&block)
12
- end
13
- end
14
-
15
- def inspect
16
- "#{self.class}: #{object_id} name: #{name}, tag: #{tag}"
17
- end
18
-
19
- def self.form_file(file_path)
20
- contents = File.open(file_path, 'r:utf-8', &:read)
21
- if contents.respond_to?(:encoding) && contents.encoding.name != 'UTF-8'
22
- contents.encoding("UTF-8")
23
- end
24
- # 2 讲xx.rb转成 Spec 对象
25
- l_spec = eval(contents, nil , file_path.to_s)
26
- if l_spec.install == nil
27
- l_spec.install = true
28
- end
29
- l_spec
30
- end
31
-
32
- # pod 必传参数
33
- def pod_requirements
34
- h = nil
35
- unless install != false
36
- return h
37
- end
38
- # 集成组件时, 【必选】参数, 必须互斥
39
- if path
40
- h = { path: path }
41
- elsif git && commit
42
- h = { git: git, commit: commit }
43
- elsif git && tag
44
- h = { git: git, tag: tag }
45
- elsif git && branch
46
- # branch is not supported for binary
47
- h = { git: git, branch: branch, depth: depth }
48
- else
49
- puts("VirusFile is not valid, `#{name}` will not be required\n")
50
- end
51
-
52
- pod_optional(h)
53
-
54
- end
55
-
56
- def pod_optional(h)
57
- OPTIONAL_ATTRS.each do |att|
58
- value = send(att)
59
- h[att] = value unless value.nil?
60
- end
61
- h
62
- end
63
-
64
- end
65
-
66
- end