Class: Extension::Command::Serve

Inherits:
ExtensionCommand show all
Defined in:
lib/project_types/extension/commands/serve.rb

Defined Under Namespace

Classes: RuntimeConfiguration

Constant Summary collapse

DEFAULT_PORT =
39351

Instance Attribute Summary

Attributes inherited from ShopifyCLI::Command

#ctx, #options

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ExtensionCommand

#specification_handler

Methods inherited from ShopifyCLI::Command::SubCommand

call

Methods inherited from ShopifyCLI::Command

call, call_help, check_node_version, check_ruby_version, check_version, #initialize, options, prerequisite_task, recommend_default_node_range, recommend_default_ruby_range, recommend_node, recommend_ruby, 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

.helpObject



83
84
85
# File 'lib/project_types/extension/commands/serve.rb', line 83

def self.help
  ShopifyCLI::Context.new.message("serve.help", ShopifyCLI::TOOL_NAME)
end

Instance Method Details

#call(args, _command_name) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/project_types/extension/commands/serve.rb', line 59

def call(args, _command_name)
  @ctx.root = args.first || @ctx.root

  config = RuntimeConfiguration.new(
    tunnel_requested: tunnel_requested?,
    resource_url: options.flags[:resource_url],
    port: options.flags[:port],
    theme: options.flags[:theme],
    generate_tmp_theme: generate_tmp_theme?,
    api_key: options.flags[:api_key],
    api_secret: options.flags[:api_secret],
    registration_id: options.flags[:registration_id],
    extension_title: options.flags[:extension_title],
    extension_type: options.flags[:extension_type],
  )

  ShopifyCLI::Result
    .success(config)
    .then(&method(:find_available_port))
    .then(&method(:start_tunnel_if_required))
    .then(&method(:serve))
    .unwrap { |error| raise error }
end