Commit 04c856a1719140d352b6585b40d1c34edba1d0e0
add --extra-plugin cli flag
Henry committed on 9/17/2018, 7:50:30 AMParent: 18d14f4199837cdee84531b77b1c5e083944bbc1
Files changed
README.md | changed |
examples/service-discovery.js | deleted |
examples/service-discovery/index.js | added |
server.js | changed |
README.md | ||
---|---|---|
@@ -67,4 +67,23 @@ | ||
67 | 67 … | |
68 | 68 … | ``` |
69 | 69 … | $ npm install |
70 | 70 … | ``` |
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.js | ||
---|---|---|
@@ -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.js | ||
---|---|---|
@@ -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.js | |||
---|---|---|---|
@@ -74,13 +74,23 @@ | |||
74 | 74 … | manifest.plugins.forEach(plugin => createSbot.use(require(plugin))) | |
75 | 75 … | } | |
76 | 76 … | } | |
77 | 77 … | ||
78 … | + // from customConfig.plugins | ||
78 | 79 … | if (Array.isArray(customPluginPaths)) { | |
79 | 80 … | console.log('loading custom plugins: ', customPluginPaths.join(', ')) | |
80 | 81 … | customPluginPaths.forEach(plugin => createSbot.use(require(plugin))) | |
81 | 82 … | } | |
82 | 83 … | ||
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 … | + | ||
83 | 93 … | // start server | |
84 | 94 … | const server = createSbot(config) | |
85 | 95 … | ||
86 | 96 … | // write RPC manifest to ~/.ssb/manifest.json |
Built with git-ssb-web