0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-02-10 23:36:14 -05:00

ES6 migration: server/adapters/scheduling/utils.js (#9689)

refs #9589
This commit is contained in:
Bill Fienberg 2018-06-14 12:15:12 -05:00 committed by Katharina Irrgang
parent a38998dfc7
commit 960ee2f20e

View file

@ -1,4 +1,4 @@
var _ = require('lodash'), const _ = require('lodash'),
Promise = require('bluebird'), Promise = require('bluebird'),
SchedulingBase = require('./SchedulingBase'), SchedulingBase = require('./SchedulingBase'),
common = require('../../lib/common'), common = require('../../lib/common'),
@ -7,10 +7,8 @@ var _ = require('lodash'),
exports.createAdapter = function (options) { exports.createAdapter = function (options) {
options = options || {}; options = options || {};
var adapter = null, let adapter = null;
activeAdapter = options.active, const {active: activeAdapter, internalPath, contentPath} = options;
internalPath = options.internalPath,
contentPath = options.contentPath;
if (!activeAdapter) { if (!activeAdapter) {
return Promise.reject(new common.errors.IncorrectUsageError({ return Promise.reject(new common.errors.IncorrectUsageError({
@ -29,7 +27,7 @@ exports.createAdapter = function (options) {
adapter = new (require(activeAdapter))(options); adapter = new (require(activeAdapter))(options);
} catch (err) { } catch (err) {
if (err.code !== 'MODULE_NOT_FOUND') { if (err.code !== 'MODULE_NOT_FOUND') {
return Promise.reject(new common.errors.IncorrectUsageError({err: err})); return Promise.reject(new common.errors.IncorrectUsageError({err}));
} }
} }
@ -41,12 +39,12 @@ exports.createAdapter = function (options) {
} catch (err) { } catch (err) {
// CASE: only throw error if module does exist // CASE: only throw error if module does exist
if (err.code !== 'MODULE_NOT_FOUND') { if (err.code !== 'MODULE_NOT_FOUND') {
return Promise.reject(new common.errors.IncorrectUsageError({err: err})); return Promise.reject(new common.errors.IncorrectUsageError({err}));
// CASE: if module not found it can be an error within the adapter (cannot find bluebird for example) // CASE: if module not found it can be an error within the adapter (cannot find bluebird for example)
} else if (err.code === 'MODULE_NOT_FOUND' && err.message.indexOf(contentPath + activeAdapter) === -1) { } else if (err.code === 'MODULE_NOT_FOUND' && err.message.indexOf(contentPath + activeAdapter) === -1) {
return Promise.reject(new common.errors.IncorrectUsageError({ return Promise.reject(new common.errors.IncorrectUsageError({
err: err, err,
help: 'Please check the imports are valid in ' + contentPath + activeAdapter help: `Please check the imports are valid in ${contentPath}${activeAdapter}`
})); }));
} }
} }
@ -60,11 +58,11 @@ exports.createAdapter = function (options) {
// CASE: only throw error if module does exist // CASE: only throw error if module does exist
if (err.code === 'MODULE_NOT_FOUND') { if (err.code === 'MODULE_NOT_FOUND') {
return Promise.reject(new common.errors.IncorrectUsageError({ return Promise.reject(new common.errors.IncorrectUsageError({
message: 'We cannot find your adapter in: ' + contentPath + ' or: ' + internalPath message: `We cannot find your adapter in: ${contentPath} or: ${internalPath}`
})); }));
} }
return Promise.reject(new common.errors.IncorrectUsageError({err: err})); return Promise.reject(new common.errors.IncorrectUsageError({err}));
} }
if (!(adapter instanceof SchedulingBase)) { if (!(adapter instanceof SchedulingBase)) {