git ssb

4+

Dominic / scuttlebot



Commit 604f9f4ad70a87889f3bbc205e28ceb448c4bd84

implement plugin file:name mapping, as discussed in #408

Dominic Tarr committed on 6/9/2017, 4:31:54 AM
Parent: 95671f8a1c271f96a96d605f9cc83598e0a7f337

Files changed

plugins/plugins.jschanged
plugins/plugins.jsView
@@ -73,9 +73,9 @@
7373 // write to disc
7474 fs.writeFileSync(cfgPath, JSON.stringify(existingConfig, null, 2), 'utf-8')
7575 }
7676
77- return {
77+ return {
7878 install: valid.source(function (pluginName, opts) {
7979 var p = pushable()
8080 var dryRun = opts && opts['dry-run']
8181 var from = opts && opts.from
@@ -173,13 +173,19 @@
173173 // iterate all modules
174174 var nodeModulesPath = path.join(config.path, 'node_modules')
175175 //instead of testing all plugins, only load things explicitly
176176 //enabled in the config
177- for(var k in config.plugins) {
178- if(config.plugins[k]) {
179- if (createSbot.plugins.some(plug => plug.name === k))
180- throw new Error('already loaded plugin named:'+k)
181- var plugin = require(path.join(nodeModulesPath, k))
177+ for(var module_name in config.plugins) {
178+ if(config.plugins[module_name]) {
179+ var name = config.plugins[module_name]
180+ if(name === true)
181+ name = /^ssb-/.test(module_name) ? module_name.substring(4) : module_name
182+
183+ if (createSbot.plugins.some(plug => plug.name === name))
184+ throw new Error('already loaded plugin named:'+name)
185+ var plugin = require(path.join(nodeModulesPath, module_name))
186+ if(plugin.name !== name)
187+ throw new Error('plugin at:'+module_name+' expected name:'+name+' but had:'+plugin.name)
182188 assertSbotPlugin(plugin)
183189 createSbot.use(plugin)
184190 }
185191 }
@@ -209,8 +215,4 @@
209215 return true
210216 }
211217
212218
213-
214-
215-
216-

Built with git-ssb-web