class Controller
Coordinates package-manager commands and static package deployment for a project.
Definitions
def initialize(root)
Initialize a controller for a project.
Signature
-
parameter
rootString | Pathname The project directory containing
package.json.-
raises
ConfigurationError If the project configuration is invalid.
Implementation
def initialize(root)
@configuration = Configuration.load(root)
end
attr :configuration
Signature
-
attribute
Configuration The validated project configuration.
def install(frozen: false)
Install Node.js packages using the detected package manager.
Signature
-
parameter
frozenBoolean Whether the lock file must remain unchanged.
-
raises
Error If the package-manager command fails.
Implementation
def install(frozen: false)
package_manager.install(frozen: frozen)
end
def run(script)
Run a script from the root package.json file.
Signature
-
parameter
scriptString The script name to run.
-
raises
Error If the package-manager command fails.
Implementation
def run(script)
package_manager.run(script)
end
def update(output: nil)
Update the static projection of the configured packages.
Signature
-
parameter
outputString | Nil An optional project-relative output directory.
-
returns
Manifest The generated static package manifest.
Implementation
def update(output: nil)
Projection.new(@configuration, output: output).update
end
def check(output: nil)
Verify that the static package projection is current.
Signature
-
parameter
outputString | Nil An optional project-relative output directory.
-
returns
Boolean truewhen the static package projection is current.-
raises
CheckError If the static package projection is missing or out of date.
Implementation
def check(output: nil)
Projection.new(@configuration, output: output).check!
end
def import_map(output: nil)
Generate an import map from the static package manifest.
Signature
-
parameter
outputString | Nil An optional project-relative output directory.
-
returns
String The formatted import map JSON.
-
raises
CheckError If the static package manifest is missing or invalid.
Implementation
def import_map(output: nil)
root = @configuration.output_path(output)
JSON.pretty_generate(Manifest.load(root).import_map)
end