0.1.0 • Published 4 years ago

sinusbundler v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

SinusBundler 📦

Overview

SinusBundler is a small JS/TS bundler based on Rollup, that allows you to split your SinusBot scripts into separate files. Besides that, you have an access to new JavaScript features as it is later transpiled down to ES5.

Installation

Using npm:

$ npm i sinusbundler -D

Using yarn:

$ yarn add sinusbundler --dev

Usage

Manifest

As opposed to standard SinusBot scripts, you do not specify plugin manifest in your script file. Instead, you should create JSON file (SinusBundler will look for script.manifest.json on default) where you store script's metadata:

{
  "name": "Hello World",
  "version": "1.0.0",
  "description": "Prints 'Hello World!'",
  "author": "Aleksander Ciesielski",
  "vars": []
}
Imports

After creating a manifest, you can start writing actual script. If you want to access SinusBot API, you can import everything from SinusBundler like this:

import * as sinusbot from "sinusbundler";

Or if you want to import just some of the modules (e.g. media):

import { media } from "sinusbundler";
Events

In addition to using event names you can also use Event enum

import { event, Event } from "sinusbundler";

event.on(Event.Chat, message => {
    const { client } = message;
    const nick = client.nick();

    client.chat(`Hello ${nick}!`);
});
Promises

Because you are able to use Promise (and also async/await syntax), some of the methods were changed to return Promise instead of relying on callbacks:

  • http.simpleRequest
  • graphics.setBanner
  • net.connect
  • db.connect (also exec and query methods of an object that it returns)

Bundling everything up

CLI Settings:

namedescriptiondefault
--inputPath to input file (.js or .ts)
--outputPath to output file (.js)
--manifestPath to manifest file (.json)script.manifest.json
--tsconfigPath to tsconfig.json, if you are not using TypeScript ignore this optiontsconfig.json

Warning: You should keep target set to es5 in tsconfig compilerOptions.

Example:

sinusbundler --input src/index.ts --output dist/bundle.js

You can also create a npm script for bundling your script:

{
  "scripts": {
    "build": "sinusbundler --input src/index.ts --output dist/bundle.js"
  }
}

Usage:

npm run build
yarn build