From 828d99dc8e99c89a8f4fde42e1dc7e7984766968 Mon Sep 17 00:00:00 2001 From: endiliey Date: Mon, 3 Sep 2018 23:30:13 +0800 Subject: [PATCH] refactor: load theme --- lib/load/index.js | 16 ++-------------- lib/load/theme.js | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 lib/load/theme.js diff --git a/lib/load/index.js b/lib/load/index.js index f31e13eeb5..f5cbbcd7a5 100644 --- a/lib/load/index.js +++ b/lib/load/index.js @@ -1,8 +1,8 @@ -const fs = require('fs-extra'); const path = require('path'); const loadConfig = require('./config'); const loadDocs = require('./docs'); const loadPages = require('./pages'); +const loadTheme = require('./theme'); const {generate} = require('./utils'); const genRoutesConfig = require('./routes'); @@ -34,19 +34,7 @@ module.exports = async function load(siteDir) { const outDir = path.resolve(siteDir, 'build'); // resolve the theme - 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.` - ); - } - }); + const themePath = loadTheme(siteDir); const baseUrl = siteConfig.baseUrl || '/'; diff --git a/lib/load/theme.js b/lib/load/theme.js new file mode 100644 index 0000000000..0aa529c145 --- /dev/null +++ b/lib/load/theme.js @@ -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; +};