fastlane-plugin-plist_surgeon 0.1.0 → 0.1.2

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: 9a5bd9c8099f25d525594f7152adcfadfa2376e6be3beaade87899ad526d9609
4
- data.tar.gz: c1459ef6a8ac23c538a4147e62b6bb89a1fa121e4e4c512bae56bef68963a63d
3
+ metadata.gz: 8a4c842111d0642840d28e07781a460e50c2391ece4591051efea52033861617
4
+ data.tar.gz: f6065508091457bee57180beb14181b688771f0f16c6198fa9723226c001b3d2
5
5
  SHA512:
6
- metadata.gz: 189d851c3a93be5cca4cc4c8c68eebc27469d47aa1ad124484602b29b26c39718106d3b79ef58cd22b03fffb1f3bf15fac38ef962abb5e64dba074eeb19f8ca1
7
- data.tar.gz: e80a97936aeff2105af0f323bb710b7a3359b0b8c7d2ecec91a4cc2ee13f8906fef1ed3fbb6e16bd4f22b459e15314dd72898688e049f55c6e5eea1076ba8f5b
6
+ metadata.gz: d94f7e8ac67bfa10333845e5dc07694dd741c1f22f5d8729218d52517a3e4cee8cd9a00a2c7fb106f760db685f350fbc0418958ff8a802ca6397c02b21548f17
7
+ data.tar.gz: 3e14d8221bf389634e6352d5be9a257eeeabf8d9aa7b318f901844840eb3f1f60899fc90d7e3e138818c930763b57593e958ac8cdcf223839324c6a38b802d32
data/README.md CHANGED
@@ -71,6 +71,17 @@ privacy_surgeon(
71
71
  | `key` | The key to update (supports dot notation for nested keys) | Yes | |
72
72
  | `value` | The value to set | Yes | |
73
73
 
74
+ ### Complex Values
75
+
76
+ You can set complex values (Arrays or Hashes) by passing a JSON string. This is especially useful when running from the command line.
77
+
78
+ ```bash
79
+ fastlane run plist_surgeon \
80
+ path:"Info.plist" \
81
+ key:"CFBundleIcons" \
82
+ value:'{"CFBundlePrimaryIcon":{"CFBundleIconFiles":["AppIcon"]}}'
83
+ ```
84
+
74
85
  ### Run tests for this plugin
75
86
 
76
87
  To run both the tests, and code style validation, run
@@ -19,17 +19,17 @@ module Fastlane
19
19
  def self.available_options
20
20
  [
21
21
  FastlaneCore::ConfigItem.new(key: :path,
22
- env_name: "ENTITLEMENTS_SURGEON_PATH",
22
+ env_name: "PLIST_SURGEON_ENTITLEMENTS_PATH",
23
23
  description: "The path to the entitlements file",
24
24
  optional: false,
25
25
  type: String),
26
26
  FastlaneCore::ConfigItem.new(key: :key,
27
- env_name: "ENTITLEMENTS_SURGEON_KEY",
27
+ env_name: "PLIST_SURGEON_ENTITLEMENTS_KEY",
28
28
  description: "The key to update (supports dot notation for nested keys)",
29
29
  optional: false,
30
30
  type: String),
31
31
  FastlaneCore::ConfigItem.new(key: :value,
32
- env_name: "ENTITLEMENTS_SURGEON_VALUE",
32
+ env_name: "PLIST_SURGEON_ENTITLEMENTS_VALUE",
33
33
  description: "The value to set",
34
34
  optional: false)
35
35
  ]
@@ -19,17 +19,17 @@ module Fastlane
19
19
  def self.available_options
20
20
  [
21
21
  FastlaneCore::ConfigItem.new(key: :path,
22
- env_name: "PLIST_SURGEON_PATH",
22
+ env_name: "PLIST_SURGEON_PLIST_PATH",
23
23
  description: "The path to the plist file",
24
24
  optional: false,
25
25
  type: String),
26
26
  FastlaneCore::ConfigItem.new(key: :key,
27
- env_name: "PLIST_SURGEON_KEY",
27
+ env_name: "PLIST_SURGEON_PLIST_KEY",
28
28
  description: "The key to update (supports dot notation for nested keys)",
29
29
  optional: false,
30
30
  type: String),
31
31
  FastlaneCore::ConfigItem.new(key: :value,
32
- env_name: "PLIST_SURGEON_VALUE",
32
+ env_name: "PLIST_SURGEON_PLIST_VALUE",
33
33
  description: "The value to set",
34
34
  optional: false)
35
35
  ]
@@ -19,17 +19,17 @@ module Fastlane
19
19
  def self.available_options
20
20
  [
21
21
  FastlaneCore::ConfigItem.new(key: :path,
22
- env_name: "PRIVACY_SURGEON_PATH",
22
+ env_name: "PLIST_SURGEON_PRIVACY_PATH",
23
23
  description: "The path to the xcprivacy file",
24
24
  optional: false,
25
25
  type: String),
26
26
  FastlaneCore::ConfigItem.new(key: :key,
27
- env_name: "PRIVACY_SURGEON_KEY",
27
+ env_name: "PLIST_SURGEON_PRIVACY_KEY",
28
28
  description: "The key to update (supports dot notation for nested keys)",
29
29
  optional: false,
30
30
  type: String),
31
31
  FastlaneCore::ConfigItem.new(key: :value,
32
- env_name: "PRIVACY_SURGEON_VALUE",
32
+ env_name: "PLIST_SURGEON_PRIVACY_VALUE",
33
33
  description: "The value to set",
34
34
  optional: false)
35
35
  ]
@@ -15,20 +15,69 @@ module Fastlane
15
15
  end
16
16
 
17
17
  set_value(plist, key, value)
18
-
19
- File.write(path, plist.to_plist)
18
+ plist_content = plist.to_plist
19
+ File.write(path, plist_content)
20
+ "#{File.basename(path)} saved with #{key} change."
20
21
  end
21
22
 
22
23
  def self.set_value(plist, key, value)
23
- if key.include?('.')
24
+ value = parse_json_if_needed(value)
25
+
26
+ if plist.kind_of?(Hash) && plist.key?(key)
27
+ plist[key] = value
28
+ elsif key.include?('.')
24
29
  set_nested_value(plist, key, value)
30
+ else
31
+ set_direct_value(plist, key, value)
32
+ end
33
+ end
34
+
35
+ def self.set_direct_value(plist, key, value)
36
+ if plist.kind_of?(Array)
37
+ plist[key.to_i] = value
25
38
  else
26
39
  plist[key] = value
27
40
  end
28
41
  end
29
42
 
43
+ def self.parse_json_if_needed(value)
44
+ if value.kind_of?(String) && value.start_with?('{', '[')
45
+ begin
46
+ require 'json'
47
+ return JSON.parse(value)
48
+ rescue JSON::ParserError
49
+ # Not JSON, keep as string
50
+ end
51
+ end
52
+ value
53
+ end
54
+
30
55
  def self.set_nested_value(plist, key, value)
31
- keys = key.split('.')
56
+ # Attempt to find if any prefix of the key exists as a literal key
57
+ parts = key.split('.')
58
+ prefix_key = find_prefix_key(plist, parts)
59
+
60
+ if prefix_key
61
+ prefix, remainder = prefix_key
62
+ set_value(plist[prefix], remainder, value)
63
+ else
64
+ set_deep_nested_value(plist, parts, value)
65
+ end
66
+ end
67
+
68
+ def self.find_prefix_key(plist, parts)
69
+ return nil unless plist.kind_of?(Hash)
70
+
71
+ (parts.size - 1).downto(1) do |i|
72
+ prefix = parts[0...i].join('.')
73
+ if plist.key?(prefix)
74
+ return [prefix, parts[i..-1].join('.')]
75
+ end
76
+ end
77
+ nil
78
+ end
79
+
80
+ def self.set_deep_nested_value(plist, keys, value)
32
81
  last_key = keys.pop
33
82
  current = plist
34
83
  keys.each do |k|
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module PlistSurgeon
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-plist_surgeon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sourcetoad