@aleksander_ciesielski/sinusbundler v0.1.0
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
(alsoexec
andquery
methods of an object that it returns)
Bundling everything up
CLI Settings:
name | description | default | ||
---|---|---|---|---|
--input | Path to input file (.js or .ts ) | |||
--output | Path to output file (.js ) | |||
--manifest | Path to manifest file (.json ) | script.manifest.json | ||
--tsconfig | Path to tsconfig.json, if you are not using TypeScript ignore this option | tsconfig.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
4 years ago