Ghost/core/server/services/themes/loader.js
Hannah Wolfe 82ef700d81
Refactored theme service to use async/await
refs: https://github.com/TryGhost/Team/issues/831

- We prefer async/await over promise chains because it makes the code much more readable
- the Theme Service needs further work and this should make that work much easier
   - e.g. https://github.com/TryGhost/Team/issues/831
   - e.g. fixing up the index.js file
2021-07-07 12:28:55 +01:00

23 lines
760 B
JavaScript

const debug = require('@tryghost/debug')('themes');
const packageJSON = require('@tryghost/package-json');
const config = require('../../../shared/config');
const themeList = require('./list');
const loadAllThemes = async function loadAllThemes() {
const themes = await packageJSON.readPackages(config.getContentPath('themes'));
debug('loading themes', Object.keys(themes));
themeList.init(themes);
};
const loadOneTheme = async function loadOneTheme(themeName) {
const theme = await packageJSON.readPackage(config.getContentPath('themes'), themeName);
debug('loaded one theme', themeName);
return themeList.set(themeName, theme[themeName]);
};
module.exports = {
loadAllThemes: loadAllThemes,
loadOneTheme: loadOneTheme
};