2017-03-13 14:44:44 +03:00
|
|
|
var _ = require('lodash'),
|
|
|
|
themeList = require('./list'),
|
|
|
|
packages = require('../utils/packages'),
|
|
|
|
settingsCache = require('../settings/cache');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Provides a JSON object which can be returned via the API
|
|
|
|
*
|
|
|
|
* @param {string} [name] - the theme to output
|
|
|
|
* @param {object} [checkedTheme] - a theme result from gscan
|
|
|
|
* @return {*}
|
|
|
|
*/
|
|
|
|
module.exports = function toJSON(name, checkedTheme) {
|
|
|
|
var themeResult, toFilter;
|
|
|
|
|
|
|
|
if (!name) {
|
|
|
|
toFilter = themeList.getAll();
|
|
|
|
// Default to returning the full list
|
2017-04-24 20:41:00 +03:00
|
|
|
themeResult = packages.filterPackages(toFilter, settingsCache.get('active_theme'));
|
2017-03-13 14:44:44 +03:00
|
|
|
} else {
|
|
|
|
// If we pass in a gscan result, convert this instead
|
|
|
|
toFilter = {};
|
|
|
|
toFilter[name] = themeList.get(name);
|
|
|
|
|
2017-04-24 20:41:00 +03:00
|
|
|
themeResult = packages.filterPackages(toFilter, settingsCache.get('active_theme'));
|
2017-03-13 14:44:44 +03:00
|
|
|
|
|
|
|
if (checkedTheme && checkedTheme.results.warning.length > 0) {
|
|
|
|
themeResult[0].warnings = _.cloneDeep(checkedTheme.results.warning);
|
|
|
|
}
|
2017-05-31 19:42:42 +03:00
|
|
|
|
|
|
|
if (checkedTheme && checkedTheme.results.error.length > 0) {
|
|
|
|
themeResult[0].errors = _.cloneDeep(checkedTheme.results.error);
|
|
|
|
}
|
2017-03-13 14:44:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return {themes: themeResult};
|
|
|
|
};
|