Class: Fastlane::Actions::AddPrefixSchemaAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/polidea/actions/add_prefix_schema.rb

Class Method Summary collapse

Class Method Details

.authorObject



62
63
64
# File 'lib/fastlane/plugin/polidea/actions/add_prefix_schema.rb', line 62

def self.author
  "Piotrek Dubiel"
end

.available_optionsObject



46
47
48
49
50
51
52
53
54
# File 'lib/fastlane/plugin/polidea/actions/add_prefix_schema.rb', line 46

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :path,
                                 env_name: "",
                                 description: "Path where search for Info.plist begins",
                                 default_value: File.absolute_path("."),
                                 optional: true)
  ]
end

.descriptionObject



42
43
44
# File 'lib/fastlane/plugin/polidea/actions/add_prefix_schema.rb', line 42

def self.description
  "Add prefix schema for Polidea Store"
end

.generate_url_schemeObject



24
25
26
# File 'lib/fastlane/plugin/polidea/actions/add_prefix_schema.rb', line 24

def self.generate_url_scheme
  Base64.urlsafe_encode64(SecureRandom.hex)[0..11]
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/fastlane/plugin/polidea/actions/add_prefix_schema.rb', line 66

def self.is_supported?(platform)
  platform == :ios
end

.modify_plist(info_plist_path, command) ⇒ Object



38
39
40
# File 'lib/fastlane/plugin/polidea/actions/add_prefix_schema.rb', line 38

def self.modify_plist(info_plist_path, command)
  system "/usr/libexec/PlistBuddy -c \"#{command}\" \"#{info_plist_path}\""
end

.outputObject



56
57
58
59
60
# File 'lib/fastlane/plugin/polidea/actions/add_prefix_schema.rb', line 56

def self.output
  [
    ['PREFIX_SCHEMA', 'Prefix schema added to Info.plist']
  ]
end

.run(config) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fastlane/plugin/polidea/actions/add_prefix_schema.rb', line 10

def self.run(config)
  prefix_schema = generate_url_scheme

  info_plists = Dir.glob(File.join(config[:path], "**/*.plist"))
  UI.user_error!("There isn't any Info.plist in this directory") if info_plists.empty?
  info_plists.each do |info_plist|
    update_plist(info_plist, prefix_schema)
  end

  Actions.lane_context[SharedValues::PREFIX_SCHEMA] = prefix_schema

  prefix_schema
end

.update_plist(info_plist_path, prefix_schema) ⇒ Object



28
29
30
31
32
33
34
35
36
# File 'lib/fastlane/plugin/polidea/actions/add_prefix_schema.rb', line 28

def self.update_plist(info_plist_path, prefix_schema)
  modify_plist(info_plist_path, "Add :CFBundleURLTypes array")
  modify_plist(info_plist_path, "Add :CFBundleURLTypes:0 dict")
  modify_plist(info_plist_path, "Add :CFBundleURLTypes:0:CFBundleURLName string 'com.polideastore.\\$(PRODUCT_NAME)'")
  modify_plist(info_plist_path, "Add :CFBundleURLTypes:0:CFBundleURLSchemes array")
  modify_plist(info_plist_path, "Add :CFBundleURLTypes:0:CFBundleURLSchemes:0 string '#{prefix_schema}'")
  modify_plist(info_plist_path, "Save")
  UI.success("Added custom url scheme: #{prefix_schema} to plist file: #{info_plist_path}")
end