1+ import { readFileSync } from 'fs'
2+
13const path = require ( 'path' )
24let seoConfig = require ( 'vuefront/seo' ) . default
35const _ = require ( 'lodash' )
46const ApolloClient = require ( 'apollo-boost' ) . default
57require ( 'isomorphic-fetch' )
68const ampify = require ( './plugins/ampify' )
9+ var fs = require ( 'fs' ) ;
10+
11+ const readConfigFile = ( path ) => {
12+ const result = { }
13+ try {
14+ var filename = require . resolve ( path ) ;
15+ const configContent = fs . readFileSync ( filename , 'utf8' ) ;
16+ let matched = / c s s .* : [ \s \n \r ] + \{ ( [ ^ { ] + ) \} / . exec ( configContent )
17+ if ( ! _ . isEmpty ( matched ) ) {
18+ const cssConfig =
19+ matched [ 1 ]
20+ . replace ( / \s \n / , '' )
21+ . split ( ',' )
22+ . map ( ( str ) =>
23+ str
24+ . split ( ':' )
25+ . map ( strV =>
26+ strV
27+ . trim ( )
28+ . replace ( / \' / g, '' )
29+ )
30+ ) . reduce ( ( accumulator , currentValue ) => {
31+ accumulator [ currentValue [ 0 ] ] = currentValue [ 1 ]
32+ return accumulator
33+ } , { } )
34+
35+ result . css = cssConfig
36+ }
37+ matched = / t h e m e : \' ( .* ) \' / . exec ( configContent )
38+ if ( ! _ . isEmpty ( matched ) ) {
39+ result . theme = matched [ 1 ]
40+ }
41+ } catch ( e ) {
42+ }
43+
44+ return result
45+ }
46+
47+ const mergeConfig = ( objValue , srcValue ) => {
48+ if ( _ . isArray ( objValue ) ) {
49+ return objValue . concat ( srcValue )
50+ } else if ( _ . isObject ( objValue ) ) {
51+ return _ . merge ( objValue , srcValue )
52+ } else {
53+ return srcValue
54+ }
55+ }
756
857export default async function vuefrontModule ( _moduleOptions ) {
958 const isNuxtVersion2 = this . options . build . transpile
@@ -159,6 +208,17 @@ export default async function vuefrontModule(_moduleOptions) {
159208 src : defaultRouter
160209 } )
161210
211+ let themeOptions = readConfigFile ( 'vuefront' )
212+
213+ const config = readConfigFile ( this . options . rootDir + '/vuefront.config.js' )
214+
215+ if ( typeof config . theme !== 'undefined' ) {
216+ const customThemeOptions = readConfigFile ( config . theme )
217+ themeOptions = _ . mergeWith ( themeOptions , customThemeOptions , mergeConfig )
218+ }
219+
220+ themeOptions = _ . mergeWith ( themeOptions , config , mergeConfig )
221+
162222 this . addPlugin ( {
163223 fileName : 'vuefront.js' ,
164224 src : path . resolve ( __dirname , './plugin.js' ) ,
@@ -167,7 +227,8 @@ export default async function vuefrontModule(_moduleOptions) {
167227 debug : this . options . dev ,
168228 browserBaseURL,
169229 baseURL,
170- pages
230+ pages,
231+ themeOptions
171232 }
172233 } )
173234
0 commit comments