Module: Venetian::Executable

Defined in:
lib/venetian/executable.rb

Overview

Executable

Provides methods for locating the Playwright executable.

Defined Under Namespace

Classes: ExecutableNotFoundError, Executor, UnsupportedPlatformError

Constant Summary collapse

DEFAULT_DIR =

:nodoc:

File.expand_path(File.join(__dir__, "..", "..", "exe"))
INSTALL_DIR_ENV_VAR =

:nodoc:

"VENETIAN_INSTALL_DIR"

Class Method Summary collapse

Class Method Details

.base_commandObject

Returns the base command to execute Playwright.



113
114
115
# File 'lib/venetian/executable.rb', line 113

def base_command
  [path, File.join(File.dirname(path), "package", "cli.js")]
end

.execute(*args, echo: true, exception: true) ⇒ Object

Executes the Playwright executable with the given arguments.



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/venetian/executable.rb', line 89

def execute(*args, echo: true, exception: true, **)
  [*base_command, *args].then do |command|
    # due to mysterious Windows behavior; see equivalent in `tailwindcss-ruby`
    next system(*args, exception:, echo:) if Gem.win_platform?

    puts command.shelljoin if echo
    begin
      executor.exec(*command)
    rescue StandardError
      exception ? raise : false
    end
  end
end

.pathObject

Returns the path to the Node executable. Raises an error if the executable cannot be found.



80
81
82
83
84
85
86
# File 'lib/venetian/executable.rb', line 80

def path
  ensure_exe_dir_exists!
  ensure_gem_platform_supported! unless ENV.key?(INSTALL_DIR_ENV_VAR)
  ensure_executable_exists!

  exe_path
end

.system(*args, echo: true, exception: true) ⇒ Object

Runs the Playwright executable with the given arguments.



104
105
106
107
108
109
110
# File 'lib/venetian/executable.rb', line 104

def system(*args, echo: true, exception: true, **)
  [*base_command, *args].then do |command|
    puts command.shelljoin if echo
    executor.system(*command,
                    exception:, **{ out: echo ? nil : File::NULL, err: echo ? nil : File::NULL }.compact)
  end
end