Skip to main content

Event-driven tooling

What kind of tool would Beemo be without the ability to listen to events? A terrible one, and as such, Beemo totally supports them! Events provide an easy mechanism for hooking into the lifecycle of a Beemo process.

To begin, create an index file in your configuration module that exports a function, either as a default export or as a named bootstrap export. This function will receive a Beemo Tool instance for the current process, in which listeners can be registered.

index.ts
import { Tool } from '@beemo/core';
export default function bootstrap(tool: Tool) {
// Add command line args to every execution
tool.driverRegistry.get('eslint').onBeforeExecute.listen((context) => {
context.addOptions(['--color', '--report-unused-disable-directives']);
});
}

The bootstrap function supports async/await.

Bootstrap resolution#

The bootstrap file is looked for and resolved in the following order relative to the configuration module.

  • index.ts
  • index.js
  • src/index.ts
  • lib/index.js
  • main field in package.json

Supported events#

The following list of events, and their arguments, can be listened to.

Tool#

EventArgumentsTypeDescription
onResolveDependenciescontext: ConfigContext, drivers: Driver[]NormalCalled after a list of Drivers have been resolved in which to create configuration files.
onRunCreateConfigcontext: ConfigContext, driverNames: string[]NormalCalled before beemo create-config is ran.
onRunDrivercontext: DriverContext, driver: DriverNormalCalled before beemo <driver> is ran. Requires a scope of the driver name.
onRunScriptcontext: ScriptContextNormalCalled before beemo run-script <script> is ran. Requires a scope of the script name.
onScaffoldcontext: ScaffoldContext, generator: string, action: string, name?: stringNormalCalled before templates are generated when scaffolding.

Driver#

EventArgumentsTypeDescription
onAfterExecutecontext: DriverContext, response: unknownConcurrentCalled after the driver has successfully been executed.
onBeforeExecutecontext: DriverContext, argv: string[]ConcurrentCalled before the underlying Driver binary command is executed.
onCreateConfigFilecontext: ConfigContext, path: Path, config: objectNormalCalled before the configuration file is written.
onCopyConfigFilecontext: ConfigContext, path: Path, config: objectNormalCalled before the configuration file is copied from module.
onDeleteConfigFilecontext: ConfigContext, path: PathNormalCalled before the configuration file is deleted. Occurs during the cleanup phase.
onFailedExecutecontext: DriverContext, error: ErrorConcurrentCalled after the driver has failed to execute.
onLoadModuleConfigcontext: ConfigContext, path: Path, config: objectNormalCalled after configuration has been loaded from the configuration module.
onLoadPackageConfigcontext: ConfigContext, config: objectNormalCalled after configuration has been extracted from package.json.
onMergeConfigcontext: ConfigContext, config: objectNormalCalled after multiple configuration sources have been merged into 1.
onReferenceConfigFilecontext: ConfigContext, path: Path, config: objectNormalCalled before the configuration file is referenced.
onTemplateConfigFilecontext: ConfigContext, path: Path, config: object/stringNormalCalled before the configuration file is written. The config is built using a consumer template, so can appear as an object or raw string (config file contents).

Script#

EventArgumentsTypeDescription
onAfterExecutecontext: ScriptContext, response: unknownConcurrentCalled after the script has successfully been executed.
onBeforeExecutecontext: ScriptContext, argv: string[]ConcurrentCalled before the Script#execute method is ran.
onFailedExecutecontext: ScriptContext, error: ErrorConcurrentCalled after the script has failed to execute.

Type declarations#

  • Driver - An instance of the Driver class.
  • Script - An instance of the Script class.
  • Context, DriverContext, ScriptContext, ScaffoldContext - Special objects passed through the entire execution process.