Sha256: 617398ca59467bead042fce7b54b13127b6981c1fc563db840385a292df77eb8

Contents?: true

Size: 1.79 KB

Versions: 70

Compression:

Stored size: 1.79 KB

Contents

require 'fileutils'
require 'forwardable'

Dir[File.join(Dir.pwd, 'tasks', '**', '*.rb')].each { |f| require f }

module Distribution
  class Package
    extend Forwardable
    include PackageHelpers

    attr_reader :config, :dir, :tarball, :package, :arch, :root

    def_delegators :@config, :version, :rb_version, :package_name,
                   :packaging_dir, :native_extensions

    def initialize(arch)
      abort 'Ruby 2.1.x required' if RUBY_VERSION !~ /^2\.1\./

      @arch = arch
      @config = ::Distribution.configuration
      @dir = "#{package_name}-#{version}-#{arch}"
      @package = self
      @root = File.expand_path '.'
    end

    def self.create(args)
      new(*args).build
    end

    def build
      initialize_install_dir
      copy_brief
      install_ruby_and_gems
      create_executable
      post_cleanup
      @tarball = create_tarball
      clean_dir
    end

    private

    def clean_dir
      FileUtils.cd root do
        FileUtils.remove_dir(dir, true) if Dir.exist? dir
      end
    end

    def post_cleanup
      print_to_console 'Cleaning up...'

      files = ["#{packaging_dir}/traveling-ruby-#{rb_version}-#{arch}.tar.gz"]

      files.each { |file| FileUtils.rm file if File.exist? file }
    end

    def create_tarball
      Tarball.new self
    end

    def create_executable
      Executable.create self
    end

    def install_ruby_and_gems
      TravellingRuby.install self
    end

    def initialize_install_dir
      clean_dir

      FileUtils.cd root do
        FileUtils.mkdir_p "#{dir}/lib/app"
      end
    end

    def copy_brief
      print_to_console 'Copying brief...'

      %w(brief.gemspec Gemfile Gemfile.lock lib assets apps bin)
        .each do |folder|
        FileUtils.cp_r File.join(root, folder), "#{dir}/lib/app"
      end
    end
  end
end

Version data entries

70 entries across 70 versions & 1 rubygems

Version Path
brief-1.17.14 tasks/distribution/package.rb
brief-1.17.13 tasks/distribution/package.rb
brief-1.17.12 tasks/distribution/package.rb
brief-1.17.11 tasks/distribution/package.rb
brief-1.17.10 tasks/distribution/package.rb
brief-1.17.9 tasks/distribution/package.rb
brief-1.17.8 tasks/distribution/package.rb
brief-1.17.7 tasks/distribution/package.rb
brief-1.17.5 tasks/distribution/package.rb
brief-1.17.4 tasks/distribution/package.rb
brief-1.17.3 tasks/distribution/package.rb
brief-1.17.2 tasks/distribution/package.rb
brief-1.17.1 tasks/distribution/package.rb
brief-1.17.0 tasks/distribution/package.rb
brief-1.16.2 tasks/distribution/package.rb
brief-1.16.1 tasks/distribution/package.rb
brief-1.16.0 tasks/distribution/package.rb
brief-1.15.5 tasks/distribution/package.rb
brief-1.15.4 tasks/distribution/package.rb
brief-1.15.3 tasks/distribution/package.rb