Packages - RevelMind/brewster GitHub Wiki
Packages consist of 2 or more files, a manifest file (package.json
) and a main Javascript file.
./
test/
package.json
index.js
The package.json
file contains information about the package, such as the name of the package, the version, etc.
{
"name": "test",
"version": "1.0.0",
"description": "Test package.",
"main": "index.js",
"commands": [
{
"usage": "test",
"description": "Says hello!"
}
]
}
name
- The name of the package.version
- The version of the package. Preferred to be major.minor.release.description
- Describes what the package is/does.main
- The path to the main Javascript file that will be loaded. This is relative to the path of thepackage.json
file.commands
- A list of commands that will show up when thehelp
command has been executed.
Commands
You don't have to add your commands to the commands
list, but it is recommended so that your commands will show up in the command list.
Each command defined in the commands
list has a usage value and an optional description value.
Javascript
Here is an example command:
module.exports = {
onCommand: function(cmd, args) {
if(cmd.toLowerCase() == 'test') {
console.log("Hello, world!"));
return true;
}
return false;
}
}
You export an Object
with the onCommand
function to detect when a command is executed. If the onCommand
function returns true, that means that the command belongs to your package. Otherwise, Brewster continues to check other packages for the executed command.
The first argument is a string that is the name of the sent command. The second argument is an array of the sent arguments, for example:
test hello world
console.log(cmd); // 'test'
console.log(args); // ['hello', 'world']