Sha256: 75e48edb3060566664356b8b3d92d45ef109c32ce74ddba368161bb9466307ed

Contents?: true

Size: 1.45 KB

Versions: 3

Compression:

Stored size: 1.45 KB

Contents

require 'rubygems/gem_runner'
require 'berkeley_library/av/core/module_info'

gem_root_module = BerkeleyLibrary::AV::Core

class << gem_root_module
  def project_root
    @project_root ||= File.expand_path('..', __dir__)
  end

  def artifacts_dir
    return project_root unless ENV['CI']

    @artifacts_dir ||= File.join(project_root, 'artifacts')
  end

  def gemspec_file
    @gemspec_file ||= begin
      gemspec_files = Dir.glob(File.expand_path('*.gemspec', project_root))
      raise ArgumentError, "Too many .gemspecs: #{gemspec_files.join(', ')}" if gemspec_files.size > 1
      raise ArgumentError, 'No .gemspec file found' if gemspec_files.empty?

      gemspec_files[0]
    end
  end

  def gemspec_basename
    File.basename(gemspec_file)
  end

  def output_file
    @output_file ||= begin
      gem_name = self::ModuleInfo::NAME
      version = self::ModuleInfo::VERSION
      basename = "#{gem_name}-#{version}.gem"
      File.join(artifacts_dir, basename)
    end
  end

  def output_file_relative
    return File.basename(output_file) unless ENV['CI']

    @output_file_relative ||= begin
      artifacts_dir_relative = File.basename(artifacts_dir)
      File.join(artifacts_dir_relative, File.basename(output_file))
    end
  end
end

desc "Build #{gem_root_module.gemspec_basename} as #{gem_root_module.output_file_relative}"
task :gem do
  args = ['build', gem_root_module.gemspec_file, "--output=#{gem_root_module.output_file}"]
  Gem::GemRunner.new.run(args)
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
berkeley_library-av-core-0.4.2 rakelib/gem.rake
berkeley_library-av-core-0.4.1 rakelib/gem.rake
berkeley_library-av-core-0.4.0 rakelib/gem.rake