11const _ = require ( 'lodash' )
22
3+ let rootPath = ''
4+
35const mergeConfig = ( objValue , srcValue ) => {
46 if ( _ . isArray ( objValue ) ) {
57 return objValue . concat ( srcValue )
@@ -10,6 +12,17 @@ const mergeConfig = (objValue, srcValue) => {
1012 }
1113}
1214
15+ const checkPath = ( path ) => {
16+ const newPath = _ . replace ( path , / ^ ( ~ ) / , rootPath )
17+ try {
18+ require . resolve ( newPath )
19+ return true
20+ } catch ( e ) {
21+
22+ }
23+ return false
24+ }
25+
1326const convertPath = ( config ) => {
1427 let result = { }
1528 const keys = [ 'atoms' , 'molecules' , 'organisms' , 'templates' , 'pages' , 'loaders' , 'extensions' ]
@@ -18,26 +31,23 @@ const convertPath = (config) => {
1831 continue
1932 }
2033 result [ keys [ type ] ] = { }
21- for ( const key in config [ keys [ type ] ] ) {
22- try {
23- require . resolve ( config [ keys [ type ] ] [ key ] )
34+ const category = config [ keys [ type ] ]
35+ for ( const key in category ) {
36+ if ( checkPath ( category [ key ] ) ) {
2437 result [ keys [ type ] ] [ key ] = {
2538 type : 'full' ,
26- path : config [ keys [ type ] ] [ key ]
39+ path : category [ key ]
2740 }
28- } catch ( e ) {
29- try {
30- require . resolve ( config . root . components + '/' + config [ keys [ type ] ] [ key ] )
31- result [ keys [ type ] ] [ key ] = {
32- type : 'full' ,
33- path : config . root . components + '/' + config [ keys [ type ] ] [ key ]
34- }
35- } catch ( e ) {
36- result [ keys [ type ] ] [ key ] = {
37- type : 'inside' ,
38- path : config . root . components ,
39- component : config [ keys [ type ] ] [ key ]
40- }
41+ } else if ( checkPath ( config . root . components + '/' + category [ key ] ) ) {
42+ result [ keys [ type ] ] [ key ] = {
43+ type : 'full' ,
44+ path : config . root . components + '/' + category [ key ]
45+ }
46+ } else {
47+ result [ keys [ type ] ] [ key ] = {
48+ type : 'inside' ,
49+ path : config . root . components ,
50+ component : category [ key ]
4151 }
4252 }
4353 }
@@ -52,33 +62,29 @@ const convertPath = (config) => {
5262 }
5363 continue
5464 }
55- try {
56- require . resolve ( config . store [ key ] . module )
65+ if ( checkPath ( config . store [ key ] . module ) ) {
5766 result . store [ key ] = {
5867 ...config . store [ key ] ,
5968 module : {
6069 type : 'full' ,
6170 path : config . store [ key ] . module
6271 }
6372 }
64- } catch ( e ) {
65- try {
66- require . resolve ( config . root . store + '/' + config . store [ key ] . module )
67- result . store [ key ] = {
68- ...config . store [ key ] ,
69- module : {
70- type : 'full' ,
71- path : config . root . store + '/' + config . store [ key ] . module
72- }
73+ } else if ( checkPath ( config . root . store + '/' + config . store [ key ] . module ) ) {
74+ result . store [ key ] = {
75+ ...config . store [ key ] ,
76+ module : {
77+ type : 'full' ,
78+ path : config . root . store + '/' + config . store [ key ] . module
7379 }
74- } catch ( e ) {
75- result . store [ key ] = {
76- ... config . store [ key ] ,
77- module : {
78- type : 'inside' ,
79- path : config . root . store ,
80- component : config . store [ key ] . module
81- }
80+ }
81+ } else {
82+ result . store [ key ] = {
83+ ... config . store [ key ] ,
84+ module : {
85+ type : 'inside' ,
86+ path : config . root . store ,
87+ component : config . store [ key ] . module
8288 }
8389 }
8490 }
@@ -89,26 +95,23 @@ const convertPath = (config) => {
8995 result . locales = { }
9096 for ( const key in config . locales ) {
9197 result . locales [ key ] = [ ]
92- for ( const key2 in config . locales [ key ] ) {
93- try {
94- require . resolve ( config . locales [ key ] [ key2 ] )
98+ const locale = config . locales [ key ]
99+ for ( const key2 in locale ) {
100+ if ( checkPath ( locale [ key2 ] ) ) {
95101 result . locales [ key ] [ key2 ] = {
96102 type : 'full' ,
97103 path : config . locales [ key ] [ key2 ]
98104 }
99- } catch ( e ) {
100- try {
101- require . resolve ( config . root . locales + '/' + config . locales [ key ] [ key2 ] )
102- result . locales [ key ] [ key2 ] = {
103- type : 'full' ,
104- path : config . root . locales + '/' + config . locales [ key ] [ key2 ]
105- }
106- } catch ( e ) {
107- result . locales [ key ] [ key2 ] = {
108- type : 'inside' ,
109- path : config . root . locales ,
110- component : config . locales [ key ] [ key2 ]
111- }
105+ } else if ( checkPath ( config . root . locales + '/' + config . locales [ key ] [ key2 ] ) ) {
106+ result . locales [ key ] [ key2 ] = {
107+ type : 'full' ,
108+ path : config . root . locales + '/' + config . locales [ key ] [ key2 ]
109+ }
110+ } else {
111+ result . locales [ key ] [ key2 ] = {
112+ type : 'inside' ,
113+ path : config . root . locales ,
114+ component : config . locales [ key ] [ key2 ]
112115 }
113116 }
114117 }
@@ -121,6 +124,8 @@ const convertPath = (config) => {
121124export default ( rootDir ) => {
122125 let themeOptions = require ( 'vuefront' ) . default
123126
127+ rootPath = rootDir
128+
124129 themeOptions = { ...themeOptions , ...convertPath ( themeOptions ) }
125130 let config = require ( rootDir + '/vuefront.config' ) . default
126131 config = { ...config , ...convertPath ( config ) }
0 commit comments