git ssb

1+

mixmix / scuttle-shell



Commit 04c856a1719140d352b6585b40d1c34edba1d0e0

add --extra-plugin cli flag

Henry committed on 9/17/2018, 7:50:30 AM
Parent: 18d14f4199837cdee84531b77b1c5e083944bbc1

Files changed

README.mdchanged
examples/service-discovery.jsdeleted
examples/service-discovery/index.jsadded
server.jschanged
README.mdView
@@ -67,4 +67,23 @@
6767
6868 ```
6969 $ npm install
7070 ```
71 +
72 +### Plugins
73 +
74 +scuttle-shell supports mutliple ways to extend the sbot that it runs with pluigns (like [ssb-chess-db](https://github.com/Happy0/ssb-chess-db) or [ssb-query](https://github.com/dominictarr/ssb-query)).
75 +
76 +First of all, it supports and loads the plugins that were installed by running `sbot plugins.install ...`.
77 +These are stored under `$HOME/.ssb/node_modules`.
78 +
79 +Additonally, you can either pass the file paths to the API constructor by adding a `plugins` field to the object you pass to `.start()`. Check out `examples/launch_sbot_custom_plugin.js` to see it in action.
80 +
81 +Alternativly you can use the command-line flag of `scuttleshell`, named `--extra-plugins`. i.e. `scuttleshell --extra-plugin path/to/plugin1 --extra-plugin path/to/plugin2`. Please not that these are not installed or persisted, you need to take care of that.
82 +
83 +If you don't want to store them in the `$HOME/.ssb` folder, there is also the option to create a `scuttleshell.json` file next to your custom scuttle-shell and set a `plugins` array inside it.
84 +
85 +```json
86 +{
87 + 'plugins': ['path/to/plug1','path/to/plug2','path/to/plug3']
88 +}
89 +```
examples/service-discovery.jsView
@@ -1,14 +1,0 @@
1-module.exports = {
2- name: 'server-discovery',
3- version: '1.0.0',
4- init: function (sbot) {
5- sbot.ws.use(function (req, res, next) {
6- res.setHeader('Access-Control-Allow-Origin', '*')
7- if (req.url === '/get-address') {
8- res.end(sbot.ws.getAddress())
9- } else {
10- next()
11- }
12- })
13- }
14-}
examples/service-discovery/index.jsView
@@ -1,0 +1,14 @@
1 +module.exports = {
2 + name: 'server-discovery',
3 + version: '1.0.0',
4 + init: function (sbot) {
5 + sbot.ws.use(function (req, res, next) {
6 + res.setHeader('Access-Control-Allow-Origin', '*')
7 + if (req.url === '/get-address') {
8 + res.end(sbot.ws.getAddress())
9 + } else {
10 + next()
11 + }
12 + })
13 + }
14 +}
server.jsView
@@ -74,13 +74,23 @@
7474 manifest.plugins.forEach(plugin => createSbot.use(require(plugin)))
7575 }
7676 }
7777
78 + // from customConfig.plugins
7879 if (Array.isArray(customPluginPaths)) {
7980 console.log('loading custom plugins: ', customPluginPaths.join(', '))
8081 customPluginPaths.forEach(plugin => createSbot.use(require(plugin)))
8182 }
8283
84 + // --extra-plugin
85 + const args = minimist(process.argv.slice(1))
86 + const extraPlugin = args['extra-plugin']
87 + if (typeof extraPlugin === 'string') { // one
88 + createSbot.use(require(extraPlugin))
89 + } else if (extraPlugin instanceof Array) { // multiple
90 + extraPlugin.forEach((plugPath) => createSbot.use(require(plugPath)))
91 + }
92 +
8393 // start server
8494 const server = createSbot(config)
8595
8696 // write RPC manifest to ~/.ssb/manifest.json

Built with git-ssb-web