A Node.js module that makes building BetterDiscord plugins based off rauenzi's ZLibrary easy!
BDPluginLibrary AKA ZLibrary AKA Zere's Plugin Library AKA 0PluginLibrary is an extremely common tool for creating plugins for BetterDiscord, making life so much easier. However, the process to "build" a plugin is annoying to say the least. This project breaks away just the build scripts and adapts them to work neatly as a CLI node module!
- the main purpose of the module: able to be called and configured externally
- able to build just one plugin without embedding in a plugin folder
- dynamically embed external node modules into your plugin
zlibrarybuilder is available on npm
npm i zlibrarybuilder --save-dev
or you can install it from the github repo
npm i https://github.com/HexCodeFFF/ZLibraryBuilder --save-dev
zlibrarybuilder
builds the single plugin contained inside the plugins
folder, outputs to the release
folder
zlibrarybuilder --pluginFolder ./plugin -ci
builds the plugin contained inside the plugin
folder, adds the install script (-i
) and
copies it to BetterDiscord (-c
)
zlibrarybuilder --pluginFolder ./plugins -cimo
the -m
argument makes it build all plugins inside the folder, like the default
ZLibrary build.js
script does.
the -o
argument is for backwards compatability, as this library changes some compilation behavior.
package.json
{
"name": "myplugin",
"dependencies": {
"zlibrarybuilder": "^1.0.0",
// ... (other dependencies)
},
// ... (other package.json stuff)
"buildConfig": {
"pluginFolder": "./plugin",
"copyToBD": true,
"addInstallScript": true
}
}
zlibrarybuilder
this example has the same end behavior as the "build one plugin" example above
there are several ways to specify config options to enable both ease of use and backwards compatibility. all options are the same, just specified differently. options are found in this order, first ones take priority:
- options specified via CLI
buildConfig
field in yourpackage.json
config.json
file at the root of your projectdefaultConfig
field in yourpackage.json
- default options
options are listed via their CLI usage, use the long name as a key in either JSON file to specify it from there.
default: ./plugins
Absolute or relative path to the folder containing the plugin(s) that build scripts can build automatically.
default: ./release
Absolute or relative path to the folder where plugins that are built should be placed.
default: false
Boolean to determine if the built plugin should also be automatically copied over to your BD plugins directory. Very convenient for development.
default: false
Boolean to determine if the plugin should include the Windows Host Script install script. This means that users on Windows that double click the plugin will be prompted to automatically install the plugin.
default: false
Boolean to include all lib functions into the plugin file.
default: false
Boolean to re-enable the default behavior of ZLibrary, which is trying to build all plugins in the pluginFolder. If disabled, will assume pluginFolder is the path to one plugin.
default: false
Boolean to re-enable the normal ZLibrary plugin header generation. The existing generation was strange and limited, and
this option only exists for backwards compatability. Leave disabled for the improved behavior, passing all
plugin config.info
keys as JSDoc entries.
View the official BetterDiscord docs for more info about these.
keep in mind that the ZLibrary authors
field overwrites the author
and authorId
properties. ZLibraryBuilder (when
oldHeader is off) attempts to convert these into the correct ZLibrary config options if authors
is unspecified, but it
is better to just work with ZLibrary.
display help for command. won't do anything if specified via JSON.
ZLibraryBuilder has the ability to automatically compile and embed external node.js modules into your plugin for you in 2 easy steps
- make sure the module in question is installed in your node_modules
- add a comment so ZLibraryBuilder knows to replace the
require()
// this statement will remain unmodified
require('ts-leaky-bucket');
// zlibrarybuilder will replace this with the entire library code for you!
require('ts-leaky-bucket' /* zlibrarybuilder embed */);
the reason that not all require calls are replaced by default is that discord itself is a node app and it is highly
recommended to properly require()
from discord's modules when possible
note: ZLibraryBuilder naively replaces all (properly commented) require()
calls with library embeds. if you
require the module twice, it'll be in your plugin twice. please require it once to a variable and reuse the variable.