refactor: load theme

This commit is contained in:
endiliey 2018-09-03 23:30:13 +08:00
parent 10b1a38762
commit 828d99dc8e
2 changed files with 22 additions and 14 deletions

20
lib/load/theme.js Normal file
View file

@ -0,0 +1,20 @@
const fs = require('fs-extra');
const path = require('path');
module.exports = function loadConfig(siteDir) {
const customThemePath = path.resolve(siteDir, 'theme');
const themePath = fs.existsSync(customThemePath)
? customThemePath
: path.resolve(__dirname, '../theme');
const themeComponents = ['Docs', 'Loading', 'NotFound'];
themeComponents.forEach(component => {
if (!require.resolve(path.join(themePath, component))) {
throw new Error(
`Failed to load ${themePath}/${component}. It does not exist.`
);
}
});
return themePath;
};