Module: AppMap::Depends::AppMapJS
- Included in:
- AppMapJSDepends
- Defined in:
- lib/appmap/depends/appmap_js.rb
Overview
Utilities for invoking the @appland/appmap CLI.
Constant Summary collapse
- APPMAP_JS =
'./node_modules/@appland/cli/src/cli.js'
Instance Method Summary collapse
- #appmap_js_command(command, options = {}) ⇒ Object
- #detect_appmap_js ⇒ Object
- #detect_nodejs ⇒ Object
- #do_fail(command, msg) ⇒ Object
- #index_appmaps(appmap_dir) ⇒ Object
Instance Method Details
#appmap_js_command(command, options = {}) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/appmap/depends/appmap_js.rb', line 34 def appmap_js_command(command, = {}) command.unshift << '--verbose' if Depends.verbose command.unshift APPMAP_JS command.unshift 'node' warn command.join(' ') if Depends.verbose stdout, stderr, status = Open3.capture3({ 'NODE_OPTIONS' => '--trace-warnings' }, *command, ) stdout_msg = stdout.split("\n").map {|line| "stdout: #{line}"}.join("\n") unless stdout.blank? stderr_msg = stderr.split("\n").map {|line| "stderr: #{line}"}.join("\n") unless stderr.blank? if Depends.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_appmap_js ⇒ Object
18 19 20 21 |
# File 'lib/appmap/depends/appmap_js.rb', line 18 def detect_appmap_js do_fail(APPMAP_JS, 'please install @appland/cli from NPM') unless File.exists?(APPMAP_JS) true end |
#detect_nodejs ⇒ Object
13 14 15 16 |
# File 'lib/appmap/depends/appmap_js.rb', line 13 def detect_nodejs do_fail('node', 'please install NodeJS') unless system('node --version 2>&1 > /dev/null') true end |
#do_fail(command, msg) ⇒ Object
28 29 30 31 32 |
# File 'lib/appmap/depends/appmap_js.rb', line 28 def do_fail(command, msg) command = command.join(' ') if command.is_a?(Array) warn [ command, msg ].join('; ') if Depends.verbose raise CommandError.new(command, msg) end |
#index_appmaps(appmap_dir) ⇒ Object
23 24 25 26 |
# File 'lib/appmap/depends/appmap_js.rb', line 23 def index_appmaps(appmap_dir) appmap_js_command [ 'index', '--appmap-dir', appmap_dir ] true end |