Skip to content

Sample Plugin

Marc Espín Sanz edited this page Apr 25, 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 it's main JavaScript file.

😀 A working example

  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: name of your plugin, it cannot contain spaces
  • id: more specific name
  • main: refers to the location of your main file.
  • mainDev: indicates the main file when the plugin is being developed
  • mainSrc: indicates the main file in the source code

Example:

{
	"name":"SamplePlugin",
	"id":"sample-plugin",
	"main":"main.js",
	"mainSrc":"main.js",
	"mainDev":"main.js"
}
  1. Create the 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