Skip to content

Sample Plugin

Marc Espín Sanz edited this page May 15, 2020 · 12 revisions

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

👉 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.)
Property Definition
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

It must have at least 2 properties ( just for now ).

  • name:
  • id:
  • main: .
  • mainDev:
  • mainSrc:

Example:

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