diff options
Diffstat (limited to 'docs/plugins/create.md')
-rw-r--r-- | docs/plugins/create.md | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/docs/plugins/create.md b/docs/plugins/create.md new file mode 100644 index 0000000..787b191 --- /dev/null +++ b/docs/plugins/create.md @@ -0,0 +1,63 @@ +# Create and publish a plugin + +A GitBook plugin is a node package published on NPM that follow a defined convention. + +## Structure + +#### package.json + +The `package.json` is a manifest format for describing **Node.js modules**. GitBook plugins are built on top of Node modules. It declares dependencies, version, ownership, and other information required to run a plugin in GitBook. This document describes the schema in detail. + +``` +{ + "name": "gitbook-plugin-mytest", + "version": "0.0.1", + "description": "This is my first GitBook plugin", + "engines": { + "gitbook": ">1.x.x" + } +} +``` + +You can learn more about `package.json` from the [NPM documentation](https://docs.npmjs.com/files/package.json). + +The **package name** must begin with `gitbook-plugin-` and the **package engines** should contains `gitbook`. + +#### index.js + +The `index.js` is main entry point of your plugin runtime: + +```js +module.exports = { + // Map of hooks + hooks: {}, + + // Map of new blocks + blocks: {}, + + // Map of new filters + filters: {} +}; +``` + +## Publish your plugin + +GitBook plugins can be published on [NPM](https://www.npmjs.com). + +To publish a new plugin, you need to create an account on [npmjs.com](https://www.npmjs.com) then publish it from the command line: + +``` +$ npm publish +``` + +## Private plugins + +Private plugins can be hosted on GitHub and included using `git` urls: + +``` +{ + "plugins": [ + "git+https://github.com/MyCompany/mygitbookplugin.git#1.0.0" + ] +} +``` |