refactor: root mixins injection (#423)

This commit is contained in:
Liu Xinyu
2018-05-12 15:13:54 +08:00
committed by ULIVZ
parent 21f939f16c
commit 3727153aa3
3 changed files with 12 additions and 14 deletions
+7
View File
@@ -1,3 +1,10 @@
export function injectMixins (options, mixins) {
if (!options.mixins) {
options.mixins = []
}
options.mixins.push(...mixins)
}
export function pathToComponentName (path) {
if (path.charAt(path.length - 1) === '/') {
return `page${path.replace(/\//g, '-') + 'index'}`
-8
View File
@@ -1,8 +0,0 @@
/* eslint-disable */
import rootMixins from '@app/root-mixins'
function injectRootMixins (options) {
if (!options.mixins) {
options.mixins = []
}
options.mixins.push(...rootMixins)
}
+5 -6
View File
@@ -342,14 +342,13 @@ async function genRoutesFile ({ siteData: { pages }, sourceDir, pageFiles }) {
component: ThemeNotFound
}`
const injectRootMixins = await fs.readFile(path.resolve(__dirname, 'code/injectRootMixins.js'), 'utf-8')
return (
`import ThemeLayout from '@themeLayout'\n` +
`import ThemeNotFound from '@themeNotFound'\n\n` +
`${injectRootMixins}\n` +
`injectRootMixins(ThemeLayout)\n` +
`injectRootMixins(ThemeNotFound)\n\n` +
`import ThemeNotFound from '@themeNotFound'\n` +
`import { injectMixins } from '@app/util'\n` +
`import rootMixins from '@app/root-mixins'\n\n` +
`injectMixins(ThemeLayout, rootMixins)\n` +
`injectMixins(ThemeNotFound, rootMixins)\n\n` +
`export const routes = [${pages.map(genRoute).join(',')}${notFoundRoute}\n]`
)
}