Commit 604f9f4ad70a87889f3bbc205e28ceb448c4bd84
implement plugin file:name mapping, as discussed in #408
Dominic Tarr committed on 6/9/2017, 4:31:54 AMParent: 95671f8a1c271f96a96d605f9cc83598e0a7f337
Files changed
plugins/plugins.js | changed |
plugins/plugins.js | ||
---|---|---|
@@ -73,9 +73,9 @@ | ||
73 | 73 | // write to disc |
74 | 74 | fs.writeFileSync(cfgPath, JSON.stringify(existingConfig, null, 2), 'utf-8') |
75 | 75 | } |
76 | 76 | |
77 | - return { | |
77 | + return { | |
78 | 78 | install: valid.source(function (pluginName, opts) { |
79 | 79 | var p = pushable() |
80 | 80 | var dryRun = opts && opts['dry-run'] |
81 | 81 | var from = opts && opts.from |
@@ -173,13 +173,19 @@ | ||
173 | 173 | // iterate all modules |
174 | 174 | var nodeModulesPath = path.join(config.path, 'node_modules') |
175 | 175 | //instead of testing all plugins, only load things explicitly |
176 | 176 | //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) | |
182 | 188 | assertSbotPlugin(plugin) |
183 | 189 | createSbot.use(plugin) |
184 | 190 | } |
185 | 191 | } |
@@ -209,8 +215,4 @@ | ||
209 | 215 | return true |
210 | 216 | } |
211 | 217 | |
212 | 218 | |
213 | - | |
214 | - | |
215 | - | |
216 | - |
Built with git-ssb-web