Method: AppMap::NodeCLI#command

Defined in:
lib/appmap/node_cli.rb

#command(command, options = {}) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/appmap/node_cli.rb', line 32

def command(command, options = {})
  command.unshift << '--verbose' if verbose
  command.unshift APPMAP_JS
  command.unshift 'npx'

  warn command.join(' ') if verbose
  stdout, stderr, status = Open3.capture3({ 'NODE_OPTIONS' => '--trace-warnings' }, *command.map(&:shellescape), options)
  stdout_msg = stdout.split("\n").map {|line| "stdout: #{line}"}.join("\n") unless Util.blank?(stdout)
  stderr_msg = stderr.split("\n").map {|line| "stderr: #{line}"}.join("\n") unless Util.blank?(stderr)
  if verbose
    warn stdout_msg if stdout_msg
    warn stderr_msg if stderr_msg
  end
  unless status.exitstatus == 0
    raise CommandError.new(command, [ stdout_msg, stderr_msg ].compact.join("\n"))
  end
  [ stdout, stderr ]
end