Skip to content

Commit 3727153

Browse files
meteorlxyulivz
authored andcommitted
refactor: root mixins injection (#423)
1 parent 21f939f commit 3727153

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

Diff for: lib/app/util.js

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
export function injectMixins (options, mixins) {
2+
if (!options.mixins) {
3+
options.mixins = []
4+
}
5+
options.mixins.push(...mixins)
6+
}
7+
18
export function pathToComponentName (path) {
29
if (path.charAt(path.length - 1) === '/') {
310
return `page${path.replace(/\//g, '-') + 'index'}`

Diff for: lib/code/injectRootMixins.js

-8
This file was deleted.

Diff for: lib/prepare.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -342,14 +342,13 @@ async function genRoutesFile ({ siteData: { pages }, sourceDir, pageFiles }) {
342342
component: ThemeNotFound
343343
}`
344344

345-
const injectRootMixins = await fs.readFile(path.resolve(__dirname, 'code/injectRootMixins.js'), 'utf-8')
346-
347345
return (
348346
`import ThemeLayout from '@themeLayout'\n` +
349-
`import ThemeNotFound from '@themeNotFound'\n\n` +
350-
`${injectRootMixins}\n` +
351-
`injectRootMixins(ThemeLayout)\n` +
352-
`injectRootMixins(ThemeNotFound)\n\n` +
347+
`import ThemeNotFound from '@themeNotFound'\n` +
348+
`import { injectMixins } from '@app/util'\n` +
349+
`import rootMixins from '@app/root-mixins'\n\n` +
350+
`injectMixins(ThemeLayout, rootMixins)\n` +
351+
`injectMixins(ThemeNotFound, rootMixins)\n\n` +
353352
`export const routes = [${pages.map(genRoute).join(',')}${notFoundRoute}\n]`
354353
)
355354
}

0 commit comments

Comments
 (0)