cocoapods-links-v2 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a201168e823abb58642c8b37326fc52d779d0526f134820371ecd865a49974b2
4
+ data.tar.gz: b32acb3c0ddaf4f7a1b9b5ba606b118a292c48fa8c55b0974e9dc12398b3c0e4
5
+ SHA512:
6
+ metadata.gz: fc9b770366bbd74b26cdfc28aff152b055bf504cf8f0013c68e84ec5a22325916e0da59030dd7fabd64c83efe223f667c8869bc5bec3b9d003205d5db81cf3aa
7
+ data.tar.gz: e3f7cd8d4f303a5e44e4e18ede5d535e9b75ec5a4f120a02d883de4ad3e827d9ebfe0b56046fe4e201ec83bb7177275994ce797891314e02a580102e125b7cfe
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ *.gem
2
+ .bundle
3
+ vendor/bundle
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'rake'
7
+ gem 'bacon'
8
+ gem 'mocha'
9
+ gem 'mocha-on-bacon'
10
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,112 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ cocoapods-links (0.3.0)
5
+ cocoapods (~> 1.0)
6
+ json (~> 1.8)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ CFPropertyList (3.0.3)
12
+ activesupport (5.2.6)
13
+ concurrent-ruby (~> 1.0, >= 1.0.2)
14
+ i18n (>= 0.7, < 2)
15
+ minitest (~> 5.1)
16
+ tzinfo (~> 1.1)
17
+ addressable (2.8.0)
18
+ public_suffix (>= 2.0.2, < 5.0)
19
+ algoliasearch (1.27.5)
20
+ httpclient (~> 2.8, >= 2.8.3)
21
+ json (>= 1.5.1)
22
+ atomos (0.1.3)
23
+ bacon (1.2.0)
24
+ claide (1.0.3)
25
+ cocoapods (1.10.2)
26
+ addressable (~> 2.6)
27
+ claide (>= 1.0.2, < 2.0)
28
+ cocoapods-core (= 1.10.2)
29
+ cocoapods-deintegrate (>= 1.0.3, < 2.0)
30
+ cocoapods-downloader (>= 1.4.0, < 2.0)
31
+ cocoapods-plugins (>= 1.0.0, < 2.0)
32
+ cocoapods-search (>= 1.0.0, < 2.0)
33
+ cocoapods-trunk (>= 1.4.0, < 2.0)
34
+ cocoapods-try (>= 1.1.0, < 2.0)
35
+ colored2 (~> 3.1)
36
+ escape (~> 0.0.4)
37
+ fourflusher (>= 2.3.0, < 3.0)
38
+ gh_inspector (~> 1.0)
39
+ molinillo (~> 0.6.6)
40
+ nap (~> 1.0)
41
+ ruby-macho (~> 1.4)
42
+ xcodeproj (>= 1.19.0, < 2.0)
43
+ cocoapods-core (1.10.2)
44
+ activesupport (> 5.0, < 6)
45
+ addressable (~> 2.6)
46
+ algoliasearch (~> 1.0)
47
+ concurrent-ruby (~> 1.1)
48
+ fuzzy_match (~> 2.0.4)
49
+ nap (~> 1.0)
50
+ netrc (~> 0.11)
51
+ public_suffix
52
+ typhoeus (~> 1.0)
53
+ cocoapods-deintegrate (1.0.4)
54
+ cocoapods-downloader (1.4.0)
55
+ cocoapods-plugins (1.0.0)
56
+ nap
57
+ cocoapods-search (1.0.0)
58
+ cocoapods-trunk (1.5.0)
59
+ nap (>= 0.8, < 2.0)
60
+ netrc (~> 0.11)
61
+ cocoapods-try (1.2.0)
62
+ colored2 (3.1.2)
63
+ concurrent-ruby (1.1.9)
64
+ escape (0.0.4)
65
+ ethon (0.14.0)
66
+ ffi (>= 1.15.0)
67
+ ffi (1.15.3)
68
+ fourflusher (2.3.1)
69
+ fuzzy_match (2.0.4)
70
+ gh_inspector (1.1.3)
71
+ httpclient (2.8.3)
72
+ i18n (1.8.10)
73
+ concurrent-ruby (~> 1.0)
74
+ json (1.8.6)
75
+ minitest (5.14.4)
76
+ mocha (1.13.0)
77
+ mocha-on-bacon (0.2.3)
78
+ mocha (>= 0.13.0)
79
+ molinillo (0.6.6)
80
+ nanaimo (0.3.0)
81
+ nap (1.1.0)
82
+ netrc (0.11.0)
83
+ public_suffix (4.0.6)
84
+ rake (13.0.6)
85
+ rexml (3.2.5)
86
+ ruby-macho (1.4.0)
87
+ thread_safe (0.3.6)
88
+ typhoeus (1.4.0)
89
+ ethon (>= 0.9.0)
90
+ tzinfo (1.2.9)
91
+ thread_safe (~> 0.1)
92
+ xcodeproj (1.20.0)
93
+ CFPropertyList (>= 2.3.3, < 4.0)
94
+ atomos (~> 0.1.3)
95
+ claide (>= 1.0.2, < 2.0)
96
+ colored2 (~> 3.1)
97
+ nanaimo (~> 0.3.0)
98
+ rexml (~> 3.2.4)
99
+
100
+ PLATFORMS
101
+ ruby
102
+
103
+ DEPENDENCIES
104
+ bacon
105
+ bundler (~> 1.6)
106
+ cocoapods-links!
107
+ mocha
108
+ mocha-on-bacon
109
+ rake
110
+
111
+ BUNDLED WITH
112
+ 1.17.2
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Mike Owens <mike.owens11@gmail.com>
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,89 @@
1
+ # cocoapods-links
2
+
3
+ A CocoaPods plugin to manage local development pods
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ gem install cocoapods-links
9
+ ```
10
+
11
+ ## Purpose
12
+ Let's face it, pod development with local dependencies can be a pain. Let's say you have a project
13
+ `MyApp` a few pods declared in your `Podfile`:
14
+
15
+ ```ruby
16
+ pod 'Foo', '~> 1.0.0'
17
+ pod 'Bar', :git => 'https://github.com/MyCompany/Bar.git', :tag => "1.0.1"
18
+ ```
19
+
20
+ Perhaps you need to make some modifications to `Bar` to implement a new feature in `MyApp`. So
21
+ you modify your `Podfile`:
22
+
23
+ ```ruby
24
+ pod 'Bar', :path => "/path/to/bar/checkout"
25
+ ```
26
+ This development flow requires you to make a temporary change to your `Podfile`
27
+ that is managed by source control. Wouldn't it be great if CocoaPods offered a means to manage
28
+ development pods without having to alter files under source control?
29
+
30
+ Enter cocoapods-links.
31
+
32
+ With cocoapods-links, developers can easily test their pods using the provided link functionality.
33
+ Linking is a two-step process:
34
+
35
+ Using `pod link` in a project folder will register a global link. Then, in another pod,
36
+ `pod link <name>` will create a link to the registered pod as a development pod.
37
+
38
+ This allows developers to easily test a pod because changes will be reflected immediately.
39
+ When the link is no longer necessary, simply remove it with `pod unlink <name>`.
40
+
41
+ **NOTE:** Although the `Podfile` and `Podfile.lock` will not be updated using links, the Pods xcodeproj will be updated. If you check in the contents of your Pods directory then you must make sure
42
+ to unlink your development pods prior to committing any changes.
43
+
44
+ ## Usage
45
+
46
+ #### Register
47
+ To register a pod for local development linking:
48
+
49
+ ```bash
50
+ pod link
51
+ ```
52
+
53
+ #### Unregister
54
+ To unregister a pod:
55
+
56
+ ```bash
57
+ pod unlink
58
+ ```
59
+
60
+ #### Link
61
+ To link a pod for use in another pod project:
62
+
63
+ ```bash
64
+ pod link <name>
65
+ ```
66
+
67
+ #### Unlink
68
+ To unlink a pod from a pod project:
69
+
70
+ ```bash
71
+ pod unlink <name>
72
+ ```
73
+
74
+ #### List
75
+ To list all registered pods
76
+
77
+ ```bash
78
+ pod list links
79
+ ```
80
+
81
+ To list all linked pods in a pod project:
82
+
83
+ ```bash
84
+ pod list links --linked
85
+ ```
86
+
87
+ ### License
88
+
89
+ cocoapods-links is released under the MIT license. See [LICENSE](LICENSE).
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ task :default => :spec
4
+
5
+ task :spec do
6
+ title 'Running Specs'
7
+ files = FileList['spec/**/*_spec.rb'].shuffle.join(' ')
8
+ sh "bundle exec bacon #{files}"
9
+ end
10
+
11
+ def title(title)
12
+ cyan_title = "\033[0;36m#{title}\033[0m"
13
+ puts
14
+ puts '-' * 80
15
+ puts cyan_title
16
+ puts '-' * 80
17
+ puts
18
+ end
@@ -0,0 +1,34 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'cocoapods_links.rb'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'cocoapods-links-v2'
8
+ spec.version = CocoapodsLinks::VERSION
9
+ spec.authors = ['Hai Feng Kao']
10
+ spec.email = ['haifeng@cocoaspice.in']
11
+ spec.summary = 'A CocoaPods plugin for linking and unlinking local pods for local development'
12
+ spec.description = <<-DESC
13
+ This CocoaPods plugin linking functionality allows to easily test their pods.
14
+
15
+ This plugin adds the following commands to the CocoaPods command line:
16
+
17
+ * pod link <name>
18
+ * pod unlink <name>
19
+ * pod list links
20
+
21
+ DESC
22
+ spec.homepage = 'https://github.com/haifengkao/cocoapods-links-v2'
23
+ spec.license = 'MIT'
24
+
25
+ spec.files = `git ls-files`.split($/)
26
+ spec.test_files = spec.files.grep(%r{^spec/})
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_dependency 'cocoapods', '~> 1.0'
30
+ spec.add_dependency 'json', '~> 2'
31
+
32
+ spec.add_development_dependency 'bundler', '~> 1.6'
33
+ spec.add_development_dependency 'rake', '~> 10.4'
34
+ end
@@ -0,0 +1,3 @@
1
+ module CocoapodsLinks
2
+ VERSION = '0.4.0'
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'pod/pod'
2
+ require 'pod/lockfile'
3
+ require 'pod/command/link'
4
+ require 'pod/command/unlink'
5
+ require 'pod/command/list'
@@ -0,0 +1,44 @@
1
+ require 'pod/links'
2
+
3
+ module Pod
4
+ class Command
5
+ class Link < Command
6
+ self.summary = 'Create pod links for local pod development'
7
+ self.description = <<-DESC
8
+ The link functionality allows developers to easily test their pods.
9
+ Linking is a two-step process:
10
+
11
+ Using 'pod link' in a project folder will create a global link.
12
+ Then, in some other pod, 'pod link <name>' will create a link to
13
+ the local pod as a Development pod.
14
+
15
+ This allows to easily test a pod because changes will be reflected immediately.
16
+ When the link is no longer necessary, simply remove it with 'pod unlink <name>'.
17
+ DESC
18
+
19
+ self.arguments = [
20
+ CLAide::Argument.new('POD_NAME', false)
21
+ ]
22
+
23
+ def initialize(argv)
24
+ @pod = argv.shift_argument()
25
+ super
26
+ end
27
+
28
+ #
29
+ # if no pod is given from the command line then we will create a link for the current pod
30
+ # so other pods can link it as a development dependency
31
+ #
32
+ # if a pod name is given from the command line then we will link that pod into the current
33
+ # pod as a development dependency
34
+ #
35
+ def run
36
+ unless @pod.nil?
37
+ Pod::Command::Links.link @pod
38
+ else
39
+ Pod::Command::Links.register
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,30 @@
1
+ require 'pod/links'
2
+
3
+ module Pod
4
+ class Command
5
+ class List
6
+ class Links < List
7
+
8
+ self.summary = 'List links'
9
+ self.description = <<-DESC
10
+ List the registered links
11
+ DESC
12
+
13
+ def self.options
14
+ [[
15
+ '--linked', 'List pods linked in the current project'
16
+ ]].concat(super)
17
+ end
18
+
19
+ def initialize(argv)
20
+ @linked = argv.flag?('linked')
21
+ super
22
+ end
23
+
24
+ def run
25
+ Pod::Command::Links.list @linked
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,44 @@
1
+ require 'pod/links'
2
+
3
+ module Pod
4
+ class Command
5
+ class Unlink < Command
6
+ self.summary = 'Remove pod links'
7
+ self.description = <<-DESC
8
+ The unlink functionality allows developers to remove reference to their local pods
9
+ when they are finished testing
10
+
11
+ Using 'pod unlink' in a project folder will remove the global link.
12
+
13
+ Using 'pod unlink <name>' will remove the link to the <name> developement pod
14
+ and install the <name> pod configured in the Podfile
15
+
16
+ This allows to easily remove developement pod references
17
+ DESC
18
+
19
+ self.arguments = [
20
+ CLAide::Argument.new('POD_NAME', false)
21
+ ]
22
+
23
+ def initialize(argv)
24
+ @pod = argv.shift_argument()
25
+ super
26
+ end
27
+
28
+ #
29
+ # if no pod is given from the command line then we will unregister the pod from the
30
+ # registered links
31
+ #
32
+ # if a pod name is given from the command line then we will unlink the given pod from
33
+ # the project
34
+ #
35
+ def run
36
+ unless @pod.nil?
37
+ Pod::Command::Links.unlink @pod
38
+ else
39
+ Pod::Command::Links.unregister
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
data/lib/pod/links.rb ADDED
@@ -0,0 +1,289 @@
1
+ require 'json'
2
+ require 'fileutils'
3
+
4
+ module Pod
5
+ class Command
6
+
7
+ #
8
+ # Links utility that provides functionality around managing CocoaPod links
9
+ #
10
+ module Links
11
+
12
+ #
13
+ # Defines the path where the links database is stored (e.g. from pod link)
14
+ #
15
+ REGISTERED_DB = File.expand_path('~/.cocoapods/plugins/link/registered.json')
16
+
17
+ #
18
+ # Defines the path where per pod links are stored (e.g. from pod link <foo> command)
19
+ #
20
+ LINKED_DB = File.expand_path('~/.cocoapods/plugins/link/linked.json')
21
+
22
+ # return the path which has '*.podspec'
23
+ def self.registerProjectPath
24
+ spec = Dir["#{Dir.pwd}/*.podspec"]
25
+ unless spec.empty?
26
+ return Dir.pwd
27
+ end
28
+
29
+ # check parent directory
30
+ spec = Dir["#{Dir.pwd}/../*.podspec"]
31
+ unless spec.empty?
32
+ return File.expand_path("..", Dir.pwd)
33
+ end
34
+
35
+ help! 'A .podspec must exist in the directory `pod link` is ran'
36
+ end
37
+
38
+ # return the path which contains 'Podfile'
39
+ def self.linkProjectPath
40
+ spec = Dir["#{Dir.pwd}/Podfile"]
41
+ unless spec.empty?
42
+ return Dir.pwd
43
+ end
44
+
45
+ # check ./Example directory
46
+ spec = Dir["#{Dir.pwd}/Example/Podfile"]
47
+ unless spec.empty?
48
+ return File.expand_path("Example", Dir.pwd)
49
+ end
50
+
51
+ help! 'Podfile must exist in the directory `pod link` is ran'
52
+ end
53
+
54
+ #
55
+ # Register a pod for local development in the current working directory. This working
56
+ # directory must have a .podspec defining the pod
57
+ #
58
+ def self.register
59
+ self.print "Registering '#{self.podspec.name}' > #{self.registerProjectPath}"
60
+ self.write_db(REGISTERED_DB, self.registerd_db, {
61
+ self.podspec.name => {
62
+ "path" => self.registerProjectPath
63
+ }
64
+ })
65
+ end
66
+
67
+ #
68
+ # Unregister a pod
69
+ #
70
+ def self.unregister
71
+ self.print "Unregistering '#{self.podspec.name}' > #{self.registerProjectPath}"
72
+ db = self.registerd_db
73
+ db.delete(self.podspec.name)
74
+ self.write_db(REGISTERED_DB, db)
75
+ end
76
+
77
+ #
78
+ # Creates a link for the given pod into the current project. The pod must be registered
79
+ # using `pod link`
80
+ #
81
+ # @param pod the name of the pod to link into the current project
82
+ #
83
+ def self.link(pod)
84
+ podfileFolder = self.linkProjectPath
85
+ # only allow registered links to be used
86
+ registered_link = self.get_registered_link pod
87
+ if registered_link.nil?
88
+ Command::help! "Pod '#{pod}'' is not registered. Did you run `pod link` from the #{pod} directory?"
89
+ end
90
+
91
+ # add the linked pod
92
+ linked_pods = [pod]
93
+ if self.linked_db.has_key?(podfileFolder)
94
+ linked_pods = linked_pods.concat self.linked_db[podfileFolder]['pods']
95
+ end
96
+
97
+ self.print "Adding link to '#{pod}' > #{registered_link['path']}"
98
+ self.write_db(LINKED_DB, self.linked_db, {
99
+ podfileFolder => {
100
+ 'pods' => linked_pods.uniq
101
+ }
102
+ })
103
+
104
+ # install pod from link
105
+ Pod::Command::Install.run(["--project-directory=#{podfileFolder}"])
106
+ end
107
+
108
+ #
109
+ # Will unlink the give pod from the current pod project
110
+ #
111
+ # @param pod the name of the pod to unlink
112
+ #
113
+ def self.unlink(pod)
114
+ podfileFolder = self.linkProjectPath
115
+ if self.linked_db.has_key?(podfileFolder)
116
+ linked_pods = self.linked_db[podfileFolder]['pods']
117
+ linked_pods.delete(pod)
118
+
119
+ #
120
+ # Update databased based on link state
121
+ # if links exist, update list of links
122
+ # if links do not exist, remove entry
123
+ #
124
+ self.print "Removing link to '#{pod}'"
125
+ if linked_pods.empty?
126
+ db = self.linked_db
127
+ db.delete(podfileFolder)
128
+ self.write_db(LINKED_DB, db)
129
+ else
130
+ self.write_db(LINKED_DB, self.linked_db, {
131
+ podfileFolder => {
132
+ 'pods' => linked_pods
133
+ }
134
+ })
135
+ end
136
+
137
+ # install pod from repo
138
+ Pod::Command::Install.run(["--project-directory=#{podfileFolder}"])
139
+ end
140
+ end
141
+
142
+ #
143
+ # Entry point for the `pod` hook to check if the current pod project should use a linked pod
144
+ # of installed from the pod requirements. In order for a link to be returned the following
145
+ # must hold true:
146
+ #
147
+ # 1. The pod must be registered (e.g. pod link)
148
+ # 2. The current pod project must have linked the registered link (e.g. pod link <name>)
149
+ #
150
+ # @param name the name of the pod to find a link for
151
+ #
152
+ # @returns the registered link for the given name or nil
153
+ #
154
+ def self.get_link(name)
155
+ if self.linked_pods.include?(name)
156
+ return self.get_registered_link name
157
+ end
158
+ return nil
159
+ end
160
+
161
+ #
162
+ # List the links.
163
+ #
164
+ # - If linked is true then list the linked pods in the current project
165
+ # - Id linked is false then list the registered links
166
+ #
167
+ # @param linked flag to determine which links to list
168
+ #
169
+ def self.list(linked = false)
170
+ if linked
171
+ self.print "Linked pods:"
172
+ self.linked_pods.each do |pod|
173
+ self.print "* #{pod}"
174
+ end
175
+ else
176
+ self.print "Registered pods:"
177
+ self.registerd_db.each do |pod, link|
178
+ self.print "* #{pod} > #{link['path']}"
179
+ end
180
+ end
181
+ end
182
+
183
+ #
184
+ # Get list of pods that are linked for the current pod project
185
+ #
186
+ # @return an array of installed links
187
+ #
188
+ def self.installed_links
189
+ installed = []
190
+ self.linked_pods.each do |pod|
191
+ unless self.get_registered_link(pod).nil?
192
+ installed.append(pod)
193
+ end
194
+ end
195
+ return installed
196
+ end
197
+
198
+ #
199
+ # Prints a formatted message with the Pod Links prefix
200
+ #
201
+ def self.print(message)
202
+ UI.puts("Pod #{'Links'.cyan} #{message}")
203
+ end
204
+
205
+ private
206
+
207
+ #
208
+ # Retrieve the registered links database from disk
209
+ #
210
+ # @returns the registered links database
211
+ #
212
+ def self.registerd_db
213
+ if File.exists?(REGISTERED_DB)
214
+ return JSON.parse(File.read(REGISTERED_DB))
215
+ end
216
+ return {}
217
+ end
218
+
219
+ #
220
+ # Retrieve the linked database from disk
221
+ #
222
+ # @returns the linked database
223
+ #
224
+ def self.linked_db
225
+ if File.exists?(LINKED_DB)
226
+ return JSON.parse(File.read(LINKED_DB))
227
+ end
228
+ return {}
229
+ end
230
+
231
+ #
232
+ # Retrieve a link for the given name from the database. If the link does not exist in the
233
+ # for the given name then this will return nil
234
+ #
235
+ # @param name the name of the link to retrieve from the database
236
+ #
237
+ # @return the link for the given name or nil
238
+ #
239
+ def self.get_registered_link(name)
240
+ if self.registerd_db.has_key?(name)
241
+ return self.registerd_db[name]
242
+ end
243
+ return nil
244
+ end
245
+
246
+ #
247
+ # Retrieve the names of the linked pods for the current project (e.g. the current directory)
248
+ #
249
+ # @returns a list of pods that are linked for the current project
250
+ #
251
+ def self.linked_pods
252
+ podfileFolder = self.linkProjectPath
253
+ if self.linked_db.has_key?(podfileFolder)
254
+ return self.linked_db[podfileFolder]['pods']
255
+ end
256
+ return []
257
+ end
258
+
259
+ #
260
+ # Read the podspec in the current working directory
261
+ #
262
+ # @returns the podspec
263
+ #
264
+ def self.podspec
265
+ spec = Dir["#{self.registerProjectPath}/*.podspec"]
266
+ if spec.empty?
267
+ help! 'A .podspec must exist in the directory `pod link` is ran'
268
+ end
269
+ return Specification.from_file(spec.fetch(0))
270
+ end
271
+
272
+ #
273
+ # Will write the provided database to disk with the newly provided link content
274
+ #
275
+ # @param filename the name of the file to write the links to
276
+ # @param links the content to write to disk
277
+ #
278
+ def self.write_db(db_path, db, entry = {})
279
+ dirname = File.dirname(db_path)
280
+ unless File.directory?(dirname)
281
+ FileUtils.mkdir_p(dirname)
282
+ end
283
+ File.open(db_path,'w') do |f|
284
+ f.write(JSON.pretty_generate(db.merge(entry)))
285
+ end
286
+ end
287
+ end
288
+ end
289
+ end
@@ -0,0 +1,244 @@
1
+ require 'pod/links'
2
+
3
+ #
4
+ # Logic:
5
+ # Override of the Lockfile generation to filter out linked pods in favor of their previously
6
+ # installed state (e.g. the state reflected from the Podfile). This is somewhat brittle as it
7
+ # depends on the format of the Lockfile hash contents. If the format changes, then this will also
8
+ # need to be changed. It would be far better to integrate the link filtering elsewhere but this
9
+ # works "for now"
10
+ #
11
+
12
+ module Pod
13
+ class Lockfile
14
+
15
+ PODFILE_LOCK = "Podfile.lock"
16
+
17
+ alias_method :real_write_to_disk, :write_to_disk
18
+
19
+ #
20
+ # Hook the Podfile.lock file generation to allow us to filter out the links added to the
21
+ # Podfile.lock. The logic here is to replace the new Podfile.lock link content with what existed
22
+ # before the link was added. Currently, this is called for both Podfile.lock and Manifest.lock
23
+ # file so we only want to alter the Podfile.lock
24
+ #
25
+ # @param path path to write the .lock file to
26
+ #
27
+ def write_to_disk(path)
28
+
29
+ # code here mimics the original method but with link filtering
30
+ filename = File.basename(path)
31
+ path.dirname.mkpath unless path.dirname.exist?
32
+ yaml = to_link_yaml
33
+ File.open(path, 'w') { |f| f.write(yaml) }
34
+ self.defined_in_file = path
35
+ end
36
+
37
+ #
38
+ # Will create pretty print YAML stringfrom the links hash that is to be dumped to a Podfile.lock
39
+ #
40
+ # This code is identical to `to_yaml` except we pass the `to_link_hash` instead of the `to_hash`
41
+ #
42
+ # @returns the YAML string content to dump to a Podfile.lock without link content
43
+ #
44
+ def to_link_yaml
45
+ keys_hint = [
46
+ 'PODS',
47
+ 'DEPENDENCIES',
48
+ 'EXTERNAL SOURCES',
49
+ 'CHECKOUT OPTIONS',
50
+ 'SPEC CHECKSUMS',
51
+ 'COCOAPODS',
52
+ ]
53
+ YAMLHelper.convert_hash(to_link_hash, keys_hint, "\n\n")
54
+ end
55
+
56
+ #
57
+ # Will get the Podfile.lock contents hash after replacing the linked content with its previous
58
+ # Podfile.lock information keeping the Podfile and Podfile.lock in sync and clear of any link
59
+ # data
60
+ #
61
+ # @returns hash that is to be dumped to the Podfile.lock file without link content
62
+ #
63
+ def to_link_hash
64
+
65
+ # retrieve the lock contents with links
66
+ after_hash = to_hash
67
+
68
+ unless File.exists?(PODFILE_LOCK)
69
+ return after_hash
70
+ end
71
+
72
+ # retrieve the lock content before the links
73
+ before_hash = YAML.load(File.read(PODFILE_LOCK))
74
+
75
+ # retrieve installed links
76
+ links = Pod::Command::Links.installed_links
77
+
78
+ #
79
+ # Logic:
80
+ # Here we will replace anything that changed in the contents that will be dumped in the
81
+ # Podfile.lock due to links with the data that previously exists in the Podfile.lock. This
82
+ # allows the Podfile.lock with the dependency trees to remain unchanged when linking
83
+ # developement pods. The Podfile.lock contains several keys, but we only need to alter the
84
+ # following:
85
+ #
86
+ # - PODS
87
+ # - DEPENDENCIES
88
+ # - EXTERNAL SOURCES
89
+ # - CHECKOUT OPTIONS
90
+ # - SPEC CHECKSUMS
91
+ #
92
+ after_hash['PODS'] =
93
+ merge_pods links, before_hash['PODS'], after_hash['PODS']
94
+
95
+ after_hash['DEPENDENCIES'] =
96
+ merge_dependencies links, before_hash['DEPENDENCIES'], after_hash['DEPENDENCIES']
97
+
98
+ after_hash['EXTERNAL SOURCES'] =
99
+ merge_hashes links, before_hash['EXTERNAL SOURCES'], after_hash['EXTERNAL SOURCES']
100
+
101
+ after_hash['CHECKOUT OPTIONS'] =
102
+ merge_hashes links, before_hash['CHECKOUT OPTIONS'], after_hash['CHECKOUT OPTIONS']
103
+
104
+ after_hash['SPEC CHECKSUMS'] =
105
+ merge_hashes links, before_hash['SPEC CHECKSUMS'], after_hash['SPEC CHECKSUMS']
106
+
107
+ return after_hash
108
+ end
109
+
110
+ def merge_pods(links, before, after)
111
+ links.each do |link|
112
+ before_index = find_pod_index before, link
113
+ after_index = find_pod_index after, link
114
+ unless before_index.nil? || after_index.nil?
115
+
116
+ # get previous value
117
+ after_value = after[after_index]
118
+
119
+ # update new value
120
+ after[after_index] = before[before_index]
121
+
122
+ # iterate and update all dependencies of previous value
123
+ if after_value.is_a?(Hash)
124
+
125
+ # clean all deps that may have been added as new deps
126
+ after_value[after_value.keys[0]].each do |key|
127
+ # key: CocoaLumberjack/Core or CocoaLumberjack/Extensions (= 1.9.2)
128
+ key_desc = key.split(" (", 2)[0]
129
+
130
+ inner_after_index = find_pod_index after, key_desc
131
+ inner_before_index = find_pod_index before, key_desc
132
+
133
+ unless inner_before_index.nil? && inner_after_index.nil?
134
+ after[inner_after_index] = before[inner_before_index]
135
+ else
136
+ # if it was removed in the new deps
137
+ unless before_index.nil?
138
+ after.insert(before_index, before[before_index])
139
+ end
140
+ end
141
+ end
142
+ end
143
+ end
144
+ end
145
+ return after
146
+ end
147
+
148
+ #
149
+ # Will merge the DEPENDENCIES of the Podfile.lock before a link and after a link
150
+ #
151
+ # @param links the installed links
152
+ # @param before the DEPENDENCIES in the Podfile.lock before the link occurs
153
+ # @param after the DEPENDENCIES after the link (includes new link that we want to filter out)
154
+ #
155
+ # @returns the merged DEPENDENCIES replacing any links that were added with their previous value
156
+ #
157
+ def merge_dependencies(links, before, after)
158
+ links.each do |link|
159
+ before_index = find_dependency_index before, link
160
+ after_index = find_dependency_index after, link
161
+ unless before_index.nil? || after_index.nil?
162
+ after[after_index] = before[before_index]
163
+ end
164
+ end
165
+ return after
166
+ end
167
+
168
+ #
169
+ # Will merge the hashes of the Podfile.lock before a link and after a link
170
+ #
171
+ # @param links the installed links
172
+ # @param before the hash in the Podfile.lock before the link occurs
173
+ # @param after the hash after the link (includes new link that we want to filter out)
174
+ #
175
+ # @returns the merged hash replacing any links that were added with their previous value
176
+ #
177
+ def merge_hashes(links, before, after)
178
+ if before.nil?
179
+ return after
180
+ end
181
+ links.each do |link|
182
+ if before.has_key?(link)
183
+ after[link] = before[link]
184
+ else
185
+ if after.has_key?(link)
186
+ after.delete(link)
187
+ end
188
+ end
189
+ end
190
+ return after
191
+ end
192
+
193
+ private
194
+
195
+ #
196
+ # Find the index in the pod array based on the link name. The pod array
197
+ # also contains version/path information so we need to massage the pod value
198
+ # for comparison. Pods are in the following format:
199
+ #
200
+ # Name (requirements)
201
+ #
202
+ # Example:
203
+ # Alamofire (= 1.1.3)
204
+ #
205
+ # @param pods the array to search
206
+ # @param name the name of the pod to find
207
+ #
208
+ # NOTE: the pods in the array can be strings or hashes, so we will check for both
209
+ #
210
+ # @return the index of nil
211
+ #
212
+ def find_pod_index(pods, name)
213
+ pods.index { |pod|
214
+ desc = pod
215
+ if pod.is_a?(Hash)
216
+ desc = pod.keys[0]
217
+ end
218
+ desc.split(" (", 2)[0] == name
219
+ }
220
+ end
221
+
222
+ #
223
+ # Find the index in the dependency array based on the link name. The dependency array
224
+ # also contains version/path information so we need to massage the dependency value
225
+ # for comparison. Dependencies are in the following format:
226
+ #
227
+ # Name (requirements)
228
+ #
229
+ # Example:
230
+ # Alamofire (= 1.1.3)
231
+ # Quick (from `https://github.com/Quick/Quick`, tag `v0.2.2`)
232
+ #
233
+ # @param dependencies the array to search
234
+ # @param name the name of the dependency to find
235
+ #
236
+ # @returns the index of nil
237
+ #
238
+ def find_dependency_index(dependencies, name)
239
+ dependencies.index { |dependency|
240
+ dependency.split(" (", 2)[0] == name
241
+ }
242
+ end
243
+ end
244
+ end
data/lib/pod/pod.rb ADDED
@@ -0,0 +1,34 @@
1
+ require 'pod/links'
2
+
3
+ #
4
+ # In order to support installing pods from links we want to override the pod entry point
5
+ # in the pod spec so we can lookup a link prior to installing the pod
6
+ #
7
+ module Pod
8
+ class Podfile
9
+ module DSL
10
+ alias_method :real_pod, :pod
11
+ def pod(name = nil, *requirements, &block)
12
+ #
13
+ # Logic:
14
+ # Lookup a link for the given pod name. If a link exists then the pod will be installed
15
+ # via the link instead of the provided requirements (e.g. it will setup local pod development
16
+ # for the link). If the link does not exist, then the pod will be installed normally
17
+ #
18
+
19
+ # handle subspec link
20
+ linked_name = name
21
+ if name.include? "/"
22
+ linked_name = name.split("/")[0]
23
+ end
24
+ link = Pod::Command::Links.get_link(linked_name)
25
+ unless link.nil?
26
+ Pod::Command::Links.print "Using link '#{name}' > #{link['path']}"
27
+ real_pod(name, :path => link['path'], &block)
28
+ else
29
+ real_pod(name, *requirements, &block)
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ module Pod
4
+ describe Command::Link do
5
+ describe 'CLAide' do
6
+ it 'registers itself' do
7
+ Command.parse(['link']).should.be.instance_of Command::Link
8
+ end
9
+ end
10
+
11
+ before do
12
+ @command = Pod::Command::Link.new CLAide::ARGV.new []
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ module Pod
4
+ describe Command::List::Links do
5
+ describe 'CLAide' do
6
+ it 'registers itself' do
7
+ Command.parse(%w(list links)).should.be.instance_of Command::List::Links
8
+ end
9
+ end
10
+
11
+ before do
12
+ @command = Pod::Command::List::Links.new CLAide::ARGV.new []
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ require File.expand_path('../../spec_helper', __FILE__)
2
+
3
+ module Pod
4
+ describe Command::Unlink do
5
+ describe 'CLAide' do
6
+ it 'registers itself' do
7
+ Command.parse(['unlink']).should.be.instance_of Command::Unlink
8
+ end
9
+ end
10
+
11
+ before do
12
+ @command = Pod::Command::Unlink.new CLAide::ARGV.new []
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ ROOT = Pathname.new(File.expand_path('../../', __FILE__))
2
+ $:.unshift((ROOT + 'lib').to_s)
3
+
4
+ require 'cocoapods'
5
+ require 'cocoapods_plugin'
6
+
7
+ require 'mocha'
8
+ require 'mocha-on-bacon'
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cocoapods-links-v2
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
+ platform: ruby
6
+ authors:
7
+ - Hai Feng Kao
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-07-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: cocoapods
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.4'
69
+ description: |2+
70
+ This CocoaPods plugin linking functionality allows to easily test their pods.
71
+
72
+ This plugin adds the following commands to the CocoaPods command line:
73
+
74
+ * pod link <name>
75
+ * pod unlink <name>
76
+ * pod list links
77
+
78
+ email:
79
+ - haifeng@cocoaspice.in
80
+ executables: []
81
+ extensions: []
82
+ extra_rdoc_files: []
83
+ files:
84
+ - ".gitignore"
85
+ - Gemfile
86
+ - Gemfile.lock
87
+ - LICENSE
88
+ - README.md
89
+ - Rakefile
90
+ - cocoapods_links.gemspec
91
+ - lib/cocoapods_links.rb
92
+ - lib/cocoapods_plugin.rb
93
+ - lib/pod/command/link.rb
94
+ - lib/pod/command/list.rb
95
+ - lib/pod/command/unlink.rb
96
+ - lib/pod/links.rb
97
+ - lib/pod/lockfile.rb
98
+ - lib/pod/pod.rb
99
+ - spec/command/link_spec.rb
100
+ - spec/command/list_spec.rb
101
+ - spec/command/unlink_spec.rb
102
+ - spec/spec_helper.rb
103
+ homepage: https://github.com/haifengkao/cocoapods-links-v2
104
+ licenses:
105
+ - MIT
106
+ metadata: {}
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubygems_version: 3.0.3
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: A CocoaPods plugin for linking and unlinking local pods for local development
126
+ test_files:
127
+ - spec/command/link_spec.rb
128
+ - spec/command/list_spec.rb
129
+ - spec/command/unlink_spec.rb
130
+ - spec/spec_helper.rb