Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# ssb-plugins2
# ssb-plugins

proof of concept muxrpc plugins as separate process

Expand Down
41 changes: 41 additions & 0 deletions help.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

var Module = {
single: 'module',
args: {
module: {
type: 'string',
description: 'a module@version-range string'
}
}
}

function desc(d, type) {
return Object.assign({
description: d,
type: type
}, Module)
}

module.exports = {
description: 'manage ssb plugins',
commands: {
install: desc('install a plugin', 'source'),
uninstall: desc('remove a plugin', 'source'),
enable: desc('enable an installed plugin, must restart ssb-server afterwards', 'async'),
disable: desc('disable an installed plugin (without uninstalling), must restart ssb-server afterwards', 'async'),
}
}














31 changes: 28 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,21 @@ var mdm = require('mdmanifest')
var explain = require('explain-error')
var valid = require('muxrpc-validation')({})

function isObject(o) {
return o && 'object' === typeof o
}

module.exports = {
name: 'plugins',
version: '1.0.0',
manifest: mdm.manifest(fs.readFileSync(path.join(__dirname, 'api.md'), 'utf8')),
manifest: {
install: 'source',
uninstall: 'source',
enable: 'async',
disable: 'async',
help: 'sync'
}
//mdm.manifest(fs.readFileSync(path.join(__dirname, 'api.md'), 'utf8')),
permissions: {
master: {allow: ['install', 'uninstall', 'enable', 'disable']}
},
Expand All @@ -30,6 +41,7 @@ module.exports = {
// helper to enable/disable plugins
function configPluginEnabled (b) {
return function (pluginName, cb) {
if(isObject(pluginName)) pluginName = pluginName.module
checkInstalled(pluginName, function (err) {
if (err) return cb(err)

Expand Down Expand Up @@ -58,6 +70,7 @@ module.exports = {

// write the plugin config to ~/.ssb/config
function writePluginConfig (pluginName, value) {

var cfgPath = path.join(config.path, 'config')
// load ~/.ssb/config
let existingConfig
Expand Down Expand Up @@ -86,6 +99,7 @@ module.exports = {

return {
install: valid.source(function (pluginName, opts) {
if(isObject(pluginName)) pluginName = pluginName.module
var p = pushable()
var dryRun = opts && opts['dry-run']
var from = opts && opts.from
Expand Down Expand Up @@ -157,6 +171,7 @@ module.exports = {
])
}, 'string', 'object?'),
uninstall: valid.source(function (pluginName, opts) {
if(isObject(pluginName)) pluginName = pluginName.module
var p = pushable()
if (!pluginName || typeof pluginName !== 'string')
return pull.error(new Error('plugin name is required'))
Expand All @@ -174,7 +189,8 @@ module.exports = {
return p
}, 'string', 'object?'),
enable: valid.async(configPluginEnabled(true), 'string'),
disable: valid.async(configPluginEnabled(false), 'string')
disable: valid.async(configPluginEnabled(false), 'string'),
help: function () { return require('./help') }
}
}
}
Expand All @@ -192,7 +208,14 @@ module.exports.loadUserPlugins = function (createSsbServer, config) {

if (createSsbServer.plugins.some(plug => plug.name === name))
throw new Error('already loaded plugin named:'+name)
var plugin = require(path.join(nodeModulesPath, module_name))
var pkg = require(path.join(nodeModulesPath, module_name, 'package.json'))
var plugin
if(pkg.ssb && pkg.ssb.outOfProcess) {
plugin = load(path.join(nodeModulesPath, module_name), name)
} else {
plugin = require(path.join(nodeModulesPath, module_name))
}

if(!plugin || plugin.name !== name)
throw new Error('plugin at:'+module_name+' expected name:'+name+' but had:'+(plugin||{}).name)
assertSsbServerPlugin(plugin)
Expand Down Expand Up @@ -225,3 +248,5 @@ function validatePluginName (name) {
return true
}



4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "ssb-plugins2",
"name": "ssb-plugins",
"description": "",
"version": "0.0.0",
"homepage": "https://github.com/dominictarr/ssb-plugins2",
Expand All @@ -15,7 +15,6 @@
"muxrpc": "^6.4.0",
"muxrpc-validation": "^3.0.0",
"mv": "^2.1.1",
"nimraf": "^1.1.0",
"osenv": "^0.1.5",
"pull-cat": "^1.1.11",
"pull-many": "^1.0.8",
Expand All @@ -35,3 +34,4 @@
"author": "Dominic Tarr <dominic.tarr@gmail.com> (http://dominictarr.com)",
"license": "MIT"
}

31 changes: 0 additions & 31 deletions run-standalone.js

This file was deleted.