| 31 | } |
| 32 | |
| 33 | function _autoload(context, pluginDir, options) { |
| 34 | /* |
| 35 | Reload all of the .js files in the given directory |
| 36 | */ |
| 37 | var sourceFiles = [], |
| 38 | property, |
| 39 | module, |
| 40 | pluginPath; |
| 41 | sourceFiles = find(pluginDir); |
| 42 | |
| 43 | var len = sourceFiles.length; |
| 44 | if (config && config.verbose) { |
| 45 | console.info(len + ' scriptcraft plugins found in ' + pluginDir); |
| 46 | } |
| 47 | |
| 48 | for (var i = 0; i < len; i++) { |
| 49 | pluginPath = sourceFiles[i]; |
| 50 | if (!pluginPath.match(/\.js$/)) { |
| 51 | continue; |
| 52 | } |
| 53 | module = {}; |
| 54 | |
| 55 | try { |
| 56 | module = require(pluginPath, options); |
| 57 | for (property in module) { |
| 58 | /* |
| 59 | all exports in plugins become members of context object |
| 60 | */ |
| 61 | context[property] = module[property]; |
| 62 | } |
| 63 | } catch (e) { |
| 64 | var msg = 'Plugin ' + pluginPath + ' ' + e; |
| 65 | console.error(msg); |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | exports.plugin = _plugin; |
| 70 | exports.autoload = _autoload; |