fastlane-plugin-json 0.1.2 → 1.1.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 +4 -4
- data/README.md +78 -7
- data/lib/fastlane/plugin/json/actions/download_json_action.rb +3 -2
- data/lib/fastlane/plugin/json/actions/merge_jsons_action.rb +100 -0
- data/lib/fastlane/plugin/json/actions/read_json_action.rb +22 -9
- data/lib/fastlane/plugin/json/actions/write_json_action.rb +8 -14
- data/lib/fastlane/plugin/json/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 171f876162ae4aa8045970d6375243fcb2a4f05c8effb677806ca5634e3ca359
|
4
|
+
data.tar.gz: 499dea3eb82ee7cd6390260d13d0218eb347c467f9c6f0544b36aa5b8a12e0be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc2c2ac056904781c571dbdd3f5c92bc0d50d0f6d46556efd3e8d4491b5fb86148debee6400fbd7df3c9a26e1d8250e15588d193054e0cc0bba04e757b209ba9
|
7
|
+
data.tar.gz: 84c7f37783ee3933209c546ff64df6e08df0517879813c199895899fbb93a30d48c9067edfcb252fbad74ef7aa19cd0b7eb9ed61ed1e3b18d4826361386b52fe
|
data/README.md
CHANGED
@@ -1,6 +1,19 @@
|
|
1
|
-
# Fastlane Json plugin
|
2
|
-
|
3
|
-
[](https://rubygems.org/gems/fastlane-plugin-json)
|
1
|
+
# Fastlane Json plugin <!-- omit in toc -->
|
2
|
+
|
3
|
+
[](https://rubygems.org/gems/fastlane-plugin-json)   [](https://github.com/MartinGonzalez/fastlane-plugin-json/actions)
|
4
|
+
|
5
|
+
- [Getting Started](#getting-started)
|
6
|
+
- [Actions](#actions)
|
7
|
+
- [read_json](#read_json)
|
8
|
+
- [download_json](#download_json)
|
9
|
+
- [write_json](#write_json)
|
10
|
+
- [merge_jsons](#merge_jsons)
|
11
|
+
- [Example](#example)
|
12
|
+
- [Run tests for this plugin](#run-tests-for-this-plugin)
|
13
|
+
- [Issues and Feedback](#issues-and-feedback)
|
14
|
+
- [Troubleshooting](#troubleshooting)
|
15
|
+
- [Using _fastlane_ Plugins](#using-fastlane-plugins)
|
16
|
+
- [About _fastlane_](#about-fastlane)
|
4
17
|
|
5
18
|
## Getting Started
|
6
19
|
|
@@ -10,12 +23,17 @@ This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To
|
|
10
23
|
fastlane add_plugin json
|
11
24
|
```
|
12
25
|
|
13
|
-
##
|
26
|
+
## Actions
|
14
27
|
|
15
28
|
This plugin provide several actions that will allow you to manipulate and create json files.
|
16
29
|
|
17
30
|
### read_json
|
18
31
|
|
32
|
+
| Key | Description | Env Var | Default |
|
33
|
+
|-----------|-------------------|---------|---------|
|
34
|
+
| json_path | Path to json file | | |
|
35
|
+
| verbose | verbose | | false |
|
36
|
+
|
19
37
|
Read a json file at specific path as a hash object.
|
20
38
|
|
21
39
|
_Having a json file at `path/to/my.json` with the following content:_
|
@@ -40,6 +58,11 @@ puts my_json[:age]
|
|
40
58
|
|
41
59
|
### download_json
|
42
60
|
|
61
|
+
| Key | Description | Env Var | Default |
|
62
|
+
|-----------|-------------------|---------|---------|
|
63
|
+
| json_url | Url to json file | | |
|
64
|
+
| verbose | verbose | | false |
|
65
|
+
|
43
66
|
Downloads a json file from server and convert it to a hash object.
|
44
67
|
|
45
68
|
```ruby
|
@@ -57,6 +80,12 @@ puts my_json[:isDev]
|
|
57
80
|
|
58
81
|
### write_json
|
59
82
|
|
83
|
+
| Key | Description | Env Var | Default |
|
84
|
+
|-----------|-------------------------------------------|---------|---------|
|
85
|
+
| hash | Hash that you want to save as a json file | | |
|
86
|
+
| file_path | Path where you want to save your json | | |
|
87
|
+
| verbose | verbose | | false |
|
88
|
+
|
60
89
|
Creates a json file from a hash.
|
61
90
|
|
62
91
|
```ruby
|
@@ -88,11 +117,53 @@ Will create a my_json.json file with the following content:
|
|
88
117
|
}
|
89
118
|
```
|
90
119
|
|
91
|
-
|
120
|
+
### merge_jsons
|
121
|
+
|
122
|
+
| Key | Description | Env Var | Default |
|
123
|
+
|-------------|-------------------------------------------|---------|---------|
|
124
|
+
| jsons_paths | Array of json files paths | | |
|
125
|
+
| output_path | Output path where result will be saved | | |
|
126
|
+
| verbose | verbose | | false |
|
127
|
+
|
128
|
+
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.
|
129
|
+
|
130
|
+
Having this files:
|
131
|
+
|
132
|
+
`example.json`
|
133
|
+
```json
|
134
|
+
{
|
135
|
+
"name": "Martin",
|
136
|
+
"age": 30
|
137
|
+
}
|
138
|
+
```
|
92
139
|
|
93
|
-
|
140
|
+
`example2.json`
|
141
|
+
```json
|
142
|
+
{
|
143
|
+
"lastName": "Gonzalez",
|
144
|
+
"age": 40,
|
145
|
+
"isDev": true
|
146
|
+
}
|
147
|
+
```
|
148
|
+
|
149
|
+
```ruby
|
150
|
+
output_path = "#{__dir__}/tmp/merged.json"
|
151
|
+
|
152
|
+
merged_hash = merge_jsons(
|
153
|
+
jsons_paths: [
|
154
|
+
"path/to/example.json",
|
155
|
+
"path/to/example2.json"
|
156
|
+
],
|
157
|
+
output_path: output_path
|
158
|
+
)
|
159
|
+
|
160
|
+
# {:name=>"Martin", :age=>40, :lastName=>"Gonzalez", :isDev=>true}
|
161
|
+
```
|
162
|
+
|
163
|
+
|
164
|
+
## Example
|
94
165
|
|
95
|
-
|
166
|
+
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`.
|
96
167
|
|
97
168
|
## Run tests for this plugin
|
98
169
|
|
@@ -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
|
@@ -47,14 +48,14 @@ module Fastlane
|
|
47
48
|
FastlaneCore::ConfigItem.new(key: :verbose,
|
48
49
|
description: "verbose",
|
49
50
|
optional: true,
|
50
|
-
|
51
|
+
type: Boolean,
|
51
52
|
default_value: false)
|
52
53
|
|
53
54
|
]
|
54
55
|
end
|
55
56
|
|
56
57
|
def self.print_params(options)
|
57
|
-
table_title = "Params for
|
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
|
@@ -7,16 +7,27 @@ module Fastlane
|
|
7
7
|
class ReadJsonAction < Action
|
8
8
|
def self.run(params)
|
9
9
|
json_path = params[:json_path]
|
10
|
+
json_string = params[:json_string]
|
10
11
|
@is_verbose = params[:verbose]
|
11
12
|
|
13
|
+
if json_path.nil? && json_string.nil?
|
14
|
+
put_error!("You need to provide a json_path (file to path) or json_string (json as string) ❌")
|
15
|
+
return nil
|
16
|
+
end
|
17
|
+
|
12
18
|
print_params(params) if @is_verbose
|
13
19
|
|
14
|
-
|
15
|
-
|
16
|
-
|
20
|
+
json_content = json_string
|
21
|
+
|
22
|
+
unless json_path.nil?
|
23
|
+
unless File.file?(json_path)
|
24
|
+
put_error!("File at path #{json_path} does not exist. Verify that the path is correct ❌")
|
25
|
+
return nil
|
26
|
+
end
|
27
|
+
|
28
|
+
json_content = File.read(json_path)
|
17
29
|
end
|
18
30
|
|
19
|
-
json_content = File.read(json_path)
|
20
31
|
begin
|
21
32
|
JSON.parse(json_content, symbolize_names: true)
|
22
33
|
rescue
|
@@ -26,6 +37,7 @@ module Fastlane
|
|
26
37
|
|
27
38
|
def self.put_error!(message)
|
28
39
|
UI.user_error!(message)
|
40
|
+
raise StandardError, message
|
29
41
|
end
|
30
42
|
|
31
43
|
def self.description
|
@@ -41,14 +53,15 @@ module Fastlane
|
|
41
53
|
FastlaneCore::ConfigItem.new(key: :json_path,
|
42
54
|
description: "Path to json file",
|
43
55
|
is_string: true,
|
44
|
-
optional:
|
45
|
-
|
46
|
-
|
47
|
-
|
56
|
+
optional: true),
|
57
|
+
FastlaneCore::ConfigItem.new(key: :json_string,
|
58
|
+
description: "A json as string",
|
59
|
+
is_string: true,
|
60
|
+
optional: true),
|
48
61
|
FastlaneCore::ConfigItem.new(key: :verbose,
|
49
62
|
description: "verbose",
|
50
63
|
optional: true,
|
51
|
-
|
64
|
+
type: Boolean)
|
52
65
|
|
53
66
|
]
|
54
67
|
end
|
@@ -11,19 +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
|
-
|
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)
|
18
|
+
file_dir = File.dirname(file_path_expanded)
|
25
19
|
Dir.mkdir(file_dir) unless File.directory?(file_dir)
|
26
|
-
print_params(params) if @is_verbose
|
27
20
|
|
28
21
|
begin
|
29
22
|
File.open(file_path, "w") do |f|
|
@@ -36,6 +29,7 @@ module Fastlane
|
|
36
29
|
|
37
30
|
def self.put_error!(message)
|
38
31
|
UI.user_error!(message)
|
32
|
+
raise StandardError, message
|
39
33
|
end
|
40
34
|
|
41
35
|
def self.description
|
@@ -51,7 +45,7 @@ module Fastlane
|
|
51
45
|
FastlaneCore::ConfigItem.new(key: :hash,
|
52
46
|
description: "Hash that you want to save as a json file",
|
53
47
|
optional: false,
|
54
|
-
|
48
|
+
type: Hash,
|
55
49
|
verify_block: proc do |value|
|
56
50
|
UI.user_error!("You must set hash: parameter") unless value && !value.empty?
|
57
51
|
end),
|
@@ -60,12 +54,12 @@ module Fastlane
|
|
60
54
|
is_string: true,
|
61
55
|
optional: false,
|
62
56
|
verify_block: proc do |value|
|
63
|
-
UI.user_error!("You must set file_path: parameter") unless value.
|
57
|
+
UI.user_error!("You must set file_path: parameter") unless value && !value.empty?
|
64
58
|
end),
|
65
59
|
FastlaneCore::ConfigItem.new(key: :verbose,
|
66
60
|
description: "verbose",
|
67
61
|
optional: true,
|
68
|
-
|
62
|
+
type: Boolean)
|
69
63
|
]
|
70
64
|
end
|
71
65
|
|
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:
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Gonzalez
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pry
|
@@ -146,11 +146,12 @@ 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
|
152
153
|
- lib/fastlane/plugin/json/version.rb
|
153
|
-
homepage:
|
154
|
+
homepage: https://github.com/martingonzalez/fastlane-plugin-json
|
154
155
|
licenses:
|
155
156
|
- MIT
|
156
157
|
metadata: {}
|
@@ -169,7 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
170
|
- !ruby/object:Gem::Version
|
170
171
|
version: '0'
|
171
172
|
requirements: []
|
172
|
-
rubygems_version: 3.0.3
|
173
|
+
rubygems_version: 3.0.3.1
|
173
174
|
signing_key:
|
174
175
|
specification_version: 4
|
175
176
|
summary: actions related to json files
|