2017-02-28 01:30:49 +03:00
|
|
|
var Promise = require('bluebird'),
|
|
|
|
errors = require('../errors'),
|
|
|
|
i18n = require('../i18n'),
|
2017-03-13 14:44:44 +03:00
|
|
|
checkTheme;
|
2017-02-28 01:30:49 +03:00
|
|
|
|
2017-03-13 14:44:44 +03:00
|
|
|
checkTheme = function checkTheme(theme, isZip) {
|
|
|
|
var checkPromise,
|
|
|
|
// gscan can slow down boot time if we require on boot, for now nest the require.
|
|
|
|
gscan = require('gscan');
|
2017-02-28 01:30:49 +03:00
|
|
|
|
2017-03-13 14:44:44 +03:00
|
|
|
if (isZip) {
|
|
|
|
checkPromise = gscan.checkZip(theme, {keepExtractedDir: true});
|
|
|
|
} else {
|
|
|
|
checkPromise = gscan.check(theme.path);
|
2017-02-28 01:30:49 +03:00
|
|
|
}
|
2017-03-13 14:44:44 +03:00
|
|
|
|
|
|
|
return checkPromise.then(function resultHandler(checkedTheme) {
|
|
|
|
checkedTheme = gscan.format(checkedTheme);
|
|
|
|
|
|
|
|
// @TODO improve gscan results
|
|
|
|
if (!checkedTheme.results.error.length) {
|
|
|
|
return checkedTheme;
|
|
|
|
}
|
|
|
|
|
|
|
|
return Promise.reject(new errors.ThemeValidationError({
|
|
|
|
message: i18n.t('errors.api.themes.invalidTheme'),
|
|
|
|
errorDetails: checkedTheme.results.error
|
|
|
|
}));
|
|
|
|
});
|
2017-02-28 01:30:49 +03:00
|
|
|
};
|
|
|
|
|
2017-03-13 14:44:44 +03:00
|
|
|
module.exports.check = checkTheme;
|