Class: Extension::Models::DevelopmentServer

Inherits:
Object
  • Object
show all
Includes:
SmartProperties
Defined in:
lib/project_types/extension/models/development_server.rb

Defined Under Namespace

Classes: DevelopmentServerError

Constant Summary collapse

EXECUTABLE_DIRECTORY =
File.join(ShopifyCLI::ROOT, "ext", "shopify-extensions")

Instance Method Summary collapse

Instance Method Details

#build(server_config) ⇒ Object



36
37
38
39
40
# File 'lib/project_types/extension/models/development_server.rb', line 36

def build(server_config)
  output, error, status = CLI::Kit::System.capture3(executable, "build", "-", stdin_data: server_config.to_yaml)
  return output if status.success?
  raise DevelopmentServerError, error
end

#create(server_config) ⇒ Object



29
30
31
32
33
34
# File 'lib/project_types/extension/models/development_server.rb', line 29

def create(server_config)
  output, _ = CLI::Kit::System.capture2e(executable, "create", "-", stdin_data: server_config.to_yaml)
  output
rescue StandardError => error
  raise error
end

#executableObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/project_types/extension/models/development_server.rb', line 14

def executable
  super || begin
    case RbConfig::CONFIG.fetch("host_os")
    when /(linux)|(darwin)/
      File.join(EXECUTABLE_DIRECTORY, "shopify-extensions")
    else
      File.join(EXECUTABLE_DIRECTORY, "shopify-extensions.exe")
    end
  end
end

#executable_installed?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/project_types/extension/models/development_server.rb', line 25

def executable_installed?
  File.exist?(executable)
end

#serve(context, server_config) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/project_types/extension/models/development_server.rb', line 42

def serve(context, server_config)
  CLI::Kit::System.popen3(executable, "serve", "-") do |input, out, err, status|
    context.debug("Sending configuration data to extension development server …")
    input << server_config.to_yaml
    input.close

    forward_output_to_user(out, err, context)

    status.value
  end
end

#versionObject

Raises:

  • (NotImplementedError)


54
55
56
# File 'lib/project_types/extension/models/development_server.rb', line 54

def version
  raise NotImplementedError
end