fastlane-plugin-patch 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +145 -0
- data/lib/fastlane/plugin/patch.rb +16 -0
- data/lib/fastlane/plugin/patch/actions/apply_patch_action.rb +124 -0
- data/lib/fastlane/plugin/patch/actions/revert_patch_action.rb +123 -0
- data/lib/fastlane/plugin/patch/helper/patch_helper.rb +84 -0
- data/lib/fastlane/plugin/patch/version.rb +5 -0
- metadata +163 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5a9f0ea20fda14d47e1b04015ebc7048990beca0
|
4
|
+
data.tar.gz: 9f044357df62f527a53cf2c48451e3050d6faa9a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dfe86d539223d6a2e65724b1bd1d70566b978abae84f5820e7c0352178a937f1eaf2761402b33bbafc5345b54153315f9bc433720b90d5a9ab1cd50ad9f1e8ce
|
7
|
+
data.tar.gz: 12c460257e0c22777678fb6e8637d6cf27a5805f1e46241167136fb8af01434b73332d22854b033e20bd56a29a4b020b16e6a950bbd0bce9a348060568276ede
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Jimmy Dee <jgvdthree@gmail.com>
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
# patch plugin
|
2
|
+
|
3
|
+
[![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-patch)
|
4
|
+
[![Gem](https://img.shields.io/gem/v/fastlane-plugin-patch.svg?style=flat)](https://rubygems.org/gems/fastlane-plugin-patch)
|
5
|
+
[![Downloads](https://img.shields.io/gem/dt/fastlane-plugin-patch.svg?style=flat)](https://rubygems.org/gems/fastlane-plugin-patch)
|
6
|
+
[![License](https://img.shields.io/badge/license-MIT-green.svg?style=flat)](https://github.com/jdee/fastlane-plugin-patch/blob/master/LICENSE)
|
7
|
+
[![CircleCI](https://img.shields.io/circleci/project/github/jdee/fastlane-plugin-patch.svg)](https://circleci.com/gh/jdee/fastlane-plugin-patch)
|
8
|
+
|
9
|
+
## Getting Started
|
10
|
+
|
11
|
+
This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-patch`, add it to your project by running:
|
12
|
+
|
13
|
+
```bash
|
14
|
+
fastlane add_plugin patch
|
15
|
+
```
|
16
|
+
|
17
|
+
## About patch
|
18
|
+
|
19
|
+
Apply and revert pattern-based patches to any text file.
|
20
|
+
|
21
|
+
This is a very preliminary plugin to apply and revert patches to text files. One
|
22
|
+
of the main intended use cases for this plugin is source-code modification, e.g.
|
23
|
+
when automatically integrating an SDK.
|
24
|
+
|
25
|
+
Please provide any feedback via issues in this repo.
|
26
|
+
|
27
|
+
### apply_patch action
|
28
|
+
|
29
|
+
```Ruby
|
30
|
+
apply_patch(
|
31
|
+
files: "examples/PatchTestAndroid/app/src/main/AndroidManifest.xml",
|
32
|
+
regexp: %r{^\s*</application>},
|
33
|
+
mode: :prepend,
|
34
|
+
text: " <meta-data android:name=\"foo\" android:value=\"bar\" />\n"
|
35
|
+
)
|
36
|
+
```
|
37
|
+
|
38
|
+
This action matches one or all occurrences of a specified regular expression and
|
39
|
+
modifies the file contents based on the optional `:mode` parameter. By default,
|
40
|
+
the action appends the specified text to the pattern match. It can also prepend
|
41
|
+
the text or replace the pattern match with the text. Use an optional `:global`
|
42
|
+
parameter to apply the patch to all instances of the regular expression.
|
43
|
+
|
44
|
+
The `regexp`, `text`, `mode` and `global` options may be specified in a YAML file to
|
45
|
+
define a patch, e.g.:
|
46
|
+
|
47
|
+
**patch.yaml**:
|
48
|
+
```yaml
|
49
|
+
regexp: '^\s*</application>'
|
50
|
+
mode: prepend
|
51
|
+
text: " <meta-data android:name='foo' android:value='bar' />\n"
|
52
|
+
global: false
|
53
|
+
```
|
54
|
+
|
55
|
+
**Fastfile**:
|
56
|
+
```Ruby
|
57
|
+
apply_patch(
|
58
|
+
files: "examples/PatchTestAndroid/app/src/main/AndroidManifest.xml",
|
59
|
+
patch: "patch.yaml"
|
60
|
+
)
|
61
|
+
```
|
62
|
+
|
63
|
+
### revert_patch action
|
64
|
+
|
65
|
+
Revert patches by passing the same arguments to the `revert_patch` action:
|
66
|
+
|
67
|
+
```Ruby
|
68
|
+
revert_patch(
|
69
|
+
files: "examples/PatchTestAndroid/app/src/main/AndroidManifest.xml",
|
70
|
+
regexp: %r{^\s*</application>},
|
71
|
+
mode: :prepend,
|
72
|
+
text: " <meta-data android:name=\"foo\" android:value=\"bar\" />\n"
|
73
|
+
)
|
74
|
+
```
|
75
|
+
|
76
|
+
```Ruby
|
77
|
+
revert_patch(
|
78
|
+
files: "examples/PatchTestAndroid/app/src/main/AndroidManifest.xml",
|
79
|
+
patch: "patch.yaml"
|
80
|
+
)
|
81
|
+
```
|
82
|
+
|
83
|
+
Patches using the `:replace` mode cannot be reverted.
|
84
|
+
|
85
|
+
### Options
|
86
|
+
|
87
|
+
|key|description|type|optional|default value|
|
88
|
+
|---|-----------|----|--------|-------------|
|
89
|
+
|:files|Absolute or relative path(s) to one or more files to patch|Array or String|no| |
|
90
|
+
|:regexp|A regular expression to match|Regexp|yes| |
|
91
|
+
|:text|Text to append to the match|String|yes| |
|
92
|
+
|:global|If true, patch all occurrences of the pattern|Boolean|yes|false|
|
93
|
+
|:mode|:append, :prepend or :replace|Symbol|yes|:append|
|
94
|
+
|:offset|Offset from which to start matching|Integer|yes|0|
|
95
|
+
|:patch|A YAML file specifying patch data|String|yes| |
|
96
|
+
|
97
|
+
The :regexp and :text options must be set either in a patch file specified using the
|
98
|
+
:patch argument or via arguments in the Fastfile.
|
99
|
+
|
100
|
+
## Example
|
101
|
+
|
102
|
+
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`.
|
103
|
+
|
104
|
+
The examples folder contains an empty Android project called PatchTestAndroid. There is an example
|
105
|
+
patch at the repo root in `patch.yaml` that will add a `meta-data` key to the end of the `application`
|
106
|
+
element in the Android project's manifest. The Fastfile includes two lanes: `apply` and `revert`.
|
107
|
+
|
108
|
+
Apply the patch to `examples/PatchTestAndroid/app/src/main/AndroidManifest.xml`:
|
109
|
+
```bash
|
110
|
+
fastlane apply
|
111
|
+
```
|
112
|
+
|
113
|
+
Revert the patch:
|
114
|
+
```bash
|
115
|
+
fastlane revert
|
116
|
+
```
|
117
|
+
|
118
|
+
## Run tests for this plugin
|
119
|
+
|
120
|
+
To run both the tests, and code style validation, run
|
121
|
+
|
122
|
+
```
|
123
|
+
rake
|
124
|
+
```
|
125
|
+
|
126
|
+
To automatically fix many of the styling issues, use
|
127
|
+
```
|
128
|
+
rubocop -a
|
129
|
+
```
|
130
|
+
|
131
|
+
## Issues and Feedback
|
132
|
+
|
133
|
+
For any other issues and feedback about this plugin, please submit it to this repository.
|
134
|
+
|
135
|
+
## Troubleshooting
|
136
|
+
|
137
|
+
If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
|
138
|
+
|
139
|
+
## Using _fastlane_ Plugins
|
140
|
+
|
141
|
+
For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
|
142
|
+
|
143
|
+
## About _fastlane_
|
144
|
+
|
145
|
+
_fastlane_ is the easiest way to automate beta deployments and releases for your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'fastlane/plugin/patch/version'
|
2
|
+
|
3
|
+
module Fastlane
|
4
|
+
module Patch
|
5
|
+
# Return all .rb files inside the "actions" and "helper" directory
|
6
|
+
def self.all_classes
|
7
|
+
Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
# By default we want to import all available actions and helpers
|
13
|
+
# A plugin can contain any number of actions and plugins
|
14
|
+
Fastlane::Patch.all_classes.each do |current|
|
15
|
+
require current
|
16
|
+
end
|
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Fastlane
|
4
|
+
module Actions
|
5
|
+
class ApplyPatchAction < 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 = Fastlane::Helper::PatchHelper
|
32
|
+
helper.files_from_params(params).each do |file|
|
33
|
+
modified_contents = File.open(file, "r") do |f|
|
34
|
+
helper.apply_patch f.read,
|
35
|
+
params[:regexp],
|
36
|
+
params[:text],
|
37
|
+
params[:global],
|
38
|
+
params[:mode],
|
39
|
+
params[:offset]
|
40
|
+
end
|
41
|
+
|
42
|
+
File.open(file, "w") { |f| f.write modified_contents }
|
43
|
+
end
|
44
|
+
rescue => e
|
45
|
+
UI.user_error! "Error in ApplyPatchAction: #{e.message}\n#{e.backtrace}"
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.description
|
49
|
+
"Apply pattern-based patches to any text file."
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.authors
|
53
|
+
["Jimmy Dee"]
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.details
|
57
|
+
<<-EOF
|
58
|
+
Append or prepend text to a specified pattern in a list of files or
|
59
|
+
replace it, once or globally. Patches are specified by arguments or
|
60
|
+
YAML files. Revert the same patches with the revert_patch action.
|
61
|
+
EOF
|
62
|
+
end
|
63
|
+
|
64
|
+
def self.example_code
|
65
|
+
[
|
66
|
+
<<-EOF
|
67
|
+
apply_patch(
|
68
|
+
files: "examples/PatchTestAndroid/app/src/main/AndroidManifest.xml",
|
69
|
+
regexp: %r{^\s*</application>},
|
70
|
+
mode: :prepend,
|
71
|
+
text: " <meta-data android:name=\"foo\" android:value=\"bar\" />\n"
|
72
|
+
)
|
73
|
+
EOF,
|
74
|
+
<<-EOF
|
75
|
+
apply_patch(
|
76
|
+
files: "examples/PatchTestAndroid/app/src/main/AndroidManifest.xml",
|
77
|
+
patch: "patch.yaml"
|
78
|
+
)
|
79
|
+
EOF
|
80
|
+
]
|
81
|
+
end
|
82
|
+
|
83
|
+
def self.available_options
|
84
|
+
[
|
85
|
+
FastlaneCore::ConfigItem.new(key: :files,
|
86
|
+
description: "Absolute or relative path(s) to one or more files to patch",
|
87
|
+
optional: false,
|
88
|
+
is_string: false),
|
89
|
+
FastlaneCore::ConfigItem.new(key: :regexp,
|
90
|
+
description: "A regular expression to match",
|
91
|
+
optional: true,
|
92
|
+
type: Regexp),
|
93
|
+
FastlaneCore::ConfigItem.new(key: :text,
|
94
|
+
description: "Text used to modify to the match",
|
95
|
+
optional: true,
|
96
|
+
type: String),
|
97
|
+
FastlaneCore::ConfigItem.new(key: :global,
|
98
|
+
description: "If true, patch all occurrences of the pattern",
|
99
|
+
optional: true,
|
100
|
+
default_value: false,
|
101
|
+
is_string: false),
|
102
|
+
FastlaneCore::ConfigItem.new(key: :offset,
|
103
|
+
description: "Offset from which to start matching",
|
104
|
+
optional: true,
|
105
|
+
default_value: 0,
|
106
|
+
type: Integer),
|
107
|
+
FastlaneCore::ConfigItem.new(key: :mode,
|
108
|
+
description: ":append, :prepend or :replace",
|
109
|
+
optional: true,
|
110
|
+
default_value: :append,
|
111
|
+
type: Symbol),
|
112
|
+
FastlaneCore::ConfigItem.new(key: :patch,
|
113
|
+
description: "A YAML file specifying patch data",
|
114
|
+
optional: true,
|
115
|
+
type: String)
|
116
|
+
]
|
117
|
+
end
|
118
|
+
|
119
|
+
def self.is_supported?(platform)
|
120
|
+
true
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Fastlane
|
4
|
+
module Actions
|
5
|
+
class RevertPatchAction < 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 = Fastlane::Helper::PatchHelper
|
32
|
+
helper.files_from_params(params).each do |file|
|
33
|
+
modified_contents = File.open(file, "r") do |f|
|
34
|
+
helper.revert_patch f.read,
|
35
|
+
params[:regexp],
|
36
|
+
params[:text],
|
37
|
+
params[:global],
|
38
|
+
params[:mode],
|
39
|
+
params[:offset]
|
40
|
+
end
|
41
|
+
|
42
|
+
File.open(file, "w") { |f| f.write modified_contents }
|
43
|
+
end
|
44
|
+
rescue => e
|
45
|
+
UI.user_error! "Error in RevertPatchAction: #{e.message}\n#{e.backtrace}"
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.description
|
49
|
+
"Revert the action of apply_patch"
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.authors
|
53
|
+
["Jimmy Dee"]
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.details
|
57
|
+
<<-EOF
|
58
|
+
Revert a patch by specifying the arguments provided to apply_patch
|
59
|
+
using arguments or the same YAML patch files.
|
60
|
+
EOF
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.example_code
|
64
|
+
[
|
65
|
+
<<-EOF
|
66
|
+
revert_patch(
|
67
|
+
files: "examples/PatchTestAndroid/app/src/main/AndroidManifest.xml",
|
68
|
+
regexp: %r{^\s*</application>},
|
69
|
+
mode: :prepend,
|
70
|
+
text: " <meta-data android:name=\"foo\" android:value=\"bar\" />\n"
|
71
|
+
)
|
72
|
+
EOF,
|
73
|
+
<<-EOF
|
74
|
+
revert_patch(
|
75
|
+
files: "examples/PatchTestAndroid/app/src/main/AndroidManifest.xml",
|
76
|
+
patch: "patch.yaml"
|
77
|
+
)
|
78
|
+
EOF
|
79
|
+
]
|
80
|
+
end
|
81
|
+
|
82
|
+
def self.available_options
|
83
|
+
[
|
84
|
+
FastlaneCore::ConfigItem.new(key: :files,
|
85
|
+
description: "Absolute or relative path(s) to one or more files to patch",
|
86
|
+
optional: false,
|
87
|
+
is_string: false),
|
88
|
+
FastlaneCore::ConfigItem.new(key: :regexp,
|
89
|
+
description: "A regular expression to match",
|
90
|
+
optional: true,
|
91
|
+
type: Regexp),
|
92
|
+
FastlaneCore::ConfigItem.new(key: :text,
|
93
|
+
description: "Text used to modify to the match",
|
94
|
+
optional: true,
|
95
|
+
type: String),
|
96
|
+
FastlaneCore::ConfigItem.new(key: :global,
|
97
|
+
description: "If true, patch all occurrences of the pattern",
|
98
|
+
optional: true,
|
99
|
+
default_value: false,
|
100
|
+
is_string: false),
|
101
|
+
FastlaneCore::ConfigItem.new(key: :offset,
|
102
|
+
description: "Offset from which to start matching",
|
103
|
+
optional: true,
|
104
|
+
default_value: 0,
|
105
|
+
type: Integer),
|
106
|
+
FastlaneCore::ConfigItem.new(key: :mode,
|
107
|
+
description: ":append or :prepend",
|
108
|
+
optional: true,
|
109
|
+
default_value: :append,
|
110
|
+
type: Symbol),
|
111
|
+
FastlaneCore::ConfigItem.new(key: :patch,
|
112
|
+
description: "A YAML file specifying patch data",
|
113
|
+
optional: true,
|
114
|
+
type: String)
|
115
|
+
]
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.is_supported?(platform)
|
119
|
+
true
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Fastlane
|
2
|
+
module Helper
|
3
|
+
class PatchHelper
|
4
|
+
class << self
|
5
|
+
# Add the specified text after the specified pattern.
|
6
|
+
# Returns a modified copy of the string.
|
7
|
+
#
|
8
|
+
# :contents: A string to modify, e.g. the contents of a file
|
9
|
+
# :regexp: A regular expression specifying a pattern to be matched
|
10
|
+
# :text: Text to be appended to the specified pattern
|
11
|
+
# :global: Boolean flag. If true, patch all occurrences of the regex.
|
12
|
+
# :mode: :append, :prepend or :replace to specify how to apply the patch
|
13
|
+
# :offset: Starting position for matching
|
14
|
+
def apply_patch(contents, regexp, text, global, mode, offset)
|
15
|
+
search_position = offset
|
16
|
+
while (matches = regexp.match(contents, search_position))
|
17
|
+
patched_pattern =
|
18
|
+
case mode
|
19
|
+
when :append
|
20
|
+
"#{matches[0]}#{text}"
|
21
|
+
when :prepend
|
22
|
+
"#{text}#{matches[0]}"
|
23
|
+
when :replace
|
24
|
+
text
|
25
|
+
else
|
26
|
+
raise ArgumentError, "Invalid mode argument. Specify :append, :prepend or :replace."
|
27
|
+
end
|
28
|
+
|
29
|
+
contents = "#{matches.pre_match}#{patched_pattern}#{matches.post_match}"
|
30
|
+
search_position = matches.pre_match.length + patched_pattern.length
|
31
|
+
break unless global
|
32
|
+
end
|
33
|
+
contents
|
34
|
+
end
|
35
|
+
|
36
|
+
# Reverts a patch. Use the same arguments that were supplied to apply_patch.
|
37
|
+
# The mode argument can only be :append or :prepend. Patches using :replace
|
38
|
+
# cannot be reverted.
|
39
|
+
# Returns a modified copy of the string.
|
40
|
+
#
|
41
|
+
# :contents: A string to modify, e.g. the contents of a file
|
42
|
+
# :regexp: A regular expression specifying a pattern to be matched
|
43
|
+
# :text: Text to be appended to the specified pattern
|
44
|
+
# :global: Boolean flag. If true, patch all occurrences of the regex.
|
45
|
+
# :mode: :append or :prepend. :replace patches cannot be reverted automatically.
|
46
|
+
# :offset: Starting position for matching
|
47
|
+
def revert_patch(contents, regexp, text, global, mode, offset)
|
48
|
+
search_position = offset
|
49
|
+
regexp_string = regexp.to_s
|
50
|
+
|
51
|
+
patched_regexp =
|
52
|
+
case mode
|
53
|
+
when :append
|
54
|
+
/#{regexp_string}#{Regexp.quote(text)}/m
|
55
|
+
when :prepend
|
56
|
+
/#{Regexp.quote(text)}#{regexp_string}/m
|
57
|
+
else
|
58
|
+
raise ArgumentError, "Invalid mode argument. Specify :append or :prepend."
|
59
|
+
end
|
60
|
+
|
61
|
+
while (matches = patched_regexp.match(contents, search_position))
|
62
|
+
reverted_text = matches[0].sub(text, '')
|
63
|
+
contents = "#{matches.pre_match}#{reverted_text}#{matches.post_match}"
|
64
|
+
search_position = matches.pre_match.length + reverted_text.length
|
65
|
+
break unless global
|
66
|
+
end
|
67
|
+
|
68
|
+
contents
|
69
|
+
end
|
70
|
+
|
71
|
+
def files_from_params(params)
|
72
|
+
case params[:files]
|
73
|
+
when Array
|
74
|
+
params[:files].map(&:to_s)
|
75
|
+
when String
|
76
|
+
params[:files].split(",")
|
77
|
+
else
|
78
|
+
raise ArgumentError, "Invalid type #{params[:files].class} for :files option. Specify an Array or a String."
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
metadata
ADDED
@@ -0,0 +1,163 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fastlane-plugin-patch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jimmy Dee
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-07-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pry
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec-simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rubocop
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: fastlane
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 2.47.0
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 2.47.0
|
125
|
+
description:
|
126
|
+
email: jgvdthree@gmail.com
|
127
|
+
executables: []
|
128
|
+
extensions: []
|
129
|
+
extra_rdoc_files: []
|
130
|
+
files:
|
131
|
+
- LICENSE
|
132
|
+
- README.md
|
133
|
+
- lib/fastlane/plugin/patch.rb
|
134
|
+
- lib/fastlane/plugin/patch/actions/apply_patch_action.rb
|
135
|
+
- lib/fastlane/plugin/patch/actions/revert_patch_action.rb
|
136
|
+
- lib/fastlane/plugin/patch/helper/patch_helper.rb
|
137
|
+
- lib/fastlane/plugin/patch/version.rb
|
138
|
+
homepage: https://github.com/jdee/fastlane-plugin-patch
|
139
|
+
licenses:
|
140
|
+
- MIT
|
141
|
+
metadata: {}
|
142
|
+
post_install_message:
|
143
|
+
rdoc_options: []
|
144
|
+
require_paths:
|
145
|
+
- lib
|
146
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
147
|
+
requirements:
|
148
|
+
- - ">="
|
149
|
+
- !ruby/object:Gem::Version
|
150
|
+
version: '0'
|
151
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
152
|
+
requirements:
|
153
|
+
- - ">="
|
154
|
+
- !ruby/object:Gem::Version
|
155
|
+
version: '0'
|
156
|
+
requirements: []
|
157
|
+
rubyforge_project:
|
158
|
+
rubygems_version: 2.6.12
|
159
|
+
signing_key:
|
160
|
+
specification_version: 4
|
161
|
+
summary: Apply and revert pattern-based patches to any text file.
|
162
|
+
test_files: []
|
163
|
+
has_rdoc:
|