Class: Lively::Electron::Packager::Generic
- Inherits:
-
Object
- Object
- Lively::Electron::Packager::Generic
- Defined in:
- lib/lively/electron/packager/generic.rb
Overview
A tool-agnostic Node project layout. Both Npm and Pnpm place CLI shims in ‘node_modules/.bin` after install. Subclasses implement the concrete #install_command and #setup! flows.
Constant Summary collapse
- ELECTRON_VERSION_RANGE =
"^41.0.0"
Instance Attribute Summary collapse
Instance Method Summary collapse
-
#electron_executable_path(package_root, environment = ::ENV) ⇒ Object
Resolves a filesystem path to the ‘electron` binary.
-
#install_command ⇒ Object
abstract
The ‘argv` for a top-level install with the current packager (e.g. `pnpm install` or `npm install`).
-
#install_hint(root) ⇒ Object
A human-readable suggestion for running the install command in ‘root`.
-
#run_install_in!(package_root) ⇒ Object
Runs #install_command inside ‘package_root` (e.g. from a bake or CI task).
-
#setup!(package_root) ⇒ Object
abstract
Creates a ‘package.json` when none exists using the tool’s ‘init` flow, then adds ELECTRON_VERSION_RANGE as a dependency.
Instance Attribute Details
#Semver range for the `electron` dependency written by {setup!}.(range) ⇒ Object (readonly)
20 |
# File 'lib/lively/electron/packager/generic.rb', line 20 ELECTRON_VERSION_RANGE = "^41.0.0" |
Instance Method Details
#electron_executable_path(package_root, environment = ::ENV) ⇒ Object
Resolves a filesystem path to the ‘electron` binary. A non-empty `ELECTRON` entry in `environment` wins outright; otherwise looks for an executable `node_modules/.bin/electron` shim under `package_root`.
53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/lively/electron/packager/generic.rb', line 53 def electron_executable_path(package_root, environment = ::ENV) explicit = environment["ELECTRON"]&.to_s if explicit && !explicit.empty? return File.(explicit) end path = local_electron_path(package_root) return path if File.executable?(path) raise NotFoundError, "Could not find electron in #{package_root}." end |
#install_command ⇒ Object
The ‘argv` for a top-level install with the current packager (e.g. `pnpm install` or `npm install`).
26 27 28 |
# File 'lib/lively/electron/packager/generic.rb', line 26 def install_command raise NotImplementedError, "#{self.class} must implement #install_command" end |
#install_hint(root) ⇒ Object
A human-readable suggestion for running the install command in ‘root`. Useful when `electron` is absent from both `node_modules` and `PATH`.
68 69 70 |
# File 'lib/lively/electron/packager/generic.rb', line 68 def install_hint(root) "Run: #{install_command.join(' ')} in #{File.(root)}" end |
#run_install_in!(package_root) ⇒ Object
Runs #install_command inside ‘package_root` (e.g. from a bake or CI task).
33 34 35 36 37 38 |
# File 'lib/lively/electron/packager/generic.rb', line 33 def run_install_in!(package_root) args = install_command unless system(*args, chdir: File.(package_root), exception: false) raise "Command failed: #{args.join(" ")} (in #{package_root})" end end |
#setup!(package_root) ⇒ Object
Creates a ‘package.json` when none exists using the tool’s ‘init` flow, then adds ELECTRON_VERSION_RANGE as a dependency.
44 45 46 |
# File 'lib/lively/electron/packager/generic.rb', line 44 def setup!(package_root) raise NotImplementedError, "#{self.class} must implement #setup!" end |