File tree Expand file tree Collapse file tree 1 file changed +12
-6
lines changed
Expand file tree Collapse file tree 1 file changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -17,16 +17,22 @@ const isComponentFile = (source) => {
1717const componentDirs = readdirSync ( srcPath ) . map ( name => path . join ( srcPath , name ) ) . filter ( isComponentDirectory ) . map ( directory => {
1818 return {
1919 path : directory ,
20- fileName : readdirSync ( directory ) . filter ( isComponentFile )
20+ fileNames : readdirSync ( directory ) . filter ( isComponentFile )
2121 } ;
2222} ) ;
2323
24+ // For every component directory.
2425componentDirs . map ( ( directory ) => {
25- let component = require ( `${ directory . path } /${ directory . fileName } ` ) ;
2626 let fileContents = '' ;
27- Object . keys ( component ) . map ( ( single ) => {
28- fileContents += `export { ${ single } } from './${ directory . fileName } ';\n` ;
29- let indexPath = `${ directory . path } /index.js` ;
30- writeFileSync ( indexPath , fileContents ) ;
27+ // Loop through its files.
28+ directory . fileNames . map ( ( fileName ) => {
29+ // Grab the file's exports.
30+ let components = require ( path . join ( directory . path , fileName ) ) ;
31+ Object . keys ( components ) . map ( ( component ) => {
32+ fileContents += `export { ${ component } } from './${ fileName } ';\n` ;
33+ } ) ;
3134 } ) ;
35+ // write the index file into the directory.
36+ let indexPath = path . join ( directory . path , 'index.js' ) ;
37+ writeFileSync ( indexPath , fileContents ) ;
3238} ) ;
You can’t perform that action at this time.
0 commit comments