You can extend the functionality of Stelace API server with plugins, built on top of all core services to add:
routes
withversions
middlewares
- new
permissions
- own
test
folder andfixtures
This means plugins are very powerful and should be installed with care if they’re not officially supported.
Most official plugins are currently included in plugins
directory of Stelace server repository and automatically loaded on startup.
You can:
- Exclude local plugins with
IGNORED_LOCAL_PLUGINS
environment variable npm install
/yarn add
any additional plugins (added to package.json) and add them toINSTALLED_PLUGINS
environment variable- or simply add Github repository URLs to
INSTALLED_PLUGINS
comma-separated list and runyarn plugins
When using INSTALLED_PLUGINS
and yarn plugins
, this runs two commands internally, supporting private plugins:
yarn plugins:install
addsINSTALLED_PLUGINS
to node_modules without updating package.json, unless you pass--save
flag. Modules are then copied toplugins/installed
.gitignore
’d directory to avoid tampering with node_modules.yarn plugins:prepare
rewritesrequire('stelace-server')
calls to use local server.
Have a look at official rating
plugin to get a complete working example.
Search filter Domain-Specific Language is also enabled by a standalone plugin, as another working example.
Plugins are expected to export the following properties from index.js
file, in addition to optional properties mentioned in the intro above:
name
version
supportedServerVersions
When developing a plugin as an external repository, you can yarn add -D https://github.com/stelace/stelace.git
as a devDependency to be able to use exports from server.js
using require('stelace-server')
.
Look at official Search filter DSL parser plugin for a blueprint.
You can easily run external plugin tests with 'stelace-server' as a devDependency.
Add this script to package.json file in your plugin repository:
// plugin loads itself before starting tests
"scripts": {
"test": "cross-env STELACE_PLUGINS_PATHS=$(shx pwd) NODE_ENV=test ava --c $(node -p 'Math.max(os.cpus().length - 1, 1)')",
}
Include the following lines at the beginning of test/*.spec.js
files:
const test = require('ava')
const {
testTools: {
lifecycle,
/* … */
}
} = require('stelace-server')
const { before, beforeEach, after } = lifecycle
test.before(before({ name: 'event' }))
test.beforeEach(beforeEach())
test.after(after())
test('Some test name', async (t) => {
/* … */
})
// …
And run plugin tests with yarn test
on the command line.
You can also ensure your plugin does not break the server using the following command with stelace-server:
STELACE_PLUGINS_PATHS=/path/to/local/plugin/repo yarn test:server
Note: you can make use of npm explore
to use this from within your plugin repository with stelace-server installed as a devDependency.
During continuous integration with circleCI:
- missing
INSTALLED_PLUGINS
are automatically installed usingyarn plugins:install --save
script, which updates package.json before building Docker image. - After build,
yarn plugins:prepare
rewrites somerequire('stelace-server')
calls to run all of server and plugin tests with local server before ending CI process.
To support private plugins, Dockerfile.prod
is configured to accept SSH key from ssh-agent as a secret during circleCI build.
This way it does not leak into any Docker image layer.
Please refer to .circleci/config.yml
file for more details.