tooltwist
Version:
Tooltwist Command Line Interface
61 lines (52 loc) • 1.82 kB
JavaScript
var Log = require('./log');
exports.findPlugin = function(mode) {
//console.log('plugin.findPlugin(' + mode + ')')
// Look for a plugin
var plugin = null;
var pluginPath = __dirname + '/../plugins/' + mode + '/' + mode;
//console.log('pluginPath=' + pluginPath)
try {
plugin = require(pluginPath);
} catch (e) {
console.log('ERROR IS ', e)
var unknownPluginError = 'Error: Cannot find module \'' + pluginPath + '\'';
if (e == unknownPluginError) {
Log.fatalError('Unknown mode \'' + mode + '\'.')
} else {
console.log(e)
Log.fatalError('Error loading plugin for mode \'' + mode + '\'.');
}
process.exit(1);
}
//Log.log('Using Plugin ' + pluginPath + '.js')
// Check the plugin has the required methods
//ZZZ
if (typeof(plugin.init) != 'function') {
Log.fatalError('Plugin is missing function init()')
}
if (typeof(plugin.commandLineInit) != 'function') {
Log.fatalError('Plugin is missing function commandLineInit()')
}
if (typeof(plugin.beforePhase1) != 'function') {
Log.fatalError('Plugin is missing function beforePhase1()')
}
if (typeof(plugin.tomcatRunning) != 'function') {
Log.fatalError('Plugin is missing function tomcatRunning()')
}
if (typeof(plugin.beforePhase2) != 'function') {
Log.fatalError('Plugin is missing function beforePhase2()')
}
if (typeof(plugin.afterPhase2) != 'function') {
Log.fatalError('Plugin is missing function afterPhase2()')
}
if (typeof(plugin.afterPhase1) != 'function') {
Log.fatalError('Plugin is missing function afterPhase1()')
}
if (typeof(plugin.createExampleTemplates) != 'function') {
Log.fatalError('Plugin is missing function createExampleTemplates()')
}
// Initialize the plugin
// We give it a path back here so it can find Log, Config, etc.
plugin.init(__dirname);
return plugin;
}