/* global __appdir */ const fs = require('fs'); const path = require('path'); class ExternalBackends { getBackends() { var files = fs.readdirSync(path.join(__appdir, 'lib', 'external-backends', 'backends')); return files; } getCredentials() { return "If this method gets called the backend class has NOT IMPLEMENTED the getCredentials method!"; } getInstance(type) { const bList = this.getBackends(); const bType = type + '-backend.js'; // Check if it's a valid backend type. if (bList.indexOf(bType) == -1) { console.log(bType + " is not a valid backend type."); return null; } const backend = new (require(path.join(__appdir, 'lib', 'external-backends', 'backends', bType)))(); return backend; } } module.exports = ExternalBackends;