lg_pod_plugin 1.0.1 → 1.0.2
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 +4 -4
- data/lib/lg_pod_plugin/cache.rb +1 -1
- data/lib/lg_pod_plugin/download.rb +7 -8
- data/lib/lg_pod_plugin/git_util.rb +7 -5
- data/lib/lg_pod_plugin/install.rb +80 -29
- data/lib/lg_pod_plugin/version.rb +1 -1
- data/lib/lg_pod_plugin.rb +50 -7
- metadata +2 -4
- data/bin/lg +0 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7a39307dd5e4f73faefa55775b51e880f9f0fda326cc618c62b957ddcba669e
|
4
|
+
data.tar.gz: 46777e3af13f74c44086743bb48352373539806a22aafc758eb104dde3f4864c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a945450a624206b131df0b963fbd8616b4df179112b54f41625ed90a46b5480823d74b80c0dc75c227f56de3d74fe225cb44243396d11ff7d864399adcbd89a0
|
7
|
+
data.tar.gz: c72bbba5713477f4f094387b650298768e94ec3de1a831daead4d2eb588654cb58190d3cbd474e983bc7b02c2b3ce144c032f27722ea75802020a513488490a8
|
data/lib/lg_pod_plugin/cache.rb
CHANGED
@@ -149,7 +149,7 @@ class Cache
|
|
149
149
|
pods_pecs.each do |s_name, s_spec|
|
150
150
|
destination = path_for_pod(request, {})
|
151
151
|
if !File.exist?(destination) || is_update
|
152
|
-
|
152
|
+
LgPodPlugin.log_green "Copying #{name} from `#{target}` to `#{destination}` "
|
153
153
|
copy_and_clean(target, destination, s_spec)
|
154
154
|
end
|
155
155
|
cache_pod_spec = path_for_spec(request, {})
|
@@ -3,7 +3,7 @@ require_relative 'cache.rb'
|
|
3
3
|
require_relative 'database.rb'
|
4
4
|
require_relative 'file_path.rb'
|
5
5
|
|
6
|
-
module
|
6
|
+
module LgPodPlugin
|
7
7
|
|
8
8
|
class Downloader
|
9
9
|
attr_accessor :git_util
|
@@ -57,12 +57,11 @@ module LgPodPlugin
|
|
57
57
|
git_url = options[:git]
|
58
58
|
# commit = options[:commit]
|
59
59
|
branch = options[:branch]
|
60
|
-
|
61
|
-
|
60
|
+
LgPodPlugin.log_green "Using `#{name}` (#{branch})"
|
62
61
|
# 发现本地有缓存, 不需要更新缓存
|
63
62
|
need_download, new_commit = self.cache.find_pod_cache(name, git_url, branch, is_update)
|
64
63
|
unless need_download
|
65
|
-
|
64
|
+
LgPodPlugin.log_green "find the cache of `#{name}`, you can use it now."
|
66
65
|
return
|
67
66
|
end
|
68
67
|
|
@@ -91,7 +90,7 @@ module LgPodPlugin
|
|
91
90
|
if new_commit != current_commit && is_update
|
92
91
|
#删除旧的pod 缓存
|
93
92
|
self.cache.clean_old_cache(name, git_url, current_commit)
|
94
|
-
|
93
|
+
LgPodPlugin.log_green "git pull #{name} origin/#{current_branch}"
|
95
94
|
self.git_util.should_pull(git, current_branch, new_commit)
|
96
95
|
current_commit = new_commit
|
97
96
|
end
|
@@ -104,15 +103,15 @@ module LgPodPlugin
|
|
104
103
|
else
|
105
104
|
branch_exist = git.branches.local.find {|e| e.to_s == branch}
|
106
105
|
if branch_exist
|
107
|
-
|
106
|
+
LgPodPlugin.log_green "git switch #{name} #{git_url} -b #{branch}"
|
108
107
|
self.git_util.git_switch(branch)
|
109
108
|
else
|
110
|
-
|
109
|
+
LgPodPlugin.log_green "git checkout #{name} #{git_url} -b #{branch}"
|
111
110
|
self.git_util.git_checkout(branch)
|
112
111
|
end
|
113
112
|
current_commit = git.log(1).to_s
|
114
113
|
if current_commit != new_commit
|
115
|
-
|
114
|
+
LgPodPlugin.log_green "git pull #{name} #{git_url} -b #{branch}"
|
116
115
|
self.git_util.should_pull(git, current_branch, new_commit)
|
117
116
|
current_commit = new_commit
|
118
117
|
end
|
@@ -27,9 +27,8 @@ module LgPodPlugin
|
|
27
27
|
def git_clone(path)
|
28
28
|
if self.branch
|
29
29
|
temp_git_path = path.join("l-temp-pod")
|
30
|
-
|
30
|
+
LgPodPlugin.log_blue "git clone --template= --single-branch --depth 1 --branch #{self.branch} #{self.git}"
|
31
31
|
system("git clone --template= --single-branch --depth 1 --branch #{self.branch} #{self.git} #{temp_git_path}")
|
32
|
-
puts "\n"
|
33
32
|
temp_git_path
|
34
33
|
else
|
35
34
|
nil
|
@@ -76,8 +75,8 @@ module LgPodPlugin
|
|
76
75
|
end
|
77
76
|
|
78
77
|
# 本地pod库git操作
|
79
|
-
def git_local_pod_check
|
80
|
-
FileUtils.chdir(
|
78
|
+
def git_local_pod_check(path)
|
79
|
+
FileUtils.chdir(path)
|
81
80
|
git = Git.open(Pathname("./"))
|
82
81
|
current_branch = git.current_branch
|
83
82
|
last_stash_message = "#{current_branch}_pod_install_cache"
|
@@ -107,16 +106,19 @@ module LgPodPlugin
|
|
107
106
|
# 获取最新的一条 commit 信息
|
108
107
|
def self.git_ls_remote_refs(git, branch)
|
109
108
|
last_commit = nil
|
110
|
-
|
109
|
+
LgPodPlugin.log_green "git ls-remote #{git} #{branch}"
|
111
110
|
sha = %x(git ls-remote #{git} #{branch}).split(" ").first
|
112
111
|
if sha
|
113
112
|
last_commit = sha
|
113
|
+
return last_commit
|
114
114
|
else
|
115
115
|
ls = Git.ls_remote(git, :refs => true )
|
116
116
|
find_branch = ls["branches"][branch]
|
117
117
|
if find_branch
|
118
118
|
last_commit = find_branch[:sha]
|
119
|
+
return last_commit
|
119
120
|
end
|
121
|
+
return nil
|
120
122
|
end
|
121
123
|
end
|
122
124
|
|
@@ -9,59 +9,105 @@ require_relative 'git_util'
|
|
9
9
|
require_relative 'pod_spec.rb'
|
10
10
|
|
11
11
|
module LgPodPlugin
|
12
|
+
|
12
13
|
class Installer
|
14
|
+
attr_accessor :name
|
15
|
+
attr_accessor :version
|
16
|
+
attr_accessor :options
|
13
17
|
attr_accessor :profile
|
14
18
|
attr_accessor :target
|
19
|
+
attr_accessor :real_name
|
15
20
|
attr_accessor :downloader
|
16
21
|
attr_accessor :git_util
|
17
|
-
|
18
|
-
|
22
|
+
|
23
|
+
def initialize(profile, name, *requirements)
|
24
|
+
if name.include?("/")
|
25
|
+
self.name = name.split("/").first
|
26
|
+
else
|
27
|
+
self.name = name
|
28
|
+
end
|
29
|
+
self.real_name = name
|
19
30
|
self.profile = profile
|
20
31
|
self.git_util = GitUtil.new
|
21
32
|
self.downloader = Downloader.new
|
22
33
|
self.target = profile.send(:current_target_definition)
|
23
|
-
|
24
|
-
|
34
|
+
|
35
|
+
unless requirements && !requirements.empty?
|
36
|
+
self.pod(self.real_name, requirements)
|
37
|
+
return
|
38
|
+
end
|
39
|
+
|
40
|
+
first = requirements[0].first
|
41
|
+
if "#{first.class}" == "String"
|
42
|
+
self.version = first
|
43
|
+
elsif "#{first.class}" == "Hash"
|
44
|
+
self.options = first
|
25
45
|
end
|
46
|
+
|
47
|
+
hash_map = requirements[0].last
|
48
|
+
if "#{hash_map.class}" == "Hash"
|
49
|
+
self.options = hash_map
|
50
|
+
end
|
51
|
+
|
52
|
+
self.pod(name, requirements)
|
53
|
+
|
26
54
|
end
|
27
55
|
|
56
|
+
private
|
57
|
+
|
28
58
|
# @param [Object] name
|
29
59
|
# @param [Hash] options
|
30
60
|
# @return [Object] nil
|
31
|
-
def pod(name,
|
61
|
+
def pod(name, *requirements)
|
32
62
|
unless name
|
33
63
|
raise StandardError, 'A dependency requires a name.'
|
34
64
|
end
|
35
|
-
|
36
|
-
|
37
|
-
self.target.store_pod(
|
65
|
+
|
66
|
+
if !requirements
|
67
|
+
self.target.store_pod(self.real_name)
|
68
|
+
return
|
69
|
+
end
|
70
|
+
|
71
|
+
if self.version && !self.options
|
72
|
+
self.target.store_pod(self.real_name, self.version)
|
73
|
+
return
|
74
|
+
end
|
75
|
+
|
76
|
+
if self.version && self.options
|
77
|
+
self.target.store_pod(self.real_name, self.version, self.options)
|
78
|
+
return
|
79
|
+
end
|
80
|
+
|
81
|
+
hash_map = self.options
|
82
|
+
unless hash_map.is_a?(Hash)
|
83
|
+
self.target.store_pod(self.real_name)
|
38
84
|
return
|
39
85
|
end
|
40
86
|
|
41
|
-
path = options[:path]
|
42
|
-
tag = options[:tag]
|
43
|
-
commit = options[:commit]
|
44
|
-
url = options[:git]
|
45
|
-
branch = options[:branch]
|
46
|
-
depth = options[:depth] ||= true
|
47
87
|
real_path = nil
|
48
|
-
|
88
|
+
tag = hash_map[:tag]
|
89
|
+
url = hash_map[:git]
|
90
|
+
path = hash_map[:path]
|
91
|
+
commit = hash_map[:commit]
|
92
|
+
branch = hash_map[:branch]
|
93
|
+
depth = hash_map[:depth] ||= true
|
94
|
+
if path
|
49
95
|
profile_path = self.profile.send(:defined_in_file).dirname
|
50
96
|
real_path = Pathname.new(path).expand_path(profile_path)
|
51
97
|
end
|
52
98
|
# 找到本地组件库 执行 git pull
|
53
99
|
if real_path && File.directory?(real_path)
|
54
|
-
|
100
|
+
hash_map[:path] = real_path
|
101
|
+
self.install_local_pod(self.name, hash_map)
|
55
102
|
return
|
56
103
|
end
|
57
104
|
|
58
105
|
# 根据tag, commit下载文件
|
59
|
-
hash_map = options
|
60
106
|
hash_map.delete(:path)
|
61
107
|
if tag || commit
|
62
108
|
hash_map.delete(:branch)
|
63
109
|
hash_map.delete(:depth)
|
64
|
-
self.target.store_pod(
|
110
|
+
self.target.store_pod(self.real_name, hash_map)
|
65
111
|
return
|
66
112
|
end
|
67
113
|
|
@@ -70,17 +116,19 @@ module LgPodPlugin
|
|
70
116
|
hash_map.delete(:tag)
|
71
117
|
hash_map.delete(:commit)
|
72
118
|
hash_map.delete(:depth)
|
73
|
-
self.downloader.download_init(name, options)
|
119
|
+
self.downloader.download_init(self.name, options)
|
74
120
|
self.downloader.pre_download_pod(self.git_util)
|
75
|
-
self.target.store_pod(
|
121
|
+
self.target.store_pod(self.real_name, hash_map)
|
76
122
|
end
|
77
123
|
|
78
124
|
end
|
79
125
|
|
126
|
+
private
|
127
|
+
|
80
128
|
def install_form_specs(spec_path = nil)
|
81
129
|
spec_path ||= './Specs'
|
82
130
|
path = File.expand_path(spec_path, Dir.pwd)
|
83
|
-
file_objects = Dir.glob(File.expand_path("*.rb",path)).map do |file_path|
|
131
|
+
file_objects = Dir.glob(File.expand_path("*.rb", path)).map do |file_path|
|
84
132
|
#读取 xxx.rb文件
|
85
133
|
Spec.form_file(file_path)
|
86
134
|
end
|
@@ -95,27 +143,30 @@ module LgPodPlugin
|
|
95
143
|
end
|
96
144
|
|
97
145
|
private
|
146
|
+
|
98
147
|
def install_local_pod(name, options = {})
|
99
148
|
hash_map = options
|
100
|
-
|
149
|
+
local_path = options[:path]
|
101
150
|
branch = options[:branch]
|
102
|
-
unless Dir.
|
103
|
-
|
151
|
+
unless Dir.glob(File.expand_path(".git", local_path)).count > 0
|
152
|
+
LgPodPlugin.log_red("pod `#{name}` at path => #{local_path} 找不到.git目录")
|
104
153
|
return
|
105
154
|
end
|
106
|
-
local_path
|
107
|
-
|
108
|
-
|
155
|
+
unless Dir.glob(File.expand_path("#{name}.podspec", local_path)).count > 0
|
156
|
+
LgPodPlugin.log_red("pod `#{name}` at path => #{local_path} 找不到#{name}.podspec文件")
|
157
|
+
return
|
109
158
|
end
|
159
|
+
|
110
160
|
self.git_util.git_init(name, :branch => branch, :path => local_path)
|
111
|
-
self.git_util.git_local_pod_check
|
161
|
+
self.git_util.git_local_pod_check(local_path)
|
162
|
+
hash_map[:path] = local_path.to_path
|
112
163
|
hash_map.delete(:tag)
|
113
164
|
hash_map.delete(:git)
|
114
165
|
hash_map.delete(:depth)
|
115
166
|
hash_map.delete(:commit)
|
116
167
|
hash_map.delete(:branch)
|
117
168
|
# 安装本地私有组件库
|
118
|
-
self.target.store_pod(
|
169
|
+
self.target.store_pod(self.real_name, hash_map)
|
119
170
|
end
|
120
171
|
|
121
172
|
end
|
data/lib/lg_pod_plugin.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'git'
|
2
2
|
require 'sqlite3'
|
3
3
|
require "lg_pod_plugin/version"
|
4
|
+
require 'cocoapods/user_interface'
|
4
5
|
require_relative 'lg_pod_plugin/database'
|
5
6
|
require_relative 'lg_pod_plugin/download'
|
6
7
|
require_relative 'lg_pod_plugin/git_util'
|
@@ -10,17 +11,59 @@ require 'cocoapods-core/podfile/target_definition'
|
|
10
11
|
|
11
12
|
module LgPodPlugin
|
12
13
|
|
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
|
+
|
13
45
|
class Error < StandardError; end
|
14
|
-
|
15
|
-
def self.
|
16
|
-
|
46
|
+
|
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(msg)
|
60
|
+
Pod::CoreUI.puts msg
|
17
61
|
end
|
18
62
|
|
19
|
-
#
|
20
|
-
def
|
21
|
-
|
63
|
+
# 对 Profile 方法进行拓展
|
64
|
+
def pod(name, *requirements)
|
65
|
+
Installer.new(self, name, requirements)
|
22
66
|
end
|
23
67
|
|
24
|
-
# autoload :Command, '../lib/command/command'
|
25
68
|
end
|
26
69
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lg_pod_plugin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- dongzb01
|
@@ -111,14 +111,12 @@ dependencies:
|
|
111
111
|
description: 拦截pod_install 方法, 并设置 pod 方法参数列表
|
112
112
|
email:
|
113
113
|
- 1060545231@qq.com
|
114
|
-
executables:
|
115
|
-
- lg
|
114
|
+
executables: []
|
116
115
|
extensions: []
|
117
116
|
extra_rdoc_files: []
|
118
117
|
files:
|
119
118
|
- LICENSE
|
120
119
|
- README.md
|
121
|
-
- bin/lg
|
122
120
|
- lib/command/cache.rb
|
123
121
|
- lib/command/command.rb
|
124
122
|
- lib/lg_pod_plugin.rb
|