Skip to content

Working with External Packages

A JS plugin is not a typical Node application as it must be bundled and registered with Logi Plugin Service in order for it to run. If a plugin was created using the logitoolkit create command, the build NPM script will include external JS dependencies as part of a bundling process. However, some packages may include certain assets in order to function. These may be non-JS script files, binaries, json files, etc. that are used by the package during runtime. If these files are not included as part of the build process, then there will likely be issues using these packages at runtime.

In order to function correctly in a plugin, a package that uses external assets must allow for the location of these assets to be configurable. Then, the assets.yml and ASSETS_PATH can be used to include these assets as part of the build process. In the example below, we will use the node-notifier package in our plugin to display a notification when an action is triggered.

Example: Showing a notification using node-notifier

Install the node-notifier package in your plugin:

npm install --save node-notifier

Create an assets.yml file in the root of the plugin directory. This will allow the plugin build to copy the executables needed to the plugin bundle for use during runtime. The assets.yml file should look like this:

- name: node-notifier
  path: node_modules/node-notifier/vendor/*

Create an action that uses the node-notifier library. Node-notifier has a customPath property to specify when creating a notifier instance. Use this to specify the location of the binary. Use the ASSETS_PATH constant to form the path of the executable so it can be found at runtime:

import { CommandAction, ASSETS_PATH } from '@logitech/plugin-sdk';

import { WindowsToaster } from 'node-notifier';

const notifier = new WindowsToaster({
  withFallback: false, // Fallback to Growl or Balloons?
  customPath: `${ASSETS_PATH}\\node-notifier\\snoreToast\\snoretoast-x64.exe`
});

export class ShowNotificationAction extends CommandAction {
  name = 'show_notification';
  displayName = 'Show notification';
  description = 'Displays an OS notification';

  onKeyDown() {
    notifier.notify(`Hello from ${this.displayName} action`);
  }
}