fastlane-plugin-patch 0.2.0 → 0.3.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e43a5073e5e6f001a9bac1edc8d5c01269365664
4
- data.tar.gz: 6a43c19f97495874c41cf06267c9090305e4fe89
3
+ metadata.gz: d6f15eb1e0e061b321516b1b0e2d10078fdc9862
4
+ data.tar.gz: 937b14b6afd6fa88b64bfe0cdf8a8d34399eea51
5
5
  SHA512:
6
- metadata.gz: d693bb861b0a1d6ccf36acac47d7068a5f6c8093deb6e100fcd5b18c2dd98bb21c055eabc12ad9b5ac28e695ef8b8c533b736a7a2a911351e0904f5835d1cb4b
7
- data.tar.gz: 006cc262c53603c6c2411e3197354e75792dcb4518474c6b43f245be10b697ea5f5835b0f3fea57964be6c687a0e87c30dfbb6592becdef6299dd8af5ff701db
6
+ metadata.gz: df39ffa6eb89432594b8ca3f1cc711aa50a8f1b5b51ea017d66be7d7578097ae4de76118b32b4a2b431038e046a03a44d0e686465d254c9599c1a2fe1b64b4ac
7
+ data.tar.gz: 407a273c955a255c4073a49e29b3aeadf47a62e665c5c7bfee6f53a07813159f8ff3f5e1610c79362f410e66034aa530b9a1bffdbd9d0c4e4123d144e131000f
data/README.md CHANGED
@@ -24,10 +24,10 @@ when automatically integrating an SDK.
24
24
 
25
25
  Please provide any feedback via issues in this repo.
26
26
 
27
- ### apply_patch action
27
+ ### patch action
28
28
 
29
29
  ```Ruby
30
- apply_patch(
30
+ patch(
31
31
  files: "examples/PatchTestAndroid/app/src/main/AndroidManifest.xml",
32
32
  regexp: %r{^\s*</application>},
33
33
  mode: :prepend,
@@ -54,7 +54,7 @@ global: false
54
54
 
55
55
  **Fastfile**:
56
56
  ```Ruby
57
- apply_patch(
57
+ patch(
58
58
  files: "examples/PatchTestAndroid/app/src/main/AndroidManifest.xml",
59
59
  patch: "patch.yaml"
60
60
  )
@@ -65,7 +65,7 @@ apply_patch(
65
65
  Capture groups may be used in `:replace` mode.
66
66
 
67
67
  ```Ruby
68
- apply_patch(
68
+ patch(
69
69
  files: "MyPod.podspec",
70
70
  regexp: /(s.name\s*=\s*)"MyPod"/,
71
71
  text: '\1"MyOtherPod"',
@@ -73,23 +73,25 @@ apply_patch(
73
73
  )
74
74
  ```
75
75
 
76
- ### revert_patch action
76
+ #### Revert patches
77
77
 
78
- Revert patches by passing the same arguments to the `revert_patch` action:
78
+ Revert patches by passing the optional `:revert` parameter:
79
79
 
80
80
  ```Ruby
81
- revert_patch(
81
+ patch(
82
82
  files: "examples/PatchTestAndroid/app/src/main/AndroidManifest.xml",
83
83
  regexp: %r{^\s*</application>},
84
84
  mode: :prepend,
85
- text: " <meta-data android:name=\"foo\" android:value=\"bar\" />\n"
85
+ text: " <meta-data android:name=\"foo\" android:value=\"bar\" />\n",
86
+ revert: true
86
87
  )
87
88
  ```
88
89
 
89
90
  ```Ruby
90
- revert_patch(
91
+ patch(
91
92
  files: "examples/PatchTestAndroid/app/src/main/AndroidManifest.xml",
92
93
  patch: "patch.yaml"
94
+ revert: true
93
95
  )
94
96
  ```
95
97
 
@@ -106,10 +108,14 @@ Patches using the `:replace` mode cannot be reverted.
106
108
  |:mode|:append, :prepend or :replace|Symbol|yes|:append|
107
109
  |:offset|Offset from which to start matching|Integer|yes|0|
108
110
  |:patch|A YAML file specifying patch data|String|yes| |
111
+ |:revert|Set to true to revert the specified patch rather than apply it|Boolean|yes|false|
109
112
 
110
113
  The :regexp and :text options must be set either in a patch file specified using the
111
114
  :patch argument or via arguments in the Fastfile.
112
115
 
116
+ **Note**: The `apply_patch` and `revert_patch` actions have been deprecated in favor of a single
117
+ `patch` action with an optional `:revert` parameter.
118
+
113
119
  ## Example
114
120
 
115
121
  Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, and running `fastlane install_plugins`.
@@ -122,6 +122,16 @@ YAML files. Revert the same patches with the revert_patch action.
122
122
  def self.is_supported?(platform)
123
123
  true
124
124
  end
125
+
126
+ def self.deprecated_notes
127
+ <<-EOF
128
+ Please use the patch action instead.
129
+ EOF
130
+ end
131
+
132
+ def self.category
133
+ :deprecated
134
+ end
125
135
  end
126
136
  end
127
137
  end
@@ -0,0 +1,153 @@
1
+ require 'yaml'
2
+
3
+ module Fastlane
4
+ module Actions
5
+ class PatchAction < Action
6
+ def self.run(params)
7
+ if params[:patch]
8
+ # raises
9
+ patch = YAML.load_file params[:patch]
10
+
11
+ # If the :patch option is present, load these params from the
12
+ # specified file. Action args override.
13
+ %w{regexp text mode global}.each do |option|
14
+ value = patch[option]
15
+ next if value.nil?
16
+
17
+ case option.to_sym
18
+ when :regexp
19
+ params[:regexp] = /#{value}/
20
+ when :mode
21
+ params[:mode] = value.to_sym
22
+ else
23
+ params[option.to_sym] = value
24
+ end
25
+ end
26
+ end
27
+
28
+ UI.user_error! "Must specify :regexp and :text either in a patch or via arguments" if
29
+ params[:regexp].nil? || params[:text].nil?
30
+
31
+ helper = Helper::PatchHelper
32
+ files = helper.files_from_params params
33
+ UI.user_error! "Must specify at least one file to patch using the :files option" if files.empty?
34
+
35
+ files.each do |file|
36
+ modified_contents = File.open(file, "r") do |f|
37
+ if params[:revert]
38
+ helper.revert_patch f.read,
39
+ params[:regexp],
40
+ params[:text],
41
+ params[:global],
42
+ params[:mode],
43
+ params[:offset]
44
+ else
45
+ helper.apply_patch f.read,
46
+ params[:regexp],
47
+ params[:text],
48
+ params[:global],
49
+ params[:mode],
50
+ params[:offset]
51
+ end
52
+ end
53
+
54
+ File.open(file, "w") { |f| f.write modified_contents }
55
+ end
56
+ rescue => e
57
+ UI.user_error! "Error in PatchAction: #{e.message}\n#{e.backtrace}"
58
+ end
59
+
60
+ def self.description
61
+ "Apply pattern-based patches to any text file."
62
+ end
63
+
64
+ def self.authors
65
+ ["Jimmy Dee"]
66
+ end
67
+
68
+ def self.details
69
+ <<-EOF
70
+ Append or prepend text to a specified pattern in a list of files or
71
+ replace it, once or globally. Patches are specified by arguments or
72
+ YAML files. Revert the same patches with the revert option.
73
+ EOF
74
+ end
75
+
76
+ def self.example_code
77
+ [
78
+ <<-EOF
79
+ patch(
80
+ files: "examples/PatchTestAndroid/app/src/main/AndroidManifest.xml",
81
+ regexp: %r{^\s*</application>},
82
+ mode: :prepend,
83
+ text: " <meta-data android:name=\"foo\" android:value=\"bar\" />\n"
84
+ )
85
+ EOF,
86
+ <<-EOF
87
+ patch(
88
+ files: "examples/PatchTestAndroid/app/src/main/AndroidManifest.xml",
89
+ patch: "patch.yaml"
90
+ )
91
+ EOF,
92
+ <<-EOF
93
+ patch(
94
+ files: "examples/PatchTestAndroid/app/src/main/AndroidManifest.xml",
95
+ patch: "patch.yaml",
96
+ revert: true
97
+ )
98
+ EOF
99
+
100
+ ]
101
+ end
102
+
103
+ def self.available_options
104
+ [
105
+ FastlaneCore::ConfigItem.new(key: :files,
106
+ description: "Absolute or relative path(s) to one or more files to patch",
107
+ optional: false,
108
+ is_string: false),
109
+ FastlaneCore::ConfigItem.new(key: :regexp,
110
+ description: "A regular expression to match",
111
+ optional: true,
112
+ type: Regexp),
113
+ FastlaneCore::ConfigItem.new(key: :text,
114
+ description: "Text used to modify to the match",
115
+ optional: true,
116
+ type: String),
117
+ FastlaneCore::ConfigItem.new(key: :global,
118
+ description: "If true, patch all occurrences of the pattern",
119
+ optional: true,
120
+ default_value: false,
121
+ is_string: false),
122
+ FastlaneCore::ConfigItem.new(key: :offset,
123
+ description: "Offset from which to start matching",
124
+ optional: true,
125
+ default_value: 0,
126
+ type: Integer),
127
+ FastlaneCore::ConfigItem.new(key: :mode,
128
+ description: ":append, :prepend or :replace",
129
+ optional: true,
130
+ default_value: :append,
131
+ type: Symbol),
132
+ FastlaneCore::ConfigItem.new(key: :patch,
133
+ description: "A YAML file specifying patch data",
134
+ optional: true,
135
+ type: String),
136
+ FastlaneCore::ConfigItem.new(key: :revert,
137
+ description: "Set to true to revert the specified patch rather than apply it",
138
+ optional: true,
139
+ default_value: false,
140
+ is_string: false)
141
+ ]
142
+ end
143
+
144
+ def self.is_supported?(platform)
145
+ true
146
+ end
147
+
148
+ def self.category
149
+ :project
150
+ end
151
+ end
152
+ end
153
+ end
@@ -121,6 +121,16 @@ using arguments or the same YAML patch files.
121
121
  def self.is_supported?(platform)
122
122
  true
123
123
  end
124
+
125
+ def self.deprecated_notes
126
+ <<-EOF
127
+ Please use the patch action with the :revert option instead.
128
+ EOF
129
+ end
130
+
131
+ def self.category
132
+ :deprecated
133
+ end
124
134
  end
125
135
  end
126
136
  end
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module Patch
3
- VERSION = "0.2.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-patch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jimmy Dee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-12 00:00:00.000000000 Z
11
+ date: 2017-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -132,6 +132,7 @@ files:
132
132
  - README.md
133
133
  - lib/fastlane/plugin/patch.rb
134
134
  - lib/fastlane/plugin/patch/actions/apply_patch_action.rb
135
+ - lib/fastlane/plugin/patch/actions/patch_action.rb
135
136
  - lib/fastlane/plugin/patch/actions/revert_patch_action.rb
136
137
  - lib/fastlane/plugin/patch/helper/patch_helper.rb
137
138
  - lib/fastlane/plugin/patch/version.rb
@@ -155,7 +156,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
156
  version: '0'
156
157
  requirements: []
157
158
  rubyforge_project:
158
- rubygems_version: 2.6.12
159
+ rubygems_version: 2.6.13
159
160
  signing_key:
160
161
  specification_version: 4
161
162
  summary: Apply and revert pattern-based patches to any text file.