Plugin Development¶
istSOS3 offer a plugin system. With new plugins you are able to extend istSOS3 with new features and functionalities.
There are two types of plugins that you can integrate: python plugins and web interfaces.
Python plugins¶
With istSOS3 Python Plugins you can add new features, or modify existings actions.
To create a new Python Plugin create your working directory into the istsos3 plugins folder:
cd istsos/plugins
mkdir istsos3_plugin_name
cd istsos3_plugin_name
mkdir lib
touch README.md config.json __init__.py action.py
Configure your plugin by modifying the config.json file:
{
"name": "Ping",
"version": "1.0.0",
"author": "Foo Bar",
"author_email": "me@example.com",
"description": "This is an istSOS3 plugin",
"license": "GPL3",
"url": "http://example.com/ping/",
"img": "http://example.com/ping/logo.png",
"api": {
"PING": [
"istsos3_plugin_name.action", "PingApi"
]
}
}
Modifiy your Python code (action.py) implementing the Action or CompositeAction class, the most important part is the api attribute. Here you register the name of the action with whom your plugin is called.
import asyncio
from istsos.entity.rest.response import Response
from istsos.actions.action import CompositeAction
class PingApi(CompositeAction):
@asyncio.coroutine
def before(self, request):
json = request.get_json()
if 'message' in json:
request['message'] = json['message']
yield from self.add_plugin("example", "Ping")
@asyncio.coroutine
def after(self, request):
request['response'] = Response(
json_source=Response.get_template({
"message": request["message"]
})
)
Web Interfaces¶
To build a new web component that can be easy be integrated into the istsos3-admin interface you have to create an npm package library.
Create the working directory:
mkdir istsos3-plugin-name
cd istsos3-plugin-name
mkdir lib
touch .babelrc .eslintrc .gitignore .npmignore README.md
touch lib/index.js
touch lib/config.js
Than initialize the npm package
npm init
If you have an npm organization scope:
npm init --scope=YOUR-ORG-NAME
Add all the required dependencies for the development.
yarn add --dev \
babel-cli \
babel-core \
babel-eslint \
babel-preset-env \
babel-preset-react \
eslint eslint-plugin-import \
eslint-plugin-jsx-a11y \
eslint-plugin-react \
eslint-watch \
babel-plugin-transform-object-rest-spread \
react \
react-dom \
Add istsos3 dependencies:
- istsos3-core contains fetching capabilities to execute istSOS3 actions.
- istsos3-ui contains some reusable istSOS3 web widgets
yarn add \
@istsos/istsos3-core \
@istsos/istsos3-ui
To develop using the Semantic UI framework
yarn add --dev \
semantic-ui-react \
semantic-ui-css
Fill the babel presets file .babelrc with this configuration
{
"presets": ["env", "react"],
"plugins": [
"transform-object-rest-spread"
]
}
Modify the package.json file scripts like this
{
"scripts": {
"build": "babel lib -d build",
"build:watch": "babel lib -w -d build",
"lint": "eslint lib/**; exit 0",
"lint:watch": "esw -w lib/**",
"prepublish": "npm run build"
}
}
Creates a symbolic link from a global folder
npm link
If working with source code of istsos3-core and istsos3-ui, link them globally as in the previews command then link them to you plugin
npm link @istsos/istsos3-core
npm link @istsos/istsos3-ui
Go in the istsos3-admin folder and link your plugin
npm link YOUR_PLUGIN_NAME
To start the development, cd to your plugin folder
npm run build:watch
Then also start the istsos3-admin module. cd to its folder and
npm start
To Build the component
yarn build