fastlane-plugin-json 0.1.3 → 0.1.4

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
  SHA256:
3
- metadata.gz: 2dfcdb6a3044272e9451d59fef9f49a0ee8120ee9c0f790d15b7c15ddccdc08b
4
- data.tar.gz: c6576b58b55ba9c371355f78c7ed3c56bb2ce1f4502519c7d8dfe8064b36ea4b
3
+ metadata.gz: 8e5909b7bfad2af730c65240d5950b4c12d6b1ea8f7401253389168a3db91be7
4
+ data.tar.gz: e3c28f6c140c41647f3a0786d52331a5d52bf83eb760cd0b02de46e36c8db0f8
5
5
  SHA512:
6
- metadata.gz: 59fc9b843dbb0879a200c531aeac537d4c52277afa2b13b21653eb48c8d42dd8f18734c6ced32d9629cad4777df0b585ab0fa6b7b1b06f90c26331b8331ae748
7
- data.tar.gz: 7f6a36f21aba3af6675a6b676b254165640db476a14625ade18ee594aaf701f0bdd62d97e8fa0851252ad7f2ad42c47fa5b2bf5201c118d55f375a8c1e8fd51c
6
+ metadata.gz: b799ce4e3d0764eec789a46f3b5646dc4f4b8f3d7fba8a94fde0c0248d16d789010c5929fb778e2c53f7b0d9815110dda6de80e905bba2e1795f7e531d10ab94
7
+ data.tar.gz: 3b4a1d42f610efaffee8909fafc3d3a7463fb44638bc12d8f0caf95d5ed13977a90fdef04af2e16e0226fd8a88ac0e410e12d266c5f30ae3132789c7b1cbdcff
data/README.md CHANGED
@@ -1,7 +1,21 @@
1
- # Fastlane Json plugin
1
+ # Fastlane Json plugin <!-- omit in toc -->
2
2
 
3
3
  [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-json)
4
4
 
5
+
6
+ - [Getting Started](#getting-started)
7
+ - [Actions](#actions)
8
+ - [read_json](#read_json)
9
+ - [download_json](#download_json)
10
+ - [write_json](#write_json)
11
+ - [merge_jsons](#merge_jsons)
12
+ - [Example](#example)
13
+ - [Run tests for this plugin](#run-tests-for-this-plugin)
14
+ - [Issues and Feedback](#issues-and-feedback)
15
+ - [Troubleshooting](#troubleshooting)
16
+ - [Using _fastlane_ Plugins](#using-fastlane-plugins)
17
+ - [About _fastlane_](#about-fastlane)
18
+
5
19
  ## Getting Started
6
20
 
7
21
  This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-json`, add it to your project by running:
@@ -10,7 +24,7 @@ This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To
10
24
  fastlane add_plugin json
11
25
  ```
12
26
 
13
- ## About json
27
+ ## Actions
14
28
 
15
29
  This plugin provide several actions that will allow you to manipulate and create json files.
16
30
 
@@ -104,11 +118,53 @@ Will create a my_json.json file with the following content:
104
118
  }
105
119
  ```
106
120
 
107
- ## Example
121
+ ### merge_jsons
122
+
123
+ | Key | Description | Env Var | Default |
124
+ |-------------|-------------------------------------------|---------|---------|
125
+ | jsons_paths | Array of json files paths | | |
126
+ | output_path | Output path where result will be saved | | |
127
+ | verbose | verbose | | false |
128
+
129
+ Merges several json files into one hash as output. Also you can set the `output_path` to save the merged hash into a json file.
130
+
131
+ Having this files:
132
+
133
+ `example.json`
134
+ ```json
135
+ {
136
+ "name": "Martin",
137
+ "age": 30
138
+ }
139
+ ```
108
140
 
109
- 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`.
141
+ `example2.json`
142
+ ```json
143
+ {
144
+ "lastName": "Gonzalez",
145
+ "age": 40,
146
+ "isDev": true
147
+ }
148
+ ```
149
+
150
+ ```ruby
151
+ output_path = "#{__dir__}/tmp/merged.json"
152
+
153
+ merged_hash = merge_jsons(
154
+ jsons_paths: [
155
+ "path/to/example.json",
156
+ "path/to/example2.json"
157
+ ],
158
+ output_path: output_path
159
+ )
160
+
161
+ # {:name=>"Martin", :age=>40, :lastName=>"Gonzalez", :isDev=>true}
162
+ ```
163
+
164
+
165
+ ## Example
110
166
 
111
- **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)
167
+ 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 all`.
112
168
 
113
169
  ## Run tests for this plugin
114
170
 
@@ -25,6 +25,7 @@ module Fastlane
25
25
 
26
26
  def self.puts_error!(message)
27
27
  UI.user_error!(message)
28
+ raise StandardError, message
28
29
  end
29
30
 
30
31
  def self.description
@@ -54,7 +55,7 @@ module Fastlane
54
55
  end
55
56
 
56
57
  def self.print_params(options)
57
- table_title = "Params for read_json #{Fastlane::Json::VERSION}"
58
+ table_title = "Params for download_json #{Fastlane::Json::VERSION}"
58
59
  FastlaneCore::PrintTable.print_values(config: options,
59
60
  hide_keys: [],
60
61
  title: table_title)
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+
5
+ module Fastlane
6
+ module Actions
7
+ class MergeJsonsAction < Action
8
+ def self.run(params)
9
+ jsons_paths = params[:jsons_paths]
10
+ output_path = params[:output_path]
11
+ @is_verbose = params[:verbose]
12
+
13
+ print_params(params) if @is_verbose
14
+ put_error!("jsons_path cannot be empty ❌") if jsons_paths.empty?
15
+
16
+ hashes = jsons_paths.map do |json_path|
17
+ put_error!("json_path: #{json_path} is not valid ❌") unless File.exist?(json_path)
18
+ json_content = File.read(File.expand_path(json_path))
19
+ begin
20
+ JSON.parse(json_content, symbolize_names: true)
21
+ rescue
22
+ put_error!("File at path #{json_path} has invalid content. ❌")
23
+ end
24
+ end
25
+
26
+ merged_hash = hashes.reduce({}, :merge)
27
+
28
+ write_hash_at(output_path, merged_hash) unless output_path.to_s.empty?
29
+
30
+ merged_hash
31
+ end
32
+
33
+ def self.write_hash_at(output_path, hash)
34
+ file_path_expanded = File.expand_path(output_path)
35
+ file_dir = File.dirname(file_path_expanded)
36
+ Dir.mkdir(file_dir) unless File.directory?(file_dir)
37
+
38
+ begin
39
+ File.open(output_path, "w") { |f| f.write(JSON.pretty_generate(hash)) }
40
+ rescue
41
+ put_error!("Failed to write json at #{output_path}. ❌")
42
+ end
43
+ end
44
+
45
+ def self.put_error!(message)
46
+ UI.user_error!(message)
47
+ raise StandardError, message
48
+ end
49
+
50
+ def self.description
51
+ "Merge a group of jsons files and expose a hash with symbolized names as result. Last json predominate over the rest"
52
+ end
53
+
54
+ def self.details
55
+ "Use this action to merge jsons files and access to it as Hash with symbolized names. Also you can set the output_path to save the result"
56
+ end
57
+
58
+ def self.available_options
59
+ [
60
+ FastlaneCore::ConfigItem.new(key: :jsons_paths,
61
+ description: "Array of json files paths",
62
+ type: Array,
63
+ optional: false,
64
+ verify_block: proc do |value|
65
+ UI.user_error!("You must set jsons_paths") unless value && !value.empty?
66
+ end),
67
+ FastlaneCore::ConfigItem.new(key: :output_path,
68
+ description: "Output path where result will be saved",
69
+ type: String,
70
+ optional: true),
71
+ FastlaneCore::ConfigItem.new(key: :verbose,
72
+ description: "verbose",
73
+ optional: true,
74
+ default_value: false,
75
+ type: Boolean)
76
+
77
+ ]
78
+ end
79
+
80
+ def self.print_params(options)
81
+ table_title = "Params for merge_json #{Fastlane::Json::VERSION}"
82
+ FastlaneCore::PrintTable.print_values(config: options,
83
+ hide_keys: [],
84
+ title: table_title)
85
+ end
86
+
87
+ def self.return_value
88
+ "Hash"
89
+ end
90
+
91
+ def self.authors
92
+ ["Martin Gonzalez"]
93
+ end
94
+
95
+ def self.is_supported?(_platform)
96
+ true
97
+ end
98
+ end
99
+ end
100
+ end
@@ -26,6 +26,7 @@ module Fastlane
26
26
 
27
27
  def self.put_error!(message)
28
28
  UI.user_error!(message)
29
+ raise StandardError, message
29
30
  end
30
31
 
31
32
  def self.description
@@ -11,20 +11,12 @@ module Fastlane
11
11
  @is_verbose = params[:verbose]
12
12
  print_params(params) if @is_verbose
13
13
 
14
- if file_path.nil? || file_path.empty?
15
- put_error!("file_path: value cannot be nil or empty")
16
- return
17
- end
18
-
19
- if hash.nil?
20
- put_error!("hash: value cannot be nil")
21
- return
22
- end
14
+ put_error!("file_path: value cannot be nil or empty") if file_path.nil? || file_path.empty?
15
+ put_error!("hash: value cannot be nil") if hash.nil?
23
16
 
24
17
  file_path_expanded = File.expand_path(file_path)
25
18
  file_dir = File.dirname(file_path_expanded)
26
19
  Dir.mkdir(file_dir) unless File.directory?(file_dir)
27
- print_params(params) if @is_verbose
28
20
 
29
21
  begin
30
22
  File.open(file_path, "w") do |f|
@@ -37,6 +29,7 @@ module Fastlane
37
29
 
38
30
  def self.put_error!(message)
39
31
  UI.user_error!(message)
32
+ raise StandardError, message
40
33
  end
41
34
 
42
35
  def self.description
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module Json
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-json
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Martin Gonzalez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-20 00:00:00.000000000 Z
11
+ date: 2020-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -146,6 +146,7 @@ files:
146
146
  - README.md
147
147
  - lib/fastlane/plugin/json.rb
148
148
  - lib/fastlane/plugin/json/actions/download_json_action.rb
149
+ - lib/fastlane/plugin/json/actions/merge_jsons_action.rb
149
150
  - lib/fastlane/plugin/json/actions/read_json_action.rb
150
151
  - lib/fastlane/plugin/json/actions/write_json_action.rb
151
152
  - lib/fastlane/plugin/json/helper/json_helper.rb