@@ -13,7 +13,7 @@ const filesFilter = (file: any) => {
1313 return true ;
1414} ;
1515
16- const getCategory = ( fileName : string , addCategory : any | boolean ) : string => {
16+ export const getCategory = ( fileName : string , addCategory : any | boolean ) : string => {
1717 const fileExt = fileName . split ( "." ) . pop ( ) . toLowerCase ( ) ;
1818 if ( typeof addCategory === "object" ) {
1919 for ( const pattern of Object . keys ( addCategory ) ) {
@@ -45,22 +45,31 @@ export const getFileName = (
4545 [ key : string ] : string ;
4646 }
4747) : string => {
48- if ( map ) {
49- for ( const pattern of Object . keys ( map ) ) {
50- if ( new RegExp ( `^${ pattern } $` ) . test ( name ) ) {
51- name = name . replace ( new RegExp ( `^${ pattern } $` ) , map [ pattern ] ) ;
52- break ;
48+ if ( name . includes ( "/" ) ) {
49+ // This is a file from a web application
50+ const nameArr : string [ ] = name . split ( "/" ) ;
51+ const cat = addCategory ? getCategory ( name , addCategory ) : null ;
52+ return [ folder , cat , ...nameArr ] . filter ( notNull ) . join ( path . sep ) ;
53+ }
54+ else {
55+ // This is a class, routine or include file
56+ if ( map ) {
57+ for ( const pattern of Object . keys ( map ) ) {
58+ if ( new RegExp ( `^${ pattern } $` ) . test ( name ) ) {
59+ name = name . replace ( new RegExp ( `^${ pattern } $` ) , map [ pattern ] ) ;
60+ break ;
61+ }
5362 }
5463 }
64+ const fileNameArray : string [ ] = name . split ( "." ) ;
65+ const fileExt = fileNameArray . pop ( ) . toLowerCase ( ) ;
66+ const cat = addCategory ? getCategory ( name , addCategory ) : null ;
67+ if ( split ) {
68+ const fileName = [ folder , cat , ...fileNameArray ] . filter ( notNull ) . join ( path . sep ) ;
69+ return [ fileName , fileExt ] . join ( "." ) ;
70+ }
71+ return [ folder , cat , name ] . filter ( notNull ) . join ( path . sep ) ;
5572 }
56- const fileNameArray : string [ ] = name . split ( "." ) ;
57- const fileExt = fileNameArray . pop ( ) . toLowerCase ( ) ;
58- const cat = addCategory ? getCategory ( name , addCategory ) : null ;
59- if ( split ) {
60- const fileName = [ folder , cat , ...fileNameArray ] . filter ( notNull ) . join ( path . sep ) ;
61- return [ fileName , fileExt ] . join ( "." ) ;
62- }
63- return [ folder , cat , name ] . filter ( notNull ) . join ( path . sep ) ;
6473} ;
6574
6675export const getFolderName = ( folder : string , name : string , split : boolean , cat : string = null ) : string => {
@@ -122,26 +131,48 @@ export async function exportFile(
122131
123132 return promise
124133 . then ( ( res : any ) => {
125- let joinedContent = content instanceof Buffer ? content . toString ( "utf-8" ) : ( content || [ ] ) . join ( "\n" ) ;
126- let isSkipped = "" ;
134+ if ( Buffer . isBuffer ( content ) ) {
135+ // This is a binary file
136+ let isSkipped = "" ;
137+
138+ if ( dontExportIfNoChanges && fs . existsSync ( fileName ) ) {
139+ const existingContent = fs . readFileSync ( fileName ) ;
140+ if ( content . equals ( existingContent ) ) {
141+ fs . writeFileSync ( fileName , content ) ;
142+ }
143+ else {
144+ isSkipped = " => skipped - no changes." ;
145+ }
146+ }
147+ else {
148+ fs . writeFileSync ( fileName , content ) ;
149+ }
127150
128- if ( res . found ) {
129- joinedContent = res . content . toString ( "utf8" ) ;
151+ log ( `Success ${ isSkipped } ` ) ;
130152 }
153+ else {
154+ // This is a text file
155+ let joinedContent = content . join ( "\n" ) ;
156+ let isSkipped = "" ;
131157
132- if ( dontExportIfNoChanges && fs . existsSync ( fileName ) ) {
133- const existingContent = fs . readFileSync ( fileName , "utf8" ) ;
134- // stringify to harmonise the text encoding.
135- if ( JSON . stringify ( joinedContent ) !== JSON . stringify ( existingContent ) ) {
136- fs . writeFileSync ( fileName , joinedContent ) ;
158+ if ( res . found ) {
159+ joinedContent = res . content . toString ( "utf8" ) ;
160+ }
161+
162+ if ( dontExportIfNoChanges && fs . existsSync ( fileName ) ) {
163+ const existingContent = fs . readFileSync ( fileName , "utf8" ) ;
164+ // stringify to harmonise the text encoding.
165+ if ( JSON . stringify ( joinedContent ) !== JSON . stringify ( existingContent ) ) {
166+ fs . writeFileSync ( fileName , joinedContent ) ;
167+ } else {
168+ isSkipped = " => skipped - no changes." ;
169+ }
137170 } else {
138- isSkipped = " => skipped - no changes." ;
171+ fs . writeFileSync ( fileName , joinedContent ) ;
139172 }
140- } else {
141- fs . writeFileSync ( fileName , joinedContent ) ;
142- }
143173
144- log ( `Success ${ isSkipped } ` ) ;
174+ log ( `Success ${ isSkipped } ` ) ;
175+ }
145176 } )
146177 . catch ( ( error ) => {
147178 throw error ;
0 commit comments