Skip to content

Commit

Permalink
Add a plugin example for creating custom types and fix grammar errors…
Browse files Browse the repository at this point in the history
… in the documentation

Signed-off-by: Axel Boberg <git@axelboberg.se>
  • Loading branch information
axelboberg committed May 16, 2024
1 parent 8f38a78 commit d3eb044
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Full documentation

Welcome to the full documentation for Bridge. Whether you're want to build your own extension or are looking for more information about the internals, this is the place to find it.
Welcome to the full documentation for Bridge. Whether you want to build your own extension or are looking for more information about the internals, this is the place to find it.

## Bundled plugins
- [Inspector](/plugins/inspector/README.md)
Expand All @@ -12,6 +12,7 @@ Welcome to the full documentation for Bridge. Whether you're want to build your

## Developing plugins
- [Guide](/docs/plugins/README.md)
- [Examples](/examples)
- [API reference](/docs/api/README.md)

## Internals
Expand Down
3 changes: 3 additions & 0 deletions examples/plugin-custom-types/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Custom types example plugin
This is an example plugin for showcasing how to create custom types that can be run within Bridge.
The type definition is located within [package.json](./package.json) while the type-specific logic resides in [index.js](./index.js).
29 changes: 29 additions & 0 deletions examples/plugin-custom-types/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
const bridge = require('bridge')

/*
The exported 'activate' function is the plugin's initialization function,
it will be called when the plugin is loaded and every time a workspace
is opened
*/
exports.activate = async () => {
/*
Listen for the item.play event to react to an item being played,
the item's type-property can be used to perform the correct action
The type 'plugin-custom-types.my-type' is in this case
defined within the plugin's package.json file
*/
bridge.events.on('item.play', item => {
if (item?.type === 'plugin-custom-types.my-type') {
// Perform action
console.log('MY CUSTOM TYPE PLAYED')
}
})

bridge.events.on('item.stop', item => {
if (item?.type === 'plugin-custom-types.my-type') {
// Perform action
console.log('MY CUSTOM TYPE STOPPED')
}
})
}
32 changes: 32 additions & 0 deletions examples/plugin-custom-types/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"name": "plugin-custom-types",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"engines": {
"bridge": "^0.0.1"
},
"author": "",
"license": "ISC",
"contributes": {
"types": [
{
"id": "plugin-custom-types.my-type",
"name": "My custom type",
"inherits": "bridge.types.delayable",
"category": "Custom types",
"properties": {
"myValue": {
"name": "My custom value",
"type": "string",
"default": "Default value",
"ui.group": "My custom type plugin"
}
}
}
]
}
}

0 comments on commit d3eb044

Please sign in to comment.