mirror of
https://github.com/strapi/strapi.git
synced 2025-07-19 07:02:26 +00:00
35 lines
813 B
JavaScript
35 lines
813 B
JavaScript
'use strict';
|
|
|
|
const VError = require('verror');
|
|
|
|
/**
|
|
* Requires a database connector
|
|
* @param {string} connector connector name
|
|
* @param {DatabaseManager} databaseManager reference to the database manager
|
|
*/
|
|
module.exports = function requireConnector(connector) {
|
|
if (!connector) {
|
|
throw new VError({ name: 'ConnectorError' }, 'initialize connector without name');
|
|
}
|
|
|
|
try {
|
|
require.resolve(`@strapi/connector-${connector}`);
|
|
} catch (error) {
|
|
throw new VError(
|
|
{ name: 'ConnectorError', cause: error },
|
|
'connector "%s" not found',
|
|
connector
|
|
);
|
|
}
|
|
|
|
try {
|
|
return require(`@strapi/connector-${connector}`);
|
|
} catch (error) {
|
|
throw new VError(
|
|
{ name: 'ConnectorError', cause: error },
|
|
'initialize connector "%s"',
|
|
connector
|
|
);
|
|
}
|
|
};
|