cocoapods-patch 0.0.6 → 1.0.0

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: 5f1fc48aa0350d562d1ad476ab439624105cee81c22bab3b604a73131e1dd6eb
4
- data.tar.gz: b03c8bf4611c20f40536936fa02c2b43f833588b63038d083fe834be9a368a0c
3
+ metadata.gz: '09b3961ea67614d95650203463aa53b0e556e4630f52bc88a1d826670aa932db'
4
+ data.tar.gz: 2bbd9aeedbf8912b991c7e83762b12c5b1ef4def1d2fc0af03a066126fd6569f
5
5
  SHA512:
6
- metadata.gz: c96592ef2a7c17cbc4916afc582a0af9219bf2ecf351dbc6f21ab10a6660cb4de8e5a8fcd69c3cada1d5d69c6c29c53e654143f426193e23a0e4bf757acb4d78
7
- data.tar.gz: c7c7d93705236d902f9ddd02d4102ae800c9280bc1f8549d31b600a7fc4a1c5b6616b2029a0e2468fa58678fabc3dc5d5a9d09ddcba34f83ad414251a7added1
6
+ metadata.gz: d973db22fe9a736b16df29b251cc3cd177ce6c7cac399f3f7f75ca55786776015e650fb680003c4376d144621c765c6eaca66d429e4eae8e00e86bcbea2f3bb9
7
+ data.tar.gz: ee4054f9540888b48282e1275355658d17bf1b744dbe2f3ad725b53b4cf0a980085f49d34eb6815fdbf03484b92bb3e253669702bd6804b6ff50aefcd470e5d0
data/CHANGELOG.md ADDED
@@ -0,0 +1,25 @@
1
+ # Installation & Update
2
+
3
+ To install or update cocoapods-patch see [README](https://github.com/DoubleSymmetry/cocoapods-patch).
4
+
5
+ ## Main
6
+
7
+ ##### Enhancements
8
+
9
+ * None.
10
+
11
+ ##### Bug Fixes
12
+
13
+ * None.
14
+
15
+ ## 1.0.0 (1.11.21)
16
+
17
+ ##### Enhancements
18
+
19
+ * Use official pre_integrate hook
20
+ [dcvz](https://github.com/dcvz)
21
+ [#7](https://github.com/DoubleSymmetry/cocoapods-patch/pull/7)
22
+
23
+ ##### Bug Fixes
24
+
25
+ * None.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+
2
+ # cocoapods-patch
3
+
4
+ cocoapods-patch is a Cocoapods plugin that solves the problem of forking and maintaining a separate version of a Pod when only a small (often a one-liner), long-lived change in the original Pod is needed.
5
+
6
+ The idea behind the plugin is that patches should live inside the repo (in the `patches` directory) and be distributed together with the rest of your source code. This way, you can more easily code review and test the changes to a Pod and keep it synced across your team.
7
+
8
+ ## Installation
9
+
10
+ First, install the plugin
11
+
12
+ $ gem install cocoapods-patch
13
+
14
+ Next, add a `plugin 'cocoapods-patch'` line to your Podfile to use the plugin. This will enable [automatic apply](#automatically-applying-all-patches-on-install) so you don't have to worry about it again.
15
+
16
+ That's it, you're done.
17
+
18
+ **NOTE:**
19
+ `cocoapods-patch` version 1.0.0 and above require you to use Cocoapods 1.11.0 or greater.
20
+ For anything below that please use version 0.0.5.
21
+
22
+ ## Usage
23
+
24
+ ### Creating a patch
25
+
26
+ To create a patch, first, you need to modify the source code of the installed Pod. Do the desired changes to the Pod source code (under the `Pods/` directory). Once you're satisfied with the result, run:
27
+
28
+ pod patch create POD_NAME
29
+
30
+ This will create a `patches/POD_NAME.diff` file in your repository. The patch is a diff between the Pod version you have specified in your Podfile and your local changes to the Pod. You can now add and commit this patch.
31
+
32
+ ### Automatically applying all patches on install
33
+
34
+ cocoapod-patch can be seamlessly integrated into the normal iOS development workflow. If you follow the installation instructions and add `plugin 'cocoapods-patch'` to your Podfile, every time you do a `pod install`, the plugin will go throught all the available patches and try to apply them. It will only warn you when the patch cannot be applied.
35
+
36
+ ### Applying a patch manually
37
+
38
+ When you want to apply a patch to a pod, run
39
+
40
+ pod patch apply POD_NAME
41
+
42
+ This command will look for the appropriate patch in the `patches` directory and, if possibly, apply it to your local Pod. A patch can be applied only once.
@@ -1,3 +1,3 @@
1
1
  module CocoapodsPatch
2
- VERSION = "0.0.6"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -1,2 +1,2 @@
1
- require 'cocoapods-patch/command'
2
- require 'cocoapods-patch/hook'
1
+ require 'pod/command'
2
+ require 'pod/hook'
@@ -37,17 +37,16 @@ def apply_patch(patch_file)
37
37
  directory_arg = (ios_project_path.to_s.eql? ".") ? "Pods" : File.join(ios_project_path, 'Pods')
38
38
 
39
39
  Dir.chdir(repo_root) {
40
- Pod::UI.puts "YOOOOO #{patch_file} - #{directory_arg}"
41
- check_cmd = "git apply --check #{patch_file} --directory=#{directory_arg} -p2 2> /dev/null"
40
+ check_cmd = "git apply --check '#{patch_file}' --directory='#{directory_arg}' -p2 2> /dev/null"
42
41
 
43
42
  can_apply = system(check_cmd)
44
43
  if can_apply
45
44
  apply_cmd = check_cmd.gsub('--check ', '')
46
45
  did_apply = system(apply_cmd)
47
46
  if did_apply
48
- Pod::UI.puts "Successfully applied #{patch_file}"
47
+ Pod::UI.puts "Successfully applied #{patch_file} 🎉"
49
48
  else
50
- Pod::UI.warn "Failed to apply #{patch_file}"
49
+ Pod::UI.warn "Error: failed to apply #{patch_file}"
51
50
  end
52
51
  end
53
52
  }
@@ -24,7 +24,16 @@ module Pod
24
24
  help! 'A Pod name is required.' unless @name
25
25
  end
26
26
 
27
+ def clear_patches_folder_if_empty
28
+ if Dir.empty?(patches_path)
29
+ FileUtils.remove_dir(patches_path)
30
+ end
31
+ end
32
+
27
33
  def run
34
+ # create patches folder if it doesn't exist
35
+ FileUtils.mkdir_p(patches_path)
36
+
28
37
  Dir.mktmpdir('cocoapods-patch-', config.project_root) do |work_dir|
29
38
  sandbox = Pod::Sandbox.new(work_dir)
30
39
  installer = Pod::Installer.new(sandbox, config.podfile)
@@ -33,18 +42,35 @@ module Pod
33
42
  installer.prepare
34
43
  installer.resolve_dependencies
35
44
 
45
+ UI.puts "Checking if pod exists in project..."
46
+ specs_by_platform = installer.send :specs_for_pod, @name
47
+
48
+ if specs_by_platform.empty?
49
+ clear_patches_folder_if_empty
50
+ help! "Given pod does not exist in project. Did you use incorrect pod name?"
51
+
52
+ return
53
+ end
54
+
36
55
  pod_installer = installer.send :create_pod_installer, @name
37
56
  pod_installer.install!
38
57
 
58
+ UI.puts "Creating patch"
39
59
  theirs = Pathname.new(work_dir).join(@name).relative_path_from(config.project_root)
40
60
  ours = config.project_pods_root.join(@name).relative_path_from(config.project_root)
41
- gen_diff_cmd = "git diff --no-index #{theirs} #{ours} > #{patch_file}"
61
+ gen_diff_cmd = "git diff --no-index '#{theirs}' '#{ours}' > '#{patch_file}'"
42
62
 
43
63
  did_succeed = system(gen_diff_cmd)
44
64
  if not did_succeed.nil?
45
- UI.puts "Created patch #{patch_file}"
65
+ if File.empty?(patch_file)
66
+ File.delete(patch_file)
67
+ clear_patches_folder_if_empty
68
+ UI.warn "Error: no changes detected between current pod and original"
69
+ else
70
+ UI.puts "Created patch #{patch_file} 🎉"
71
+ end
46
72
  else
47
- UI.warn "Error creating patch for #{@name}"
73
+ UI.warn "Error: failed to create patch for #{@name}"
48
74
  end
49
75
  end
50
76
  end
@@ -1,3 +1,6 @@
1
+ require_relative 'patch/apply'
2
+ require_relative 'patch/create'
3
+
1
4
  module Pod
2
5
  class Command
3
6
  class Patch < Command
@@ -7,6 +10,10 @@ module Pod
7
10
  def patch_file
8
11
  config.project_root + 'patches' + "#{@name}.diff"
9
12
  end
13
+
14
+ def patches_path
15
+ config.project_root + 'patches'
16
+ end
10
17
  end
11
18
  end
12
19
  end
@@ -0,0 +1,3 @@
1
+ require_relative 'command/patch'
2
+ require_relative 'command/patch/apply'
3
+ require_relative 'command/patch/create'
data/lib/pod/hook.rb ADDED
@@ -0,0 +1,28 @@
1
+ require 'cocoapods'
2
+ require 'pathname'
3
+ require_relative 'command/patch/apply'
4
+
5
+ module CocoapodsPatch
6
+ module Hooks
7
+ Pod::HooksManager.register('cocoapods-patch', :pre_install) do |context|
8
+ Pod::UI.puts 'Preparing patchable pods for clean patching'
9
+ patches_dir = Pathname.new(Dir.pwd) + 'patches'
10
+ if patches_dir.directory?
11
+ patches = patches_dir.each_child.select { |c| c.to_s.end_with?('.diff') }
12
+ patches.each do |p|
13
+ pod_name = File.basename(p, ".diff")
14
+ context.sandbox.clean_pod(pod_name)
15
+ end
16
+ end
17
+ end
18
+
19
+ Pod::HooksManager.register('cocoapods-patch', :pre_integrate) do |context|
20
+ Pod::UI.puts 'Applying patches if necessary'
21
+ patches_dir = Pathname.new(Dir.pwd) + 'patches'
22
+ if patches_dir.directory?
23
+ patches = patches_dir.each_child.select { |c| c.to_s.end_with?('.diff') }
24
+ patches.each { |p| apply_patch(p) }
25
+ end
26
+ end
27
+ end
28
+ end
metadata CHANGED
@@ -1,43 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cocoapods-patch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Double Symmetry
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-14 00:00:00.000000000 Z
11
+ date: 2021-11-01 00:00:00.000000000 Z
12
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.11.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.11.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - "~>"
18
32
  - !ruby/object:Gem::Version
19
- version: '1.3'
33
+ version: '2.0'
20
34
  type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
- version: '1.3'
40
+ version: '2.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: rake
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ">="
45
+ - - "~>"
32
46
  - !ruby/object:Gem::Version
33
- version: '0'
47
+ version: '13.0'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ">="
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '13.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
39
67
  - !ruby/object:Gem::Version
40
- version: '0'
68
+ version: '3.9'
41
69
  description: Create & apply patches to Pods
42
70
  email:
43
71
  - dev@doublesymmetry.com
@@ -45,14 +73,15 @@ executables: []
45
73
  extensions: []
46
74
  extra_rdoc_files: []
47
75
  files:
48
- - lib/cocoapods-patch.rb
49
- - lib/cocoapods-patch/command.rb
50
- - lib/cocoapods-patch/command/patch.rb
51
- - lib/cocoapods-patch/command/patch/apply.rb
52
- - lib/cocoapods-patch/command/patch/create.rb
53
- - lib/cocoapods-patch/gem_version.rb
54
- - lib/cocoapods-patch/hook.rb
76
+ - CHANGELOG.md
77
+ - README.md
78
+ - lib/cocoapods_patch.rb
55
79
  - lib/cocoapods_plugin.rb
80
+ - lib/pod/command.rb
81
+ - lib/pod/command/patch.rb
82
+ - lib/pod/command/patch/apply.rb
83
+ - lib/pod/command/patch/create.rb
84
+ - lib/pod/hook.rb
56
85
  homepage: https://github.com/DoubleSymmetry/cocoapods-patch
57
86
  licenses:
58
87
  - MIT
@@ -1,3 +0,0 @@
1
- require 'cocoapods-patch/command/patch'
2
- require 'cocoapods-patch/command/patch/apply'
3
- require 'cocoapods-patch/command/patch/create'
@@ -1,27 +0,0 @@
1
- require 'cocoapods'
2
- require 'pathname'
3
- require_relative 'command/patch/apply'
4
-
5
- class Pod::Installer
6
- # Because our patches may also delete files, we need to apply them before the pod project is generated
7
- # The project is generated in the `integrate` method, so we override it
8
- # We first run our patch action and then the original implementation of the method
9
- # Reference: https://github.com/CocoaPods/CocoaPods/blob/760828a07f8fcfbff03bce13f56a1789b6f5a95d/lib/cocoapods/installer.rb#L178
10
- alias_method :integrate_old, :integrate
11
-
12
- def integrate
13
- # apply our patches
14
- apply_patches
15
- # run the original implementation
16
- integrate_old
17
- end
18
-
19
- def apply_patches
20
- Pod::UI.puts 'Applying patches if necessary'
21
- patches_dir = Pathname.new(Dir.pwd) + 'patches'
22
- if patches_dir.directory?
23
- patches = patches_dir.each_child.select { |c| c.to_s.end_with?('.diff') }
24
- patches.each { |p| apply_patch(p) }
25
- end
26
- end
27
- end
@@ -1 +0,0 @@
1
- require 'cocoapods-patch/gem_version'