Skip to content

Commit

Permalink
refactor: root mixins injection (#423)
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy authored and ulivz committed May 12, 2018
1 parent 21f939f commit 3727153
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
7 changes: 7 additions & 0 deletions lib/app/util.js
Original file line number Diff line number Diff line change
@@ -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'}`
Expand Down
8 changes: 0 additions & 8 deletions lib/code/injectRootMixins.js

This file was deleted.

11 changes: 5 additions & 6 deletions lib/prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]`
)
}
Expand Down

0 comments on commit 3727153

Please sign in to comment.