11var path = require ( 'path' ) ;
22var inflection = require ( 'inflection' ) ;
33var CoreObject = require ( 'core-object' ) ;
4+ var fse = require ( 'fs-extra' ) ;
5+ var existsSync = require ( 'exists-sync' ) ;
46var isTypeInSingleTypeCollection = require ( '../utils/is-type-in-single-type-collection' ) ;
7+ var defaultTypeForCollection = require ( '../utils/default-type-for-collection' ) ;
58var calculateCollectionInfo = require ( '../utils/calculate-collection-info' ) ;
69
710var FileInfo = CoreObject . extend ( {
@@ -35,6 +38,7 @@ var FileInfo = CoreObject.extend({
3538 this . populateName ( ) ;
3639 this . populateCollection ( ) ;
3740 this . populateBucket ( ) ;
41+ this . populateFileContents ( ) ;
3842
3943 this . _fileInfoCollection . add ( this ) ;
4044 } ,
@@ -81,6 +85,15 @@ var FileInfo = CoreObject.extend({
8185 this . collectionGroup = values . collectionGroup ;
8286 } ,
8387
88+ populateFileContents : function ( ) {
89+ var fullPath = path . join ( this . projectRoot , this . sourceRelativePath ) ;
90+ if ( ! existsSync ( fullPath ) ) {
91+ return ;
92+ }
93+
94+ this . _fileContents = fse . readFileSync ( fullPath , { encoding : 'utf8' } ) ;
95+ } ,
96+
8497 repopulate : function ( ) {
8598 var inComponentsCollection = this . collection === 'components' ;
8699 var renderableName = path . join ( this . namespace , this . name ) ;
@@ -101,6 +114,27 @@ var FileInfo = CoreObject.extend({
101114 }
102115 }
103116 }
117+
118+ var isDefaultTypeForCollection = defaultTypeForCollection ( this . collection ) === this . type ;
119+ var shouldUseDotFormNaming = this . shouldUseDotFormNaming ( ) ;
120+
121+ if ( ! isDefaultTypeForCollection && shouldUseDotFormNaming ) {
122+ this . updateDefaultExportToNamed ( ) ;
123+ }
124+ } ,
125+
126+ updateDefaultExportToNamed : function ( ) {
127+ if ( this . ext !== '.js' ) { return ; }
128+ if ( ! this . _fileContents ) { return ; }
129+
130+ var newContents = this . _fileContents
131+ . replace ( 'export default ' , 'export const ' + this . type + ' = ' ) ;
132+
133+
134+ var fullPath = path . join ( this . projectRoot , this . sourceRelativePath ) ;
135+
136+ fse . writeFileSync ( fullPath , newContents , { encoding : 'utf-8' } ) ;
137+ this . _fileContents = fse . readFileSync ( fullPath , { encoding : 'utf8' } ) ;
104138 } ,
105139
106140 shouldUseDotFormNaming : function ( ) {
0 commit comments