@dotbit/plugin-template
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

@dotbit/plugin-template

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.

Usage

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)

Write a plugin

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.

Publish a plugin

Please use this command below, otherwise, you are publishing a private package.

pnpm publish --access public

Contribute

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.

Readme

Keywords

none

Package Sidebar

Install

npm i @dotbit/plugin-template

Weekly Downloads

1

Version

0.0.2

License

MIT

Unpacked Size

7.09 kB

Total Files

9

Last publish

Collaborators

  • max-npm
  • jeffjing