Sha256: a5bedbbec1a47650dd6735e16b7e14941407e745ad339bbb190d3063a9e56b63

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

module TerraspaceBundler
  class Exporter
    include TB::Mod::PathConcern
    include TB::Util::Logging

    def initialize(options={})
      @options = options
    end

    def run
      purge
      lockfile.mods.each do |mod|
        export(mod)
      end
    end

    def export(mod)
      downloader = Mod::Downloader.new(mod)
      downloader.switch_version(mod.sha)

      stage_path = stage_path(mod.full_repo)
      stage_path = "#{stage_path}/#{mod.subfolder}" if mod.subfolder
      mod_path = mod_path(mod)
      FileUtils.rm_rf(mod_path)
      FileUtils.mkdir_p(File.dirname(mod_path))
      FileUtils.cp_r(stage_path, mod_path)
      FileUtils.rm_rf("#{mod_path}/.git")
      logger.debug "Exported: #{mod_path}"
    end

    def mod_path(mod)
      name = mod.name
      export_to = mod.export_to || TB.config.export_path
      "#{export_to}/#{name}"
    end

  private
    def purge
      return unless TB.config.export_purge
      FileUtils.rm_rf(TB.config.export_path)
    end

    def lockfile
      Lockfile.instance
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
terraspace-bundler-0.2.0 lib/terraspace_bundler/exporter.rb