Class: Fastlane::Actions::ReplaceFileAction

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

Class Method Summary collapse

Class Method Details

.authorsObject



32
33
34
# File 'lib/fastlane/plugin/rearchive/actions/replace_file_action.rb', line 32

def self.authors
  ["naoigcat"]
end

.available_optionsObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/fastlane/plugin/rearchive/actions/replace_file_action.rb', line 36

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :archive_path,
                         description: "The path of the .ipa or .xcarchive to be modified",
                            optional: false,
                                type: String),

    FastlaneCore::ConfigItem.new(key: :files,
                         description: "Files that should be replaced",
                            optional: false,
                                type: Hash)
  ]
end

.descriptionObject



28
29
30
# File 'lib/fastlane/plugin/rearchive/actions/replace_file_action.rb', line 28

def self.description
  "Replace files inside .ipa/.xcarchive"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/fastlane/plugin/rearchive/actions/replace_file_action.rb', line 50

def self.is_supported?(platform)
  [:ios].include?(platform)
end

.run(params) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/fastlane/plugin/rearchive/actions/replace_file_action.rb', line 9

def self.run(params)
  archive_path = File.expand_path(params[:archive_path])
  raise "Archive path #{archive_path} does not exist" unless File.exist?(archive_path)

  if File.directory?(archive_path)
    archive = RearchiveHelper::XCArchive.new(archive_path)
  else
    archive = RearchiveHelper::IPAArchive.new(archive_path)
  end
  params[:files].each do |old_file, new_file|
    FastlaneCore::UI.message("Replacing #{old_file}")
    relative_path = archive.app_path(old_file)
    local_path = archive.local_path(relative_path)
    system("mkdir -p #{File.dirname(local_path).shellescape}", exception: true)
    system("cp #{new_file.shellescape} #{local_path.shellescape}", exception: true)
    archive.replace(relative_path)
  end
end