2015-10-06 16:36:56 +03:00
|
|
|
/**
|
|
|
|
* Dependencies
|
|
|
|
*/
|
|
|
|
|
2015-10-13 14:55:24 +03:00
|
|
|
var readThemes = require('./read-themes'),
|
2015-10-06 16:36:56 +03:00
|
|
|
Promise = require('bluebird'),
|
2015-11-12 15:29:45 +03:00
|
|
|
_ = require('lodash'),
|
|
|
|
i18n = require('../i18n');
|
2015-10-06 16:36:56 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Validate themes:
|
|
|
|
*
|
|
|
|
* 1. Check if theme has package.json
|
|
|
|
*/
|
|
|
|
|
|
|
|
function validateThemes(dir) {
|
|
|
|
var result = {
|
|
|
|
warnings: [],
|
|
|
|
errors: []
|
|
|
|
};
|
|
|
|
|
2015-10-13 14:55:24 +03:00
|
|
|
return readThemes(dir)
|
2015-10-06 16:36:56 +03:00
|
|
|
.tap(function (themes) {
|
|
|
|
_.each(themes, function (theme, name) {
|
|
|
|
var hasPackageJson, warning;
|
|
|
|
|
2015-10-28 17:13:54 +03:00
|
|
|
hasPackageJson = theme['package.json'] !== undefined;
|
2015-10-06 16:36:56 +03:00
|
|
|
|
|
|
|
if (!hasPackageJson) {
|
|
|
|
warning = {
|
2015-11-12 15:29:45 +03:00
|
|
|
message: i18n.t('errors.utils.validatethemes.themeWithNoPackage.message'),
|
|
|
|
context: i18n.t('errors.utils.validatethemes.themeWithNoPackage.context', {name: name}),
|
|
|
|
help: i18n.t('errors.utils.validatethemes.themeWithNoPackage.help', {url: 'http://docs.ghost.org/themes/'})
|
2015-10-06 16:36:56 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
result.warnings.push(warning);
|
|
|
|
}
|
2015-10-28 17:13:54 +03:00
|
|
|
|
|
|
|
// if package.json is `null`, it means that it exists
|
|
|
|
// but JSON.parse failed (invalid json syntax)
|
|
|
|
if (hasPackageJson && theme['package.json'] === null) {
|
|
|
|
warning = {
|
2015-11-12 15:29:45 +03:00
|
|
|
message: i18n.t('errors.utils.validatethemes.malformedPackage.message'),
|
|
|
|
context: i18n.t('errors.utils.validatethemes.malformedPackage.context', {name: name}),
|
|
|
|
help: i18n.t('errors.utils.validatethemes.malformedPackage.help', {url: 'http://docs.ghost.org/themes/'})
|
2015-10-28 17:13:54 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
result.warnings.push(warning);
|
|
|
|
}
|
2015-10-06 16:36:56 +03:00
|
|
|
});
|
|
|
|
})
|
|
|
|
.then(function () {
|
|
|
|
var hasNotifications = result.warnings.length || result.errors.length;
|
|
|
|
|
|
|
|
if (hasNotifications) {
|
|
|
|
return Promise.reject(result);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Expose `validateThemes`
|
|
|
|
*/
|
|
|
|
|
|
|
|
module.exports = validateThemes;
|