mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-23 19:02:29 +03:00
20fec74c73
closes #5492 - remove core/server/require-tree.js and split it into modules - add read-directory module to recursively read directories - add validate-themes module to scan themes and return errors/warnings - add parse-package-json module to parse json and validate requirements - rewrite core/server/models/index.js to manually require models
53 lines
1.2 KiB
JavaScript
53 lines
1.2 KiB
JavaScript
/**
|
|
* Dependencies
|
|
*/
|
|
|
|
var readDirectory = require('./read-directory'),
|
|
Promise = require('bluebird'),
|
|
_ = require('lodash');
|
|
|
|
/**
|
|
* Validate themes:
|
|
*
|
|
* 1. Check if theme has package.json
|
|
*/
|
|
|
|
function validateThemes(dir) {
|
|
var result = {
|
|
warnings: [],
|
|
errors: []
|
|
};
|
|
|
|
return readDirectory(dir)
|
|
.tap(function (themes) {
|
|
_.each(themes, function (theme, name) {
|
|
var hasPackageJson, warning;
|
|
|
|
hasPackageJson = !!theme['package.json'];
|
|
|
|
if (!hasPackageJson) {
|
|
warning = {
|
|
message: 'Found a theme with no package.json file',
|
|
context: 'Theme name: ' + name,
|
|
help: 'This will be required in future. Please see http://docs.ghost.org/themes/'
|
|
};
|
|
|
|
result.warnings.push(warning);
|
|
}
|
|
});
|
|
})
|
|
.then(function () {
|
|
var hasNotifications = result.warnings.length || result.errors.length;
|
|
|
|
if (hasNotifications) {
|
|
return Promise.reject(result);
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Expose `validateThemes`
|
|
*/
|
|
|
|
module.exports = validateThemes;
|