Creating your first plugin
First we need to tell ourselves if we want to do the plugin as an npm package, or some folder just for us. If we want to do the plugin as an npm package then we need to make our package called gcommands-plugin-{name}
. If we want it purely just a folder then we just need to make a plugins
folder, into which we put the plugin folder.
You can also do the plugin in TypeScript, but you don't have to. If you do make the plugin in TypeScript, you have to build the plugin before publishing.
Now that we have everything ready, let's create the main index.js
file for the plugin.
Then we import Plugin
from gcommands
.
const { Plugin, registerDirectory } = require('gcommands');
const path = require('path');
new Plugin('my-first-plugin', () => {
registerDirectory(path.join(__dirname, 'listeners'));
})
2
3
4
5
6
We have registered a listeners folder that we will keep in the plugin. Then all you have to do is create listeners in this folder, as already shown here
Package
├── node_modules
└── gcommands-plugin-my-plugin
└── listeners
└── ready.js
└── index.js
├── package.json
└── src
└── index.js
2
3
4
5
6
7
8
Folder
├── node_modules
├── package.json
├── plugins
└── my-first-plugin
└── listeners
└── ready.js
└── index.js
└── src
└── index.js
2
3
4
5
6
7
8
9