Skip to content

Latest commit

 

History

History
164 lines (110 loc) · 3.75 KB

7-to-8.md

File metadata and controls

164 lines (110 loc) · 3.75 KB

Migration Guide

Migrating from version 7 to version 8.

Version 8 has again seen a large section of the nrelay codebase receive huge changes. However, the plugin API has remained relatively the same from version 7 to version 8.

This document is not an exhaustive list of every single breaking change, but is intended to be a guide which will help plugin developers convert plugins to the new version 8 style.

Quick links

The nrelay CLI

The largest change from version 7 to version 8 is the creation of the nrelay command line interface. Previously, the entire nrelay codebase had to be cloned in order to run plugins, but the CLI provides a clean way of avoiding this issue.

To install the CLI, run the command

npm install -g nrelay-cli

This will globally install the CLI and make the nrelay command available.

Migrating plugins to the CLI style

To migrate the plugins, first create a new nrelay project

nrelay new my-project-name

When this has completed, copy all of the plugins you want to migrate into the src/ directory of the newly generated project.

Changes to imports

Since nrelay is now an npm module which is installed in all nrelay projects, the location of all imports has changed to simply be from 'nrelay'.

Refactor example

Change

import { Library, PacketHook, Client } from './../core';

class HelloPlugin {

}

to

import { Library, PacketHook, Client } from 'nrelay';

class HelloPlugin {

}

Changes to the CLI class

The CLI class has been removed. The functionality which it provided is now provided by the Runtime class.

Refactor example

Change

class ExamplePlugin {
  constructor() {
    const clients = CLI.getClients();
    Logger.log('Plugin', `There are ${clients.length} clients connected`);
  }
}

to

class ExamplePlugin {
  constructor(runtime: Runtime) {
    const clients = runtime.getClients();
    Logger.log('Plugin', `There are ${clients.length} clients connected`);
  }
}

Changes to the client event emitter

The static client event emitter has been replaced by an event emitter on the Runtime class. The event names have also been moved into an enum to provide stronger typing.

Refactor example

Change

import { Client } from './../core';

class ExamplePlugin {
  constructor() {
    Client.on('ready', (client) => {
      Logger.log('Plugin', `${client.alias} is ready!`);
    });
  }
}

to

import { Client, Events, Runtime } from 'nrelay';

class ExamplePlugin {
  constructor(runtime: Runtime) {
    runtime.on(Events.ClientReady, (client: Client) => {
      Logger.log('Plugin', `${client.alias} is ready!`);
    });
  }
}

Changes to static classes

The majority of the static classes, with the exception of the Logger class, have been changed to be instance based. Instances of these previously static classes are available in the Runtime.

Refactor example

Change

class ExamplePlugin {
  constructor() {

    const itemCount = Object.keys(ResourceManager.items).length;

    Logger.log('Plugin', `There are ${itemCount} items`);
  }
}

to

class ExamplePlugin {
  constructor(runtime: Runtime) {

    const itemCount = Object.keys(runtime.resources.items).length;

    Logger.log('Plugin', `There are ${itemCount} items`);
  }
}

Other classes which are affected include:

  • AccountService.
  • LibraryManager.
  • Updater.