Class: ReactOnRails::Dev::ProcessManager

Inherits:
Object
  • Object
show all
Defined in:
lib/react_on_rails/dev/process_manager.rb

Class Method Summary collapse

Class Method Details

.ensure_procfile(procfile) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/react_on_rails/dev/process_manager.rb', line 14

def ensure_procfile(procfile)
  return if File.exist?(procfile)

  warn <<~MSG
    ERROR:
    Please ensure `#{procfile}` exists in your project!
  MSG
  exit 1
end

.installed?(process) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
# File 'lib/react_on_rails/dev/process_manager.rb', line 7

def installed?(process)
  IO.popen([process, "-v"], &:close)
  true
rescue Errno::ENOENT
  false
end

.run_with_process_manager(procfile) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/react_on_rails/dev/process_manager.rb', line 24

def run_with_process_manager(procfile)
  # Validate procfile path for security
  unless valid_procfile_path?(procfile)
    warn "ERROR: Invalid procfile path: #{procfile}"
    exit 1
  end

  # Clean up stale files before starting
  FileManager.cleanup_stale_files

  if installed?("overmind")
    system("overmind", "start", "-f", procfile)
  elsif installed?("foreman")
    system("foreman", "start", "-f", procfile)
  else
    warn <<~MSG
      NOTICE:
      For this script to run, you need either 'overmind' or 'foreman' installed on your machine. Please try this script after installing one of them.
    MSG
    exit 1
  end
end