@@ -3,23 +3,32 @@ import VueI18n from 'vue-i18n'
33import ApolloClient from "apollo-boost" ;
44import _ from 'lodash'
55import 'isomorphic-fetch'
6- < %
7- const vfresolver = ( options ) => {
8- if ( typeof options === 'string' ) {
9- return `(require('${ options } ').default ? require('${ options } ').default:require('${ options } '))`
10- } else if ( typeof options . el !== 'undefined' ) {
11- return `require('${ options . package } ')['${ options . el } ']`
12- } else if ( typeof options . path !== 'undefined' ) {
13- let result = `require('${ options . package } ')`
14- for ( const key in options . path ) {
15- result += `['${ options . path [ key ] } ']`
16- }
17- return result
6+ import mainConfig from 'vuefront'
7+ import userConfig from '~/vuefront.config'
8+ < % if ( options . theme !== 'default' ) { % >
9+ import themeConfig from '<%= options.theme %>'
10+ < % } % >
11+
12+ const mergeConfig = ( objValue , srcValue ) => {
13+ if ( _ . isArray ( objValue ) ) {
14+ return objValue . concat ( srcValue )
15+ } else if ( _ . isObject ( objValue ) ) {
16+ return _ . merge ( objValue , srcValue )
17+ } else {
18+ return srcValue
1819 }
1920}
20- % >
21- < % for ( var key in options . vuefrontConfig . css ) { % >
22- import '<%= options.vuefrontConfig.css[key] %>' < % } % >
21+
22+ let themeOptions = mainConfig
23+
24+ if ( typeof themeConfig !== 'undefined' ) {
25+ themeOptions = _ . mergeWith ( themeOptions , themeConfig , mergeConfig )
26+ }
27+ themeOptions = _ . mergeWith ( themeOptions , userConfig , mergeConfig )
28+
29+ for ( var key in themeOptions . css ) {
30+ themeOptions . css [ key ] ( )
31+ }
2332
2433Vue . use ( VueI18n )
2534
@@ -54,15 +63,15 @@ export const init = (ctx, inject) => {
5463function loadLocaleMessages ( options ) {
5564 const locales = require . context ( `~/locales` , true , / \. j s o n $ / )
5665 const messages = { }
57-
58- < % for ( var key in options . vuefrontConfig . locales ) { % >
59- if ( _ . isUndefined ( messages [ '<%=key%>' ] ) ) {
60- messages [ '<%=key%>' ] = { }
66+
67+ for ( var key in options . locales ) {
68+ if ( _ . isUndefined ( messages [ key ] ) ) {
69+ messages [ key ] = { }
70+ }
71+ for ( var key2 in options . locales [ key ] ) {
72+ messages [ key ] = _ . merge ( { } , messages [ key ] , options . locales [ key ] [ key2 ] )
73+ }
6174 }
62- < % for ( var key2 in options . vuefrontConfig . locales [ key ] ) { % >
63- messages [ '<%=key%>' ] = _ . merge ( { } , messages [ '<%=key%>' ] , < %= vfresolver ( options . vuefrontConfig . locales [ key ] [ key2 ] ) % > )
64- < % } % >
65- < % } % >
6675 locales . keys ( ) . forEach ( key => {
6776 const local = / ^ .\/ ( [ a - z A - Z - ] + ) \/ / . exec ( key ) [ 1 ]
6877 if ( _ . isUndefined ( messages [ local ] ) ) {
@@ -77,16 +86,10 @@ function loadLocaleMessages(options) {
7786 return messages
7887}
7988
80- < % for ( var key in options . vuefrontConfig . plugins ) { % >
81- import plugin < %= key % > from '<%= options.vuefrontConfig.plugins[key] %>'
82- < % } % >
83-
8489export default async ( ctx , inject ) => {
90+
8591 init ( ctx , inject )
86- const options = < %= JSON . stringify ( options . vuefrontConfig ) % >
87- < % for ( var key in options . vuefrontConfig . plugins ) { % >
88- await plugin < %= key % > ( ctx )
89- < % } % >
92+
9093 const components = {
9194 element : { } ,
9295 template : { } ,
@@ -101,34 +104,42 @@ export default async (ctx, inject) => {
101104 opts . preserveState = false
102105 }
103106 }
104- < % for ( var key in options . vuefrontConfig . store ) {
105- if ( typeof options . vuefrontConfig . store [ key ] . module !== 'undefined' ) { % >
106- ctx . store . registerModule ( < %= JSON . stringify ( options . vuefrontConfig . store [ key ] . path ) % > , { namespaced : true , ...< %= vfresolver ( options . vuefrontConfig . store [ key ] . module ) % > } , opts ) < % } else { % >
107- ctx . store . registerModule ( < %= JSON . stringify ( options . vuefrontConfig . store [ key ] . path ) % > , { namespaced : true } , opts ) < % } } % >
108-
109- < % for ( var key in options . vuefrontConfig . atoms ) { % >
110- components [ 'vfA<%= key %>' ] = Vue . component ( 'vfA<%= key %>' , < %= vfresolver ( options . vuefrontConfig . atoms [ key ] ) % > ) < % } % >
111-
112- < % for ( var key in options . vuefrontConfig . molecules ) { % >
113- components [ 'vfM<%= key %>' ] = Vue . component ( 'vfM<%= key %>' , < %= vfresolver ( options . vuefrontConfig . molecules [ key ] ) % > ) < % } % >
114107
115- < % for ( var key in options . vuefrontConfig . organisms ) { % >
116- components [ 'vfO<%= key %>' ] = Vue . component ( 'vfO<%= key %>' , < %= vfresolver ( options . vuefrontConfig . organisms [ key ] ) % > ) < % } % >
108+ for ( var key in themeOptions . store ) {
109+ if ( typeof themeOptions . store [ key ] . module !== 'undefined' ) {
110+ ctx . store . registerModule ( themeOptions . store [ key ] . path , { namespaced : true , ...themeOptions . store [ key ] . module } , opts )
111+ } else {
112+ ctx . store . registerModule ( themeOptions . store [ key ] . path , { namespaced : true } , opts )
113+ }
114+ }
117115
118- < % for ( var key in options . vuefrontConfig . templates ) { % >
119- components [ 'vfT<%= key %>' ] = Vue . component ( 'vfT<%= key %>' , < %= vfresolver ( options . vuefrontConfig . templates [ key ] ) % > ) < % } % >
116+ for ( var key in themeOptions . atoms ) {
117+ components [ `vfA${ key } ` ] = Vue . component ( `vfA${ key } ` , themeOptions . atoms [ key ] )
118+ }
120119
121- < % for ( var key in options . vuefrontConfig . components ) { % >
122- components [ 'vf<%= key %>' ] = Vue . component ( 'vf<%= key %>' , < %= vfresolver ( options . vuefrontConfig . components [ key ] ) % > ) < % } % >
120+ for ( var key in themeOptions . molecules ) {
121+ components [ `vfM${ key } ` ] = Vue . component ( `vfM${ key } ` , themeOptions . molecules [ key ] )
122+ }
123123
124- < % for ( var key in options . vuefrontConfig . modules ) { % >
125- components [ 'vfModule<%= key %>' ] = Vue . component ( 'vfModule<%= key %>' , < %= vfresolver ( options . vuefrontConfig . modules [ key ] ) % > ) < % } % >
124+ for ( var key in themeOptions . organisms ) {
125+ components [ `vfO${ key } ` ] = Vue . component ( `vfO${ key } ` , themeOptions . organisms [ key ] )
126+ }
126127
127- < % for ( var key in options . vuefrontConfig . loaders ) { % >
128- components [ 'vfLoader<%= key %>' ] = Vue . component ( 'vfLoader<%= key %>' , < %= vfresolver ( options . vuefrontConfig . loaders [ key ] ) % > ) < % } % >
128+ for ( var key in themeOptions . templates ) {
129+ components [ `vfT${ key } ` ] = Vue . component ( `vfT${ key } ` , themeOptions . templates [ key ] )
130+ }
131+ for ( var key in themeOptions . components ) {
132+ components [ `vf${ key } ` ] = Vue . component ( `vf${ key } ` , themeOptions . components [ key ] )
133+ }
134+ for ( var key in themeOptions . modules ) {
135+ components [ `vfModule${ key } ` ] = Vue . component ( `vfModule${ key } ` , themeOptions . modules [ key ] )
136+ }
137+ for ( var key in themeOptions . loaders ) {
138+ components [ `vfLoader${ key } ` ] = Vue . component ( `vfLoader${ key } ` , themeOptions . loaders [ key ] )
139+ }
129140
130141 inject ( 'vuefront' , {
131- options,
142+ options : themeOptions ,
132143 components,
133144 baseURL,
134145 get isClient ( ) {
@@ -155,7 +166,7 @@ export default async (ctx, inject) => {
155166
156167 ctx . app . i18n = new VueI18n ( {
157168 locale : ctx . store . getters [ 'common/language/locale' ] ,
158- messages : loadLocaleMessages ( options )
169+ messages : loadLocaleMessages ( themeOptions )
159170 } )
160171
161172}
0 commit comments