How to use @boost/event - 10 common examples

To help you get started, we’ve selected a few @boost/event examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github beemojs / beemo / packages / core / src / Driver.ts View on Github external
export default abstract class Driver<
  Config extends object = {},
  Options extends DriverOptions = DriverOptions
> extends Plugin {
  command: DriverCommandOptions = {};

  // @ts-ignore Set after instantiation
  config: Config;

  // @ts-ignore Set after instantiation
  metadata: DriverMetadata;

  onLoadModuleConfig = new Event<[ConfigContext, Path, Config]>('load-module-config');

  onLoadPackageConfig = new Event<[ConfigContext, Config]>('load-package-config');

  onMergeConfig = new Event<[ConfigContext, Config]>('merge-config');

  onCreateConfigFile = new Event<[ConfigContext, Path, Config]>('create-config-file');

  onCopyConfigFile = new Event<[ConfigContext, Path, Config]>('copy-config-file');

  onReferenceConfigFile = new Event<[ConfigContext, Path, Config]>('reference-config-file');

  onDeleteConfigFile = new Event<[ConfigContext, Path]>('delete-config-file');

  onBeforeExecute = new ConcurrentEvent<[DriverContext, Argv]>('before-execute');

  onAfterExecute = new ConcurrentEvent<[DriverContext, unknown]>('after-execute');

  onFailedExecute = new ConcurrentEvent<[DriverContext, Error]>('failed-execute');
github milesj / boost / packages / pipeline / src / WorkUnit.ts View on Github external
output?: Output;

  startTime: number = 0;

  statusText: string = '';

  stopTime: number = 0;

  readonly onFail = new Event<[Error | null]>('fail');

  readonly onPass = new Event<[Output]>('pass');

  readonly onRun = new BailEvent<[Input]>('run');

  readonly onSkip = new Event<[Input]>('skip');

  readonly title: string;

  private action: Action;

  private status: Status = STATUS_PENDING;

  // We want to support all contexts, so we use any.
  // Unknown and `Context` will not work because of the constraint.
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  constructor(title: string, action: Action, options?: Options) {
    super(options);

    if (!title || typeof title !== 'string') {
      throw new RuntimeError('pipeline', 'PL_REQ_TITLE');
    }
github milesj / boost / packages / core / src / Tool.ts View on Github external
// @ts-ignore Set after instantiation
  config: Config = {};

  console: Console;

  debug: Debugger;

  log: Logger;

  msg: Translator;

  onExit = new Event<[number]>('exit');

  onInit = new Event<[]>('init');

  onLoadPlugin = new Event<
    [PluginRegistry[keyof PluginRegistry]],
    Extract
  >('load-plugin');

  options: Required;

  package: PackageConfig = { name: '', version: '0.0.0' };

  rootPath: Path;

  private configLoader: ConfigLoader;

  private initialized: boolean = false;

  private plugins: { [K in keyof PluginRegistry]?: Set } = {};
github milesj / boost / packages / core / src / Console.ts View on Github external
constructor(tool: Tool, /* test only */ testWriters: typeof BOUND_WRITERS = BOUND_WRITERS) {
    super();

    this.debug = createDebugger('console');
    this.tool = tool;
    this.writers = testWriters;

    this.onError = new Event('error');
    this.onRoutine = new Event('routine');
    this.onRoutines = new Event('routines');
    this.onStart = new Event('start');
    this.onStop = new Event('stop');
    this.onTask = new Event('task');
    this.onTasks = new Event('tasks');

    // istanbul ignore next
    if (process.env.NODE_ENV !== 'test') {
      process
        .on('SIGINT', this.handleSignal)
        .on('SIGTERM', this.handleSignal)
        .on('uncaughtException', this.handleFailure)
        // @ts-ignore
        .on('unhandledRejection', this.handleFailure);
    }
  }
github beemojs / beemo / packages / driver-eslint / src / ESLintDriver.ts View on Github external
import fs from 'fs';
import { Event } from '@boost/event';
import { Driver, ConfigContext, ConfigArgs, Execution, Path } from '@beemo/core';
import { ESLintDriverArgs, ESLintConfig } from './types';

// Success: Writes warnings to stdout
// Failure: Writes to stdout and stderr
export default class ESLintDriver extends Driver {
  onCreateIgnoreFile = new Event<
    [ConfigContext, Path, { ignore: string[] }]
  >('create-ignore-file');

  bootstrap() {
    this.setMetadata({
      bin: 'eslint',
      configName: '.eslintrc.js',
      description: this.tool.msg('app:eslintDescription'),
      title: 'ESLint',
    });

    this.onCreateConfigFile.listen(this.handleCreateIgnoreFile);
  }

  /**
   * ESLint writes warnings to stdout, so we need to display
github milesj / boost / packages / core / src / Console.ts View on Github external
constructor(tool: Tool, /* test only */ testWriters: typeof BOUND_WRITERS = BOUND_WRITERS) {
    super();

    this.debug = createDebugger('console');
    this.tool = tool;
    this.writers = testWriters;

    this.onError = new Event('error');
    this.onRoutine = new Event('routine');
    this.onRoutines = new Event('routines');
    this.onStart = new Event('start');
    this.onStop = new Event('stop');
    this.onTask = new Event('task');
    this.onTasks = new Event('tasks');

    // istanbul ignore next
    if (process.env.NODE_ENV !== 'test') {
      process
        .on('SIGINT', this.handleSignal)
        .on('SIGTERM', this.handleSignal)
        .on('uncaughtException', this.handleFailure)
        // @ts-ignore
        .on('unhandledRejection', this.handleFailure);
    }
  }
github milesj / boost / packages / pipeline / src / WorkUnit.ts View on Github external
export default abstract class WorkUnit
  extends Contract
  implements Runnable, Hierarchical {
  depth: number = 0;

  index: number = 0;

  output?: Output;

  startTime: number = 0;

  statusText: string = '';

  stopTime: number = 0;

  readonly onFail = new Event<[Error | null]>('fail');

  readonly onPass = new Event<[Output]>('pass');

  readonly onRun = new BailEvent<[Input]>('run');

  readonly onSkip = new Event<[Input]>('skip');

  readonly title: string;

  private action: Action;

  private status: Status = STATUS_PENDING;

  // We want to support all contexts, so we use any.
  // Unknown and `Context` will not work because of the constraint.
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
github beemojs / beemo / packages / core / src / Driver.ts View on Github external
// @ts-ignore Set after instantiation
  metadata: DriverMetadata;

  onLoadModuleConfig = new Event<[ConfigContext, Path, Config]>('load-module-config');

  onLoadPackageConfig = new Event<[ConfigContext, Config]>('load-package-config');

  onMergeConfig = new Event<[ConfigContext, Config]>('merge-config');

  onCreateConfigFile = new Event<[ConfigContext, Path, Config]>('create-config-file');

  onCopyConfigFile = new Event<[ConfigContext, Path, Config]>('copy-config-file');

  onReferenceConfigFile = new Event<[ConfigContext, Path, Config]>('reference-config-file');

  onDeleteConfigFile = new Event<[ConfigContext, Path]>('delete-config-file');

  onBeforeExecute = new ConcurrentEvent<[DriverContext, Argv]>('before-execute');

  onAfterExecute = new ConcurrentEvent<[DriverContext, unknown]>('after-execute');

  onFailedExecute = new ConcurrentEvent<[DriverContext, Error]>('failed-execute');

  blueprint(predicates: Predicates) /* infer */ {
    // eslint-disable-next-line
    return {
      args: array(string()),
      dependencies: array(string()),
      env: object(string()),
      strategy: string(STRATEGY_NATIVE).oneOf([
        STRATEGY_NATIVE,
        STRATEGY_CREATE,
github beemojs / beemo / packages / core / src / Beemo.ts View on Github external
: string().required(),
  };
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export default class Beemo extends Tool> {
  moduleRoot?: Path;

  // eslint-disable-next-line @typescript-eslint/no-explicit-any
  pipeline: Pipeline> | null = null;

  onResolveDependencies = new Event<[ConfigContext, Driver[]]>(
    'resolve-dependencies',
  );

  onRunConfig = new Event<[ConfigContext, string[]]>('run-config');

  onRunDriver = new Event<[DriverContext, Driver]>('run-driver');

  onRunScript = new Event<[ScriptContext]>('run-script');

  onScaffold = new Event<[ScaffoldContext, string, string, string?]>('scaffold');

  constructor(argv: Argv, binName?: string, testingOnly: boolean = false) {
    super(
      {
        appName: 'beemo',
        appPath: path.join(__dirname, '..'),
        configBlueprint: configBlueprint(),
        configName: binName || 'beemo',
        scoped: true,
      },
github beemojs / beemo / packages / core / src / Driver.ts View on Github external
onMergeConfig = new Event<[ConfigContext, Config]>('merge-config');

  onCreateConfigFile = new Event<[ConfigContext, Path, Config]>('create-config-file');

  onCopyConfigFile = new Event<[ConfigContext, Path, Config]>('copy-config-file');

  onReferenceConfigFile = new Event<[ConfigContext, Path, Config]>('reference-config-file');

  onDeleteConfigFile = new Event<[ConfigContext, Path]>('delete-config-file');

  onBeforeExecute = new ConcurrentEvent<[DriverContext, Argv]>('before-execute');

  onAfterExecute = new ConcurrentEvent<[DriverContext, unknown]>('after-execute');

  onFailedExecute = new ConcurrentEvent<[DriverContext, Error]>('failed-execute');

  blueprint(predicates: Predicates) /* infer */ {
    // eslint-disable-next-line
    return {
      args: array(string()),
      dependencies: array(string()),
      env: object(string()),
      strategy: string(STRATEGY_NATIVE).oneOf([
        STRATEGY_NATIVE,
        STRATEGY_CREATE,
        STRATEGY_REFERENCE,
        STRATEGY_COPY,
        STRATEGY_NONE,
      ]),
    } as $FixMe;
  }

@boost/event

An event system with multiple emitter patterns.

MIT
Latest version published 2 months ago

Package Health Score

75 / 100
Full package analysis