forked from penchef/fastlane-plugin-xml_editor
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ab2cee0
Showing
14 changed files
with
266 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
source 'https://rubygems.org' | ||
|
||
gemspec | ||
|
||
plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile') | ||
eval(File.read(plugins_path), binding) if File.exist?(plugins_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2017 Jonathan Ritchie <[email protected]> | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# xml_editor plugin | ||
|
||
[](https://rubygems.org/gems/fastlane-plugin-xml_editor) | ||
|
||
## Getting Started | ||
|
||
This project is a [fastlane](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-xml_editor`, add it to your project by running: | ||
|
||
```bash | ||
fastlane add_plugin xml_editor | ||
``` | ||
|
||
## About xml_editor | ||
|
||
Generic xml editor for iOS and Android projects. | ||
|
||
**Note to author:** Add a more detailed description about this plugin here. If your plugin contains multiple actions, make sure to mention them here. | ||
|
||
## Example | ||
|
||
Check out the [example `Fastfile`](fastlane/Fastfile) to see how to use this plugin. Try it by cloning the repo, running `fastlane install_plugins` and `bundle exec fastlane test`. | ||
|
||
**Note to author:** Please set up a sample project to make it easy for users to explore what your plugin does. Provide everything that is necessary to try out the plugin in this project (including a sample Xcode/Android project if necessary) | ||
|
||
## Run tests for this plugin | ||
|
||
To run both the tests, and code style validation, run | ||
|
||
``` | ||
rake | ||
``` | ||
|
||
To automatically fix many of the styling issues, use | ||
``` | ||
rubocop -a | ||
``` | ||
|
||
## Issues and Feedback | ||
|
||
For any other issues and feedback about this plugin, please submit it to this repository. | ||
|
||
## Troubleshooting | ||
|
||
If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide. | ||
|
||
## Using `fastlane` Plugins | ||
|
||
For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/). | ||
|
||
## About `fastlane` | ||
|
||
`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). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
require 'bundler/gem_tasks' | ||
|
||
require 'rspec/core/rake_task' | ||
RSpec::Core::RakeTask.new | ||
|
||
require 'rubocop/rake_task' | ||
RuboCop::RakeTask.new(:rubocop) | ||
|
||
task default: [:spec, :rubocop] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
test: | ||
override: | ||
- bundle exec rake | ||
machine: | ||
ruby: | ||
version: 2.2.4 | ||
# Enable xcode below if you need macOS | ||
# xcode: | ||
# version: "7.3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# coding: utf-8 | ||
lib = File.expand_path("../lib", __FILE__) | ||
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) | ||
require 'fastlane/plugin/xml_editor/version' | ||
|
||
Gem::Specification.new do |spec| | ||
spec.name = 'fastlane-plugin-xml_editor' | ||
spec.version = Fastlane::XmlEditor::VERSION | ||
spec.author = %q{Jonathan Ritchie} | ||
spec.email = %q{[email protected]} | ||
|
||
spec.summary = %q{Generic xml editor for iOS and Android projects.} | ||
# spec.homepage = "https://github.com/<GITHUB_USERNAME>/fastlane-plugin-xml_editor" | ||
spec.license = "MIT" | ||
|
||
spec.files = Dir["lib/**/*"] + %w(README.md LICENSE) | ||
spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) | ||
spec.require_paths = ['lib'] | ||
|
||
# Don't add a dependency to fastlane or fastlane_re | ||
# since this would cause a circular dependency | ||
|
||
# spec.add_dependency 'your-dependency', '~> 1.0.0' | ||
|
||
spec.add_development_dependency 'pry' | ||
spec.add_development_dependency 'bundler' | ||
spec.add_development_dependency 'rspec' | ||
spec.add_development_dependency 'rake' | ||
spec.add_development_dependency 'rubocop' | ||
spec.add_development_dependency 'fastlane', '>= 2.14.2' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
lane :test do | ||
xml_editor | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Autogenerated by fastlane |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
require 'fastlane/plugin/xml_editor/version' | ||
|
||
module Fastlane | ||
module XmlEditor | ||
# Return all .rb files inside the "actions" and "helper" directory | ||
def self.all_classes | ||
Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))] | ||
end | ||
end | ||
end | ||
|
||
# By default we want to import all available actions and helpers | ||
# A plugin can contain any number of actions and plugins | ||
Fastlane::XmlEditor.all_classes.each do |current| | ||
require current | ||
end |
82 changes: 82 additions & 0 deletions
82
lib/fastlane/plugin/xml_editor/actions/xml_editor_action.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
module Fastlane | ||
module Actions | ||
class XmlEditorAction < Action | ||
def self.run(params) | ||
require "plist" | ||
require "nokogiri" | ||
|
||
path_to_file = File.expand_path(params[:path_to_xml_file]) | ||
new_attribute_value = params[:new_value] | ||
xml_is_plist = params[:xml_is_plist] | ||
|
||
if xml_is_plist | ||
begin | ||
UI.message("Modifying key-value pair in plist file located at: #{path_to_file}") | ||
plist = Plist.parse_xml(path_to_file) | ||
plist[params[:plist_key]] = new_attribute_value | ||
new_plist = Plist::Emit.dump(plist) | ||
File.write(path_to_file, new_plist) | ||
rescue => exception | ||
UI.error(exception) | ||
UI.user_error!("Unable to set value to plist file at '#{path_to_file}'") | ||
end | ||
UI.success("Plist value changed for key: #{params[:plist_key]}") | ||
else | ||
xml_search_path = params[:xml_path] | ||
@doc = Nokogiri::XML(File.open(path_to_file)) | ||
element_root = @doc.at_xpath(xml_search_path).content = new_attribute_value | ||
File.write(path_to_file, @doc.to_xml) | ||
UI.success("XML element value successfully changed!") | ||
end | ||
end | ||
|
||
def self.description | ||
"Generic XML file editor" | ||
end | ||
|
||
def self.authors | ||
["Jonathan Ritchie"] | ||
end | ||
|
||
def self.details | ||
"This plugin allows you to modify any element of a standard XML document or plist file" | ||
end | ||
|
||
def self.available_options | ||
[ | ||
FastlaneCore::ConfigItem.new(key: :path_to_xml_file, | ||
env_name: "PATH_TO_XML_FILE", | ||
description: "The path to the XML file in your project", | ||
optional: false, | ||
type: String), | ||
FastlaneCore::ConfigItem.new(key: :xml_path, | ||
env_name: "XML_PATH", | ||
description: "The xmlpath to the XML element that will be modified", | ||
optional: true, | ||
type: String), | ||
FastlaneCore::ConfigItem.new(key: :new_value, | ||
env_name: "NEW_VALUE", | ||
description: "The new XML attribute value which will be inserted into the XML file", | ||
optional: false, | ||
type: String), | ||
FastlaneCore::ConfigItem.new(key: :xml_is_plist, | ||
env_name: "XML_IS_PLIST", | ||
description: "Flag indicating if the specified XML file is a plist file", | ||
is_string: false, | ||
optional: false, | ||
default_value: false), | ||
FastlaneCore::ConfigItem.new(key: :plist_key, | ||
env_name: "PLIST_KEY", | ||
description: "Key in the specified property list that will have it's value modified", | ||
optional: true, | ||
type: String) | ||
] | ||
end | ||
|
||
def self.is_supported?(platform) | ||
[:ios, :mac, :android].include?(platform) | ||
true | ||
end | ||
end | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
lib/fastlane/plugin/xml_editor/helper/xml_editor_helper.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Fastlane | ||
module Helper | ||
class XmlEditorHelper | ||
# class methods that you define here become available in your action | ||
# as `Helper::XmlEditorHelper.your_method` | ||
# | ||
def self.show_message | ||
UI.message("Hello from the xml_editor plugin helper!") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module Fastlane | ||
module XmlEditor | ||
VERSION = "0.1.0" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) | ||
|
||
# This module is only used to check the environment is currently a testing env | ||
module SpecHelper | ||
end | ||
|
||
require 'fastlane' # to import the Action super class | ||
require 'fastlane/plugin/xml_editor' # import the actual plugin | ||
|
||
Fastlane.load_actions # load other actions (in case your plugin calls other actions or shared values) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
describe Fastlane::Actions::XmlEditorAction do | ||
describe '#run' do | ||
it 'prints a message' do | ||
expect(Fastlane::UI).to receive(:message).with("The xml_editor plugin is working!") | ||
|
||
Fastlane::Actions::XmlEditorAction.run(nil) | ||
end | ||
end | ||
end |