11const _ = require ( 'lodash' )
2+ const renderImport = ( component , tag ) => {
3+ let result = ''
4+
5+ if ( component . type === 'full' ) {
6+ result = `import ${ tag } from '${ component . path } ';`
7+ } else {
8+ result = `import {${ component . component } as ${ tag } } from '${ component . path } ';`
9+ }
10+
11+ return result
12+ }
213const getImport = ( name , type , config , tag ) => {
314 let comImport = false
415
5-
616 switch ( type ) {
7- case 'A' :
17+ case 'A' :
818 if ( ! config . atoms [ name ] ) {
919 return
1020 }
11- if ( config . atoms [ name ] . type === 'full' ) {
12- comImport = `const ${ tag } = () => import('${ config . atoms [ name ] . path } ');`
13- } else {
14- comImport = `const ${ tag } = () => import('${ config . atoms [ name ] . path } ').then(m => m.${ config . atoms [ name ] . component } );`
15- }
21+ comImport = renderImport ( config . atoms [ name ] , tag )
1622 break ;
17- case 'M' :
23+ case 'M' :
1824 if ( ! config . molecules [ name ] ) {
1925 return
2026 }
21- if ( config . molecules [ name ] . type === 'full' ) {
22- comImport = `const ${ tag } = () => import('${ config . molecules [ name ] . path } ');`
23- } else {
24- comImport = `const ${ tag } = () => import('${ config . molecules [ name ] . path } ').then(m => m.${ config . molecules [ name ] . component } );`
25- }
27+ comImport = renderImport ( config . molecules [ name ] , tag )
2628 break ;
27- case 'O' :
29+ case 'O' :
2830 if ( ! config . organisms [ name ] ) {
2931 return
3032 }
31- if ( config . organisms [ name ] . type === 'full' ) {
32- comImport = `const ${ tag } = () => import('${ config . organisms [ name ] . path } ');`
33- } else {
34- comImport = `const ${ tag } = () => import('${ config . organisms [ name ] . path } ').then(m => m.${ config . organisms [ name ] . component } );`
35- }
33+ comImport = renderImport ( config . organisms [ name ] , tag )
3634 break ;
37- case 'T' :
35+ case 'T' :
3836 if ( ! config . templates [ name ] ) {
3937 return
4038 }
41- if ( config . templates [ name ] . type === 'full' ) {
42- comImport = `const ${ tag } = () => import('${ config . templates [ name ] . path } ');`
43- } else {
44- comImport = `const ${ tag } = () => import('${ config . templates [ name ] . path } ').then(m => m.${ config . templates [ name ] . component } );`
45- }
39+ comImport = renderImport ( config . templates [ name ] , tag )
4640 break ;
47- case 'L' :
41+ case 'L' :
4842 if ( ! config . loaders [ name ] ) {
4943 return
5044 }
51- if ( config . loaders [ name ] . type === 'full' ) {
52- comImport = `const ${ tag } = () => import('${ config . loaders [ name ] . path } ');`
53- } else {
54- comImport = `const ${ tag } = () => import('${ config . loaders [ name ] . path } ').then(m => m.${ config . loaders [ name ] . component } );`
55- }
45+ comImport = renderImport ( config . loaders [ name ] , tag )
5646 break ;
57- case 'E' :
47+ case 'E' :
5848 if ( ! config . extensions [ name ] ) {
5949 return
6050 }
61- if ( config . extensions [ name ] . type === 'full' ) {
62- comImport = `const ${ tag } = () => import('${ config . extensions [ name ] . path } ');`
63- } else {
64- comImport = `const ${ tag } = () => import('${ config . extensions [ name ] . path } ').then(m => m.${ config . extensions [ name ] . component } );`
65- }
51+ comImport = renderImport ( config . extensions [ name ] , tag )
6652 break ;
6753 }
6854 return comImport
@@ -79,10 +65,5 @@ module.exports = function match (_, config, { kebabTag, camelTag: tag }) {
7965
8066 let comImport = getImport ( name , type , config , tag )
8167
82- if ( type === 'O' && name === 'virtual' ) {
83- comImport = ''
84- }
85-
86-
8768 return [ tag , comImport ]
8869}
0 commit comments