-
-
Notifications
You must be signed in to change notification settings - Fork 126
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.
- Create the project folder in .graviton2/plugins.
$ mkdir SamplePlugin
$ cd SamplePlugin
- 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
Property main
refers to the location of your main.js file.
- Create our main file, wherever you want, I'm going to create it in the root folder.
touch main.js
- 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?
- We have declared our entry function, this will be executed when Graviton loads the plugin.
- 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.
- As you can see, it's creating a Notification, it passes as an argument an object with two properties, the title and the content.
- And finally, you export the entry function so Graviton can execute it.
Documentation
Tutorials
Contributing
About