Class: Node::Commands::Serve

Inherits:
ShopifyCli::Command show all
Defined in:
lib/project_types/node/commands/serve.rb

Instance Attribute Summary

Attributes inherited from ShopifyCli::Command

#ctx, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ShopifyCli::Command

call, call_help, #initialize, options, prerequisite_task, run_prerequisites, subcommand, subcommand_registry

Methods included from ShopifyCli::Feature::Set

#hidden?, #hidden_feature

Constructor Details

This class inherits a constructor from ShopifyCli::Command

Class Method Details

.extended_helpObject



40
41
42
# File 'lib/project_types/node/commands/serve.rb', line 40

def self.extended_help
  ShopifyCli::Context.message('node.serve.extended_help')
end

.helpObject



36
37
38
# File 'lib/project_types/node/commands/serve.rb', line 36

def self.help
  ShopifyCli::Context.message('node.serve.help', ShopifyCli::TOOL_NAME)
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/project_types/node/commands/serve.rb', line 13

def call(*)
  project = ShopifyCli::Project.current
  url = options.flags[:host] || ShopifyCli::Tunnel.start(@ctx)
  @ctx.abort(@ctx.message('node.serve.error.host_must_be_https')) if url.match(/^https/i).nil?
  project.env.update(@ctx, :host, url)
  ShopifyCli::Tasks::UpdateDashboardURLS.call(
    @ctx,
    url: url,
    callback_url: "/auth/callback",
  )

  if project.env.shop
    project_url = "#{project.env.host}/auth?shop=#{project.env.shop}"
    @ctx.puts("\n" + @ctx.message('node.serve.open_info', project_url) + "\n")
  end

  CLI::UI::Frame.open(@ctx.message('node.serve.running_server')) do
    env = project.env.to_h
    env['PORT'] = ShopifyCli::Tunnel::PORT.to_s
    @ctx.system('npm run dev', env: env)
  end
end