Class: AppMap::NodeCLI
Overview
Utilities for invoking the @appland/appmap CLI.
Direct Known Subclasses
Constant Summary collapse
- APPMAP_JS =
'@appland/appmap'
Instance Attribute Summary collapse
-
#appmap_dir ⇒ Object
Directory to scan for AppMaps.
-
#verbose ⇒ Object
readonly
Returns the value of attribute verbose.
Instance Method Summary collapse
- #command(command, options = {}) ⇒ Object
- #detect_nodejs ⇒ Object
- #index_appmaps ⇒ Object
-
#initialize(verbose: false, appmap_dir: AppMap::DEFAULT_APPMAP_DIR) ⇒ NodeCLI
constructor
A new instance of NodeCLI.
Constructor Details
#initialize(verbose: false, appmap_dir: AppMap::DEFAULT_APPMAP_DIR) ⇒ NodeCLI
Returns a new instance of NodeCLI.
15 16 17 18 19 20 |
# File 'lib/appmap/node_cli.rb', line 15 def initialize(verbose: false, appmap_dir: AppMap::DEFAULT_APPMAP_DIR) @verbose = verbose @appmap_dir = appmap_dir detect_nodejs end |
Instance Attribute Details
#appmap_dir ⇒ Object
Directory to scan for AppMaps.
13 14 15 |
# File 'lib/appmap/node_cli.rb', line 13 def appmap_dir @appmap_dir end |
#verbose ⇒ Object (readonly)
Returns the value of attribute verbose.
11 12 13 |
# File 'lib/appmap/node_cli.rb', line 11 def verbose @verbose end |
Instance Method Details
#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, = {}) 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), ) 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 |
#detect_nodejs ⇒ Object
22 23 24 25 |
# File 'lib/appmap/node_cli.rb', line 22 def detect_nodejs do_fail('node', 'please install NodeJS') unless system('node --version 2>&1 > /dev/null') true end |
#index_appmaps ⇒ Object
27 28 29 30 |
# File 'lib/appmap/node_cli.rb', line 27 def index_appmaps command [ 'index', '--appmap-dir', appmap_dir ] true end |