How to use the @boost/common.instanceOf function in @boost/common

To help you get started, we’ve selected a few @boost/common 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 milesj / boost / packages / core / src / ModuleLoader.ts View on Github external
if (!importedModule || !moduleName) {
      throw new Error(
        this.tool.msg('errors:moduleImportFailed', {
          modules: modulesToAttempt.join(', '),
          typeName,
        }),
      );
    }

    if (!this.contract) {
      return importedModule;
    }

    // An instance was returned instead of the class definition
    if (instanceOf(importedModule, this.contract)) {
      throw new TypeError(
        this.tool.msg('errors:moduleClassInstanceExported', {
          appName,
          moduleName,
          typeName,
        }),
      );
    } else if (typeof importedModule !== 'function') {
      throw new TypeError(this.tool.msg('errors:moduleClassDefRequired', { moduleName, typeName }));
    }

    const ModuleClass = importedModule as ConcreteConstructor;
    const module = new ModuleClass(...args);

    if (!instanceOf(module, this.contract)) {
      throw new TypeError(
github milesj / boost / packages / core / src / Tool.ts View on Github external
addPlugin(typeName: K, plugin: PluginRegistry[K]): this {
    const type = this.getRegisteredPlugin(typeName);

    if (!instanceOf(plugin, Plugin)) {
      throw new TypeError(this.msg('errors:pluginNotExtended', { parent: 'Plugin', typeName }));
    } else if (!instanceOf(plugin, type.contract)) {
      throw new TypeError(
        this.msg('errors:pluginNotExtended', { parent: type.contract.name, typeName }),
      );
    }

    plugin.tool = this;

    if (type.beforeBootstrap) {
      type.beforeBootstrap(plugin);
    }

    plugin.bootstrap();

    if (type.afterBootstrap) {
github milesj / boost / packages / core / src / Tool.ts View on Github external
addPlugin(typeName: K, plugin: PluginRegistry[K]): this {
    const type = this.getRegisteredPlugin(typeName);

    if (!instanceOf(plugin, Plugin)) {
      throw new TypeError(this.msg('errors:pluginNotExtended', { parent: 'Plugin', typeName }));
    } else if (!instanceOf(plugin, type.contract)) {
      throw new TypeError(
        this.msg('errors:pluginNotExtended', { parent: type.contract.name, typeName }),
      );
    }

    plugin.tool = this;

    if (type.beforeBootstrap) {
      type.beforeBootstrap(plugin);
    }

    plugin.bootstrap();

    if (type.afterBootstrap) {
      type.afterBootstrap(plugin);
    }
github milesj / boost / packages / core / src / Tool.ts View on Github external
    const plugin = this.getPlugins(typeName).find(p => instanceOf(p, Plugin) && p.name === name);
github milesj / boost / packages / core / src / ModuleLoader.ts View on Github external
loadModule(module: string | OptionsObject | Tm, args: any[] = []): Tm {
    if (this.contract && instanceOf(module, this.contract)) {
      return module as Tm;
    } else if (typeof module === 'string') {
      return this.importModule(module, args);
    } else if (isObject(module)) {
      return this.importModuleFromOptions(module, args);
    }

    throw new TypeError(this.tool.msg('errors:moduleTypeInvalid', { typeName: this.typeName }));
  }
github milesj / boost / packages / core / src / reporters / BoostReporter.ts View on Github external
getStepProgress(task: Task, type: 'routines' | 'tasks'): string {
    if (!task.parent || !instanceOf(task.parent, Routine)) {
      return '';
    }

    return `[${task.metadata.index + 1}/${task.parent![type].length}]`;
  }