Class: ShopifyCLI::Services::App::Deploy::Heroku::NodeService

Inherits:
BaseService
  • Object
show all
Defined in:
lib/shopify_cli/services/app/deploy/heroku/node_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BaseService

call

Constructor Details

#initialize(context:) ⇒ NodeService

Returns a new instance of NodeService.



9
10
11
12
# File 'lib/shopify_cli/services/app/deploy/heroku/node_service.rb', line 9

def initialize(context:)
  @context = context
  super()
end

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



7
8
9
# File 'lib/shopify_cli/services/app/deploy/heroku/node_service.rb', line 7

def context
  @context
end

Instance Method Details

#callObject



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
41
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
68
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
94
95
# File 'lib/shopify_cli/services/app/deploy/heroku/node_service.rb', line 14

def call
  spin_group = CLI::UI::SpinGroup.new
  heroku_service = ShopifyCLI::Heroku.new(context)

  spin_group.add(context.message("core.app.deploy.heroku.downloading")) do |spinner|
    heroku_service.download
    spinner.update_title(context.message("core.app.deploy.heroku.downloaded"))
  end
  spin_group.wait

  install_message = context.message(
    context.windows? ? "core.app.deploy.heroku.installing_windows" : "core.app.deploy.heroku.installing"
  )
  spin_group.add(install_message) do |spinner|
    heroku_service.install
    spinner.update_title(context.message("core.app.deploy.heroku.installed"))
  end
  spin_group.wait

  spin_group.add(context.message("core.app.deploy.heroku.git.checking")) do |spinner|
    ShopifyCLI::Git.init(context)
    spinner.update_title(context.message("core.app.deploy.heroku.git.initialized"))
  end
  spin_group.wait

  if ( = heroku_service.whoami)
    context.puts(context.message("core.app.deploy.heroku.authenticated_with_account", ))
  else
    CLI::UI::Frame.open(
      context.message("core.app.deploy.heroku.authenticating"),
      success_text: context.message("core.app.deploy.heroku.authenticated")
    ) do
      heroku_service.authenticate
    end
  end

  if (app_name = heroku_service.app)
    context.puts(context.message("core.app.deploy.heroku.app.selected", app_name))
  else
    app_type = CLI::UI::Prompt.ask(context.message("core.app.deploy.heroku.app.no_apps_found")) do |handler|
      handler.option(context.message("core.app.deploy.heroku.app.create")) { :new }
      handler.option(context.message("core.app.deploy.heroku.app.select")) { :existing }
    end

    if app_type == :existing
      app_name = CLI::UI::Prompt.ask(context.message("core.app.deploy.heroku.app.name"))
      CLI::UI::Frame.open(
        context.message("core.app.deploy.heroku.app.selecting", app_name),
        success_text: context.message("core.app.deploy.heroku.app.selected", app_name)
      ) do
        heroku_service.select_existing_app(app_name)
      end
    elsif app_type == :new
      CLI::UI::Frame.open(
        context.message("core.app.deploy.heroku.app.creating"),
        success_text: context.message("core.app.deploy.heroku.app.created")
      ) do
        heroku_service.create_new_app
      end
    end
  end

  branches = ShopifyCLI::Git.branches(context)
  if branches.length == 1
    branch_to_deploy = branches[0]
    context.puts(context.message("core.app.deploy.heroku.git.branch_selected", branch_to_deploy))
  else
    prompt_question = context.message("core.app.deploy.heroku.git.what_branch")
    branch_to_deploy = CLI::UI::Prompt.ask(prompt_question) do |handler|
      branches.each do |branch|
        handler.option(branch) { branch }
      end
    end
  end

  CLI::UI::Frame.open(
    context.message("core.app.deploy.heroku.deploying"),
    success_text: context.message("core.app.deploy.heroku.deployed")
  ) do
    heroku_service.deploy(branch_to_deploy)
  end
end