Class: ShopifyCLI::Packager
- Inherits:
-
Object
- Object
- ShopifyCLI::Packager
- Defined in:
- lib/shopify_cli/packager.rb
Constant Summary collapse
- PACKAGING_DIR =
File.join(ShopifyCLI::ROOT, "packaging")
- BUILDS_DIR =
File.join(PACKAGING_DIR, "builds", ShopifyCLI::VERSION)
Instance Method Summary collapse
- #build_debian ⇒ Object
- #build_homebrew ⇒ Object
- #build_rpm ⇒ Object
-
#initialize ⇒ Packager
constructor
A new instance of Packager.
Constructor Details
#initialize ⇒ Packager
Returns a new instance of Packager.
6 7 8 |
# File 'lib/shopify_cli/packager.rb', line 6 def initialize FileUtils.mkdir_p(BUILDS_DIR) end |
Instance Method Details
#build_debian ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/shopify_cli/packager.rb', line 10 def build_debian ensure_program_installed("dpkg-deb", "brew install dpkg") root_dir = File.join(PACKAGING_DIR, "debian") debian_dir = File.join(root_dir, "shopify-cli", "DEBIAN") FileUtils.mkdir_p(debian_dir) puts "\nBuilding Debian package" puts "Generating metadata files…" Dir.glob("#{debian_dir}/*").each { |file| File.delete(file) } = %w(control preinst prerm) .each do |file| file_path = File.join(debian_dir, file) file_contents = File.read(File.join(root_dir, "#{file}.base")) file_contents = file_contents.gsub("SHOPIFY_CLI_VERSION", ShopifyCLI::VERSION) File.open(file_path, "w", 0775) { |f| f.write(file_contents) } end puts "Building package…" Dir.chdir(root_dir) raise "Failed to build package" unless system("dpkg-deb", "-b", "shopify-cli") output_path = File.join(root_dir, "shopify-cli.deb") final_path = File.join(BUILDS_DIR, "shopify-cli-#{ShopifyCLI::VERSION}.deb") puts "Moving generated package: \n From: #{output_path}\n To: #{final_path}\n\n" FileUtils.mv(output_path, final_path) end |
#build_homebrew ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/shopify_cli/packager.rb', line 69 def build_homebrew root_dir = File.join(PACKAGING_DIR, "homebrew") build_path = File.join(BUILDS_DIR, "[email protected]") puts "\nBuilding Homebrew package" puts "Generating formula…" File.delete(build_path) if File.exist?(build_path) spec_contents = File.read(File.join(root_dir, "[email protected]")) spec_contents = spec_contents.gsub("SHOPIFY_CLI_VERSION", ShopifyCLI::VERSION) puts "Grabbing sha256 checksum from Rubygems.org" require "digest/sha2" require "open-uri" gem_checksum = URI.open("https://rubygems.org/downloads/shopify-cli-#{ShopifyCLI::VERSION}.gem") do |io| Digest::SHA256.new.hexdigest(io.read) end puts "Got sha256 checksum for gem: #{gem_checksum}" spec_contents = spec_contents.gsub("SHOPIFY_CLI_GEM_CHECKSUM", gem_checksum) puts "Writing generated formula\n To: #{build_path}\n\n" File.write(build_path, spec_contents) end |
#build_rpm ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/shopify_cli/packager.rb', line 42 def build_rpm ensure_program_installed("rpmbuild", "brew install rpm") root_dir = File.join(PACKAGING_DIR, "rpm") rpm_build_dir = File.join(root_dir, "build") FileUtils.mkdir_p(rpm_build_dir) spec_path = File.join(root_dir, "shopify-cli.spec") puts "\nBuilding RPM package" puts "Generating spec file…" File.delete(spec_path) if File.exist?(spec_path) spec_contents = File.read(File.join(root_dir, "shopify-cli.spec.base")) spec_contents = spec_contents.gsub("SHOPIFY_CLI_VERSION", ShopifyCLI::VERSION) File.write(spec_path, spec_contents) puts "Building package…" Dir.chdir(root_dir) system("rpmbuild", "-bb", File.basename(spec_path)) output_dir = File.join(root_dir, "build", "noarch") puts "Moving generated packages: \n From: #{output_dir}\n To: #{BUILDS_DIR}\n\n" FileUtils.mv(Dir.glob("#{output_dir}/*.rpm"), BUILDS_DIR) end |