Class: ShopifyCLI::Heroku
- Inherits:
-
Object
- Object
- ShopifyCLI::Heroku
- Defined in:
- lib/shopify_cli/heroku.rb
Constant Summary collapse
- DOWNLOAD_URLS =
{ linux: "https://cli-assets.heroku.com/heroku-linux-x64.tar.gz", mac: "https://cli-assets.heroku.com/heroku-darwin-x64.tar.gz", windows: "https://cli-assets.heroku.com/heroku-x64.exe", mac_m1: "https://cli-assets.heroku.com/heroku-darwin-x64.tar.gz", }
Instance Method Summary collapse
- #add_buildpacks(buildpacks) ⇒ Object
- #app ⇒ Object
- #authenticate ⇒ Object
- #create_new_app ⇒ Object
- #deploy(branch_to_deploy) ⇒ Object
- #download ⇒ Object
- #get_config(config) ⇒ Object
- #heroku_command ⇒ Object
-
#initialize(ctx) ⇒ Heroku
constructor
A new instance of Heroku.
- #install ⇒ Object
- #select_existing_app(app_name) ⇒ Object
- #set_config(config, value) ⇒ Object
- #whoami ⇒ Object
Constructor Details
#initialize(ctx) ⇒ Heroku
Returns a new instance of Heroku.
10 11 12 |
# File 'lib/shopify_cli/heroku.rb', line 10 def initialize(ctx) @ctx = ctx end |
Instance Method Details
#add_buildpacks(buildpacks) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/shopify_cli/heroku.rb', line 84 def add_buildpacks(buildpacks) result = @ctx.system(heroku_command, "buildpacks:clear") msg = @ctx.("core.heroku.error.add_buildpacks") @ctx.abort(msg) unless result.success? buildpacks.each do |buildpack| result = @ctx.system(heroku_command, "buildpacks:add", buildpack) msg = @ctx.("core.heroku.error.add_buildpacks") @ctx.abort(msg) unless result.success? end end |
#app ⇒ Object
14 15 16 17 18 19 |
# File 'lib/shopify_cli/heroku.rb', line 14 def app return nil unless (app = git_remote) app = app.split("/").last app = app.split(".").first app end |
#authenticate ⇒ Object
21 22 23 24 |
# File 'lib/shopify_cli/heroku.rb', line 21 def authenticate result = @ctx.system(heroku_command, "login") @ctx.abort(@ctx.("core.heroku.error.authentication")) unless result.success? end |
#create_new_app ⇒ Object
26 27 28 29 30 |
# File 'lib/shopify_cli/heroku.rb', line 26 def create_new_app output, status = @ctx.capture2e(heroku_command, "create") @ctx.abort(@ctx.("core.heroku.error.creation")) unless status.success? @ctx.puts(output) end |
#deploy(branch_to_deploy) ⇒ Object
32 33 34 35 |
# File 'lib/shopify_cli/heroku.rb', line 32 def deploy(branch_to_deploy) result = @ctx.system("git", "push", "-u", "heroku", "#{branch_to_deploy}:master") @ctx.abort(@ctx.("core.heroku.error.deploy")) unless result.success? end |
#download ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/shopify_cli/heroku.rb', line 37 def download return if installed? result = @ctx.system("curl", "-o", download_path, DOWNLOAD_URLS[@ctx.os], chdir: ShopifyCLI.cache_dir) @ctx.abort(@ctx.("core.heroku.error.download")) unless result.success? @ctx.abort(@ctx.("core.heroku.error.download")) unless File.exist?(download_path) end |
#get_config(config) ⇒ Object
71 72 73 74 75 |
# File 'lib/shopify_cli/heroku.rb', line 71 def get_config(config) output, status = @ctx.capture2e(heroku_command, "config:get", config.to_s) return output.strip if status.success? nil end |
#heroku_command ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/shopify_cli/heroku.rb', line 96 def heroku_command local_path = File.join(ShopifyCLI.cache_dir, "heroku", "bin", "heroku").to_s if File.exist?(local_path) local_path elsif @ctx.windows? begin # Check if Heroku exists in the Windows registry and run it from there require "win32/registry" windows_path = Win32::Registry::HKEY_CURRENT_USER.open('SOFTWARE\heroku') do |reg| reg[""] # This reads the 'Default' registry key end File.join(windows_path, "bin", "heroku").to_s rescue StandardError, LoadError "heroku" end else "heroku" end end |
#install ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/shopify_cli/heroku.rb', line 45 def install return if installed? result = if @ctx.windows? @ctx.system("\"#{download_path}\"") else @ctx.system("tar", "-xf", download_path, chdir: ShopifyCLI.cache_dir) end @ctx.abort(@ctx.("core.heroku.error.install")) unless result.success? @ctx.rm(download_path) end |
#select_existing_app(app_name) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/shopify_cli/heroku.rb', line 58 def select_existing_app(app_name) result = @ctx.system(heroku_command, "git:remote", "-a", app_name) msg = @ctx.("core.heroku.error.could_not_select_app", app_name) @ctx.abort(msg) unless result.success? end |
#set_config(config, value) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/shopify_cli/heroku.rb', line 77 def set_config(config, value) result = @ctx.system(heroku_command, "config:set", "#{config}=#{value}") msg = @ctx.("core.heroku.error.set_config", config, value) @ctx.abort(msg) unless result.success? end |
#whoami ⇒ Object
65 66 67 68 69 |
# File 'lib/shopify_cli/heroku.rb', line 65 def whoami output, status = @ctx.capture2e(heroku_command, "whoami") return output.strip if status.success? nil end |