Sha256: 46b4a2fab461f54c28c1dbc8172e6b6bd6286453b3ccb631d540eef4caa71716

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

require_relative "base"
require_relative "fetcher"
require_relative "pusher"

module PodPrebuild
  class CachePrebuilder < CommandExecutor
    def initialize(options)
      super(options)
      @cache_branch = options[:cache_branch]
      @push_cache = options[:push_cache]
      @fetcher = PodPrebuild::CacheFetcher.new(options)
      @pusher = PodPrebuild::CachePusher.new(options)
    end

    def run
      @fetcher.run
      prebuild
      changes = PodPrebuild::JSONFile.new(@config.delta_file_path)
      return if changes.empty?

      sync_cache(changes)
      @pusher.run if @push_cache
    end

    private

    def prebuild
      Pod::UI.step("Installation") do
        Pod::Command::Install.new(CLAide::ARGV.new([])).run
      end
    end

    def sync_cache(changes)
      Pod::UI.step("Syncing cache") do
        FileUtils.cp(@config.manifest_path, @config.manifest_path(in_cache: true))
        clean_cache(changes["deleted"])
        zip_to_cache(changes["updated"])
      end
    end

    def zip_to_cache(pods_to_update)
      pods_to_update.each do |pod|
        Pod::UI.puts "- Update cache: #{pod}"
        ZipUtils.zip(
          "#{@config.generated_frameworks_dir}/#{pod}",
          to_dir: @config.generated_frameworks_dir(in_cache: true)
        )
      end
    end

    def clean_cache(pods_to_delete)
      pods_to_delete.each do |pod|
        Pod::UI.puts "- Clean up cache: #{pod}"
        FileUtils.rm_rf("#{@config.generated_frameworks_dir(in_cache: true)}/#{pod}.zip")
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
cocoapods-binary-cache-0.1.1 lib/command/executor/prebuilder.rb