How to develop a Javascript Plugin

The JS wrapper is the code itself, written in JavaScript. The name of the file should be written in the config.json file format.

index.js

Within each plugin, the methods receiving parameters from the Kaholo server can be individually configured within each process,  and will return back to the server the execution result accordingly in the format of a Promise or async.

Promise example

function method_func(action, settings){
    return new Promise((resolve,reject) => {
    // Implement your code here....
    }
}

Once the method is established, you can implement your code within the promise and using the parameters received from both:
1. The action parameters set in the map
2. The plugin settings.
Both parameters are taken from the config.json file.

//change directory
const command = `cd ${action.params.ABC}`

Note: it is important not to forget to return the resolve or the reject back to the promise.

return resolve(stdout);

async example:

async function method_func(action, settings) {
   const results = {success = true};
   // Do logic here
   //for success just return
   return result
  
   //Otherwise if action failed throw the error.
   throw new Error ("Error has accrued")
}

When finishing the code for the plugin, the function needs to be externally exported in order for the server to note that this function exists.

module.exports = {
   executeYourPlugin
};

If you need additional support creating your plugin , please contact us at support@kaholo.io

Close Menu