Skip to content

Sample Plugin

Marc Espín edited this page Mar 6, 2020 · 12 revisions

This guide is to show you how a basic plugin works in Graviton version 2.X.

Note: Plugins in v2.X works slight different compared to v1.X.

Graviton plugins are like most of NPM packages, they have it's own package.json, and also it's main JavaScript file.

  1. Create the project folder in .graviton2/plugins.

$ mkdir SamplePlugin $ cd SamplePlugin

  1. Now, let's create our package.json ( You can use npm init if you wish.) It must have at least 2 properties ( just for now ).
  • name
  • main

Peropert main refers to the location of your main.js file.

  1. Create our main file, wherever you want, I'm going to create it in the root folder.

touch main.js

  1. Paste this code in the main.js:
function entry(API){
  new API.Notification({
    title:'A cool notification!',
    content:'Some content :)'
  })
}

module.exports = { entry }

What is this code doing?

  1. We have declared our entry function, this will be executed when Graviton loads the plugin.
  2. The entry function has only one argument, it's the API, it's an object containing all the different components and methods you can use in your plugin.
  3. As you can see, it's creating a Notification, it passes as an argument an object with two properties, the title and the content.
  4. And finally, you export the entry function so Graviton can execute it.

Documentation

Tutorials

Contributing

About

Clone this wiki locally