-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
validate.js
42 lines (36 loc) · 1.44 KB
/
validate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var Promise = require('bluebird'),
config = require('../../config'),
common = require('../../lib/common'),
checkTheme;
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');
if (isZip) {
checkPromise = gscan.checkZip(theme, {
keepExtractedDir: true
});
} else {
checkPromise = gscan.check(theme.path);
}
return checkPromise
.then(function resultHandler(checkedTheme) {
checkedTheme = gscan.format(checkedTheme, {
onlyFatalErrors: config.get('env') === 'production'
});
// CASE: production and no fatal errors
// CASE: development returns fatal and none fatal errors, theme is only invalid if fatal errors
if (!checkedTheme.results.error.length ||
config.get('env') === 'development' && !checkedTheme.results.hasFatalErrors) {
return checkedTheme;
}
return Promise.reject(new common.errors.ThemeValidationError({
message: common.i18n.t('errors.api.themes.invalidTheme'),
errorDetails: checkedTheme.results.error,
context: checkedTheme
}));
}).catch(function (error) {
return Promise.reject(error);
});
};
module.exports.check = checkTheme;