@@ -21,7 +21,7 @@ const figureOutFileMimetype = (filePath) => {
2121 return 'application/octet-stream' ;
2222} ;
2323
24- const pushOneFileToS3 = ( basePath , to ) => {
24+ const pushOneFileToS3 = ( basePath , to , cacheControllDays = 1 ) => {
2525 return new Promise ( async ( resolve , reject ) => {
2626 file = Path . basename ( basePath ) ;
2727
@@ -33,6 +33,7 @@ const pushOneFileToS3 = (basePath, to) => {
3333 Bucket : to . bucket ,
3434 Key : uploadKey ,
3535 Body : content ,
36+ CacheControl : `max-age=${ cacheControll * 60 * 60 * 24 } ` || 'max-age=86400' ,
3637 ContentType : figureOutFileMimetype ( basePath ) ,
3738 } ;
3839
@@ -77,13 +78,13 @@ const canDeploy = () => {
7778 return true ;
7879}
7980
80- const upload = async ( bucket , path ) => {
81+ const upload = async ( bucket , path , cacheControll ) => {
8182 return runOnEachFile (
8283 browserBuildDir ,
8384 {
8485 realpath : true ,
8586 } ,
86- ( file , incOptions ) => pushOneFileToS3 ( file , incOptions ) ,
87+ ( file , incOptions ) => pushOneFileToS3 ( file , incOptions , cacheControll ) ,
8788 { bucket, path } ,
8889 ) ;
8990} ;
@@ -98,21 +99,33 @@ const upload = async (bucket, path) => {
9899 if ( args . indexOf ( '--latest' ) > - 1 ) {
99100 console . log ( `publish latest version ${ major } .x.x` ) ;
100101 if ( canDeploy ( ) ) {
101- paths . push ( `filestack-js/${ major } .x.x` ) ;
102+ paths . push ( {
103+ bucket,
104+ path : `filestack-js/${ major } .x.x` ,
105+ cacheControll : 1 ,
106+ } ) ;
102107 }
103108 }
104109
105110 if ( args . indexOf ( '--current' ) > - 1 ) {
106111 console . log ( `publish current version ${ version } ` ) ;
107112 if ( canDeploy ( ) ) {
108- paths . push ( `filestack-js/${ version } ` )
113+ paths . push ( {
114+ bucket,
115+ path : `filestack-js/${ version } ` ,
116+ cacheControll : 30
117+ } ) ;
109118 }
110119 }
111120
112121 if ( args . indexOf ( '--beta' ) > - 1 ) {
113122 console . log ( `publish beta version` ) ;
114- paths . push ( `filestack-js/beta` )
123+ paths . push ( {
124+ bucket,
125+ path : `filestack-js/beta` ,
126+ cacheControll : 0
127+ } )
115128 }
116129
117- Promise . all ( paths . map ( ( p ) => upload ( bucket , p ) ) ) . then ( ( res ) => console . log ( res ) )
130+ Promise . all ( paths . map ( ( data ) => upload ( data . bucket , data . path , data . cacheControll ) ) ) . then ( ( res ) => console . log ( res ) )
118131} ) ( ) ;
0 commit comments