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



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

def self.author
  "Piotrek Dubiel"
end

.available_optionsObject



49
50
51
52
53
54
55
56
57
# File 'lib/fastlane/plugin/polidea/actions/add_prefix_schema.rb', line 49

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



45
46
47
# File 'lib/fastlane/plugin/polidea/actions/add_prefix_schema.rb', line 45

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

.generate_url_schemeObject



27
28
29
# File 'lib/fastlane/plugin/polidea/actions/add_prefix_schema.rb', line 27

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

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/fastlane/plugin/polidea/actions/add_prefix_schema.rb', line 69

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

.modify_plist(info_plist_path, command) ⇒ Object



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

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

.outputObject



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

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
23
24
25
# File 'lib/fastlane/plugin/polidea/actions/add_prefix_schema.rb', line 10

def self.run(config)
  Fastlane::Polidea.session.action_launched("add_prefix_schema", 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

  Fastlane::Polidea.session.action_completed("add_prefix_schema")
  prefix_schema
end

.update_plist(info_plist_path, prefix_schema) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/fastlane/plugin/polidea/actions/add_prefix_schema.rb', line 31

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