Class: Everywhere::Commands::Dev

Inherits:
Dry::CLI::Command
  • Object
show all
Defined in:
lib/everywhere/commands/dev.rb

Overview

Run the app's normal dev server and open the desktop shell pointed at it. No packaging: the shell skips the sidecar when NATIVE_DEV_URL is set, so the edit-refresh loop is untouched Rails/Hanami.

Instance Method Summary collapse

Instance Method Details

#call(port: "3000", shell_dir: nil) ⇒ Object



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
# File 'lib/everywhere/commands/dev.rb', line 19

def call(port: "3000", shell_dir: nil, **)
  framework = Framework.detect
  config = Everywhere::Config.load(framework.root)
  shell_dir ||= Everywhere::Paths.shell_dir!

  server_pid = nil
  if port_open?(port)
    UI.warn "something is ALREADY RUNNING on port #{port} — attaching to it instead of starting"
    UI.warn "#{UI.dim("your Procfile.dev/watchers are NOT running; stop that server or use --port if this isn't yours")}"
  else
    UI.step("starting #{UI.bold(framework.name)} dev server #{UI.dim("(" + framework.dev_command + ")")}")
    server_pid = Shellout.spawn({ "PORT" => port.to_s }, framework.dev_command, chdir: framework.root)
    wait_for_port(port)
  end

  dev_url = "http://127.0.0.1:#{port}#{config.entry_path}"
  UI.step("opening desktop shell → #{UI.cyan(dev_url)}")
  Shellout.run!({ "NATIVE_DEV_URL" => dev_url, "NATIVE_CONFIG" => config.to_shell_json,
                  "CARGO_TARGET_DIR" => Everywhere::Paths.cargo_target_dir },
                "cargo", "run", chdir: shell_dir)
ensure
  if server_pid
    Process.kill("TERM", -Process.getpgid(server_pid)) rescue Process.kill("TERM", server_pid) rescue nil
    Process.wait(server_pid) rescue nil
  end
end