This is a demo plugin demonstrating the basic structure of a .bit plugin.
This plugin adds a method fly
to BitAccount
and a method flyAccount
to DotBit
.
import { createInstance } from 'dotbit'
import { BitPluginTemplate } from '@dotbit/plugin-template'
const dotbit = createInstance()
const plugin = new BitPluginTemplate()
// Install plugin to this `DotBit` instance
dotbit.installPlugin(plugin)
// A method `flyAccount` is added to this `DotBit` instance by the plugin
dotbit.flyAccount('imac.bit').then(console.log) // => 'imac.bit is flying to sky'
const bitAccount = dotbit.account('imac.bit')
// A method `fly` is also added to this `BitAccount` instance by the plugin
bitAccount.fly().then(conosle.log) // => 'imac.bit is flying'
// This will reomve the plugin
dotbit.uninstallPlugin(plugin)
- Please copy this template plugin under packages folder.
- Rename the folder to your preferred name, and change the package name to
@dotbit/plugin-xxx
. - Finish the plugin code according to dotbit plugin API below.
- Add tests under ./tests.
- Wrap them up and commit the code, and finally create a pull request.
- Once the codes are merged, your plugin will be published to npm. You can then use your plugin in production.
NOTE: The distributed codes will use ES Module or CommonJS and not compressed. You don't need to include webpack, rollup or other bundle tools. In most cases, you will only need to run the build command:
npm run build
.
Please check out the code here: index.ts
Basically, your plugin should provide 1 required method onInstall
and 2 optional methods onInitAccount
and onUninstall
. Their signatures are below:
export interface BitPluginBase {
version?: string,
name?: string,
/**
* This function will be invoked when plugin installed
* @param dotbit {DotBit}
*/
onInstall: (dotbit: DotBit) => void,
/**
* This function will be invoked when plugin uninstalled
* @param dotbit {DotBit}
*/
onUninstall?: (dotbit: DotBit) => void,
/**
* This function will be invoked when .bit account initialized
* @param bitAccount {BitAccount}
*/
onInitAccount?: (bitAccount: BitAccount) => void,
}
You can also check out here: types.ts.
Please use this command below, otherwise, you are publishing a private package.
pnpm publish --access public
We are willing to integrate with more brilliant projects in this ecosystem.
Please feel free to raise an issue or PR if you have any idea. Or you can chat directly with .bit developers in .bit Discord channel.