Sha256: fdd5f5e6d1a29fae546eea891c21ae70227e67547da26abba71500528cdc7e31

Contents?: true

Size: 1.6 KB

Versions: 40

Compression:

Stored size: 1.6 KB

Contents

# frozen_string_literal: true
module ThemeCheck
  class Packager
    ROOT = File.expand_path('../../..', __FILE__)
    PACKAGING_DIR = File.join(ROOT, 'packaging')
    BUILDS_DIR = File.join(PACKAGING_DIR, 'builds', ThemeCheck::VERSION)

    def initialize
      FileUtils.mkdir_p(BUILDS_DIR)
    end

    def build_homebrew
      root_dir = File.join(PACKAGING_DIR, 'homebrew')

      build_path = File.join(BUILDS_DIR, "theme-check.rb")
      puts "\nBuilding Homebrew package"

      puts "Generating formula..."
      File.delete(build_path) if File.exist?(build_path)

      spec_contents = File.read(File.join(root_dir, 'theme_check.base.rb'))
      spec_contents = spec_contents.gsub('THEME_CHECK_VERSION', ThemeCheck::VERSION)

      puts "Grabbing sha256 checksum from Rubygems.org"
      require 'digest/sha2'
      require 'open-uri'
      gem_checksum = URI.open("https://rubygems.org/downloads/theme-check-#{ThemeCheck::VERSION}.gem") do |io|
        Digest::SHA256.new.hexdigest(io.read)
      end

      puts "Got sha256 checksum for gem: #{gem_checksum}"
      spec_contents = spec_contents.gsub('THEME_CHECK_GEM_CHECKSUM', gem_checksum)

      puts "Writing generated formula\n  To: #{build_path}\n\n"
      File.write(build_path, spec_contents)
    end

    private

    def ensure_program_installed(program, installation_cmd)
      unless system(program, '--version', out: File::NULL, err: File::NULL)
        raise <<~MESSAGE

          Could not find program #{program} which is required to build the package.
          You can install it by running `#{installation_cmd}`.

        MESSAGE
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 1 rubygems

Version Path
theme-check-1.15.0 lib/theme_check/packager.rb
theme-check-1.14.0 lib/theme_check/packager.rb
theme-check-1.13.0 lib/theme_check/packager.rb
theme-check-1.12.1 lib/theme_check/packager.rb
theme-check-1.12.0 lib/theme_check/packager.rb
theme-check-1.11.0 lib/theme_check/packager.rb
theme-check-1.10.3 lib/theme_check/packager.rb
theme-check-1.10.2 lib/theme_check/packager.rb
theme-check-1.10.1 lib/theme_check/packager.rb
theme-check-1.10.0 lib/theme_check/packager.rb
theme-check-1.9.2 lib/theme_check/packager.rb
theme-check-1.9.1 lib/theme_check/packager.rb
theme-check-1.9.0 lib/theme_check/packager.rb
theme-check-1.8.0 lib/theme_check/packager.rb
theme-check-1.7.2 lib/theme_check/packager.rb
theme-check-1.7.1 lib/theme_check/packager.rb
theme-check-1.7.0 lib/theme_check/packager.rb
theme-check-1.6.2 lib/theme_check/packager.rb
theme-check-1.6.1 lib/theme_check/packager.rb
theme-check-1.6.0 lib/theme_check/packager.rb