Skip to content

Sample Plugin

Marc Espín Sanz edited this page Jun 24, 2020 · 12 revisions

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

👉 Sample plugin

Setup

Create the project folder in your .graviton2/plugins.

Create the plugin folder, you can name it as you wish.

mkdir SamplePlugin

Go inside it.

cd SamplePlugin

Now, let's create our package.json ( You can use npm init if you wish.)

Property Definition
name Plugin's name
id Technical name (no spaces)
main Location of your main file

Example:

{
  "name": "SamplePlugin",
  "id": "sample-plugin",
  "main" :"main.js",
}

Create the main file in the root folder.

touch main.js

Coding

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 recognize and execute it.

Documentation

Tutorials

Contributing

About

Clone this wiki locally