@@ -100,6 +100,21 @@ function makeDistNonJS() {
100100 . pipe ( dest ( 'dist' ) ) ;
101101}
102102
103+ function makeDistWebCache ( ) {
104+ return new Promise ( ( resolve ) => {
105+ fs . rmSync ( "./dist/web-cache" , { recursive : true , force : true } ) ;
106+ fs . rmSync ( "./dist-web-cache" , { recursive : true , force : true } ) ;
107+ fs . cpSync ( "./dist" , "./dist-web-cache" , {
108+ recursive : true ,
109+ force : true
110+ } ) ;
111+ let config = JSON . parse ( fs . readFileSync ( './package.json' , 'utf8' ) ) ;
112+ fs . mkdirSync ( "./dist/web-cache" ) ;
113+ fs . renameSync ( "./dist-web-cache" , `./dist/web-cache/${ config . apiVersion } ` ) ;
114+ resolve ( ) ;
115+ } ) ;
116+ }
117+
103118function serve ( ) {
104119 return src ( '.' )
105120 . pipe ( webserver ( {
@@ -184,20 +199,38 @@ function _majorVersionBumpConfigFile(fileName) {
184199 fs . writeFileSync ( fileName , JSON . stringify ( config , null , 4 ) ) ;
185200}
186201
202+ function _patchIndexHTML ( ) {
203+ let indexHtmlPath = './src/index.html' ;
204+ let config = JSON . parse ( fs . readFileSync ( './package.json' , 'utf8' ) ) ;
205+ let indexHTML = fs . readFileSync ( indexHtmlPath , 'utf8' ) ;
206+ let version = config . apiVersion ;
207+ const replaceStr = '<script>window.PHOENIX_APP_CACHE_VERSION="LATEST";</script>' ;
208+ if ( ! indexHTML . includes ( replaceStr ) ) {
209+ throw new Error ( "Expected index.html to include " + replaceStr ) ;
210+ }
211+ indexHTML = indexHTML . replace ( replaceStr ,
212+ `<script>window.PHOENIX_APP_CACHE_VERSION="${ version } ";</script>` ) ;
213+ fs . writeFileSync ( indexHtmlPath , indexHTML ) ;
214+ }
215+
187216function patchVersionBump ( ) {
217+ // adding anything here should be added to patch-version-bump.yml and yearly-major-version-bump.yml
188218 return new Promise ( ( resolve ) => {
189219 _patchBumpConfigFile ( './package.json' ) ;
190220 _patchBumpConfigFile ( './src-node/package.json' ) ;
191221 _patchBumpConfigFile ( './src/config.json' ) ;
222+ _patchIndexHTML ( ) ;
192223 resolve ( ) ;
193224 } ) ;
194225}
195226
196227function majorVersionBump ( ) {
228+ // adding anything here should be added to patch-version-bump.yml and yearly-major-version-bump.yml
197229 return new Promise ( ( resolve ) => {
198230 _majorVersionBumpConfigFile ( './package.json' ) ;
199231 _majorVersionBumpConfigFile ( './src-node/package.json' ) ;
200232 _majorVersionBumpConfigFile ( './src/config.json' ) ;
233+ _patchIndexHTML ( ) ;
201234 resolve ( ) ;
202235 } ) ;
203236}
@@ -636,6 +669,7 @@ exports.releaseStaging = series(cleanDist, exports.build, makeBracketsConcatJS,
636669exports . releaseProd = series ( cleanDist , exports . build , makeBracketsConcatJS , _compileLessSrc ,
637670 makeDistNonJS , makeJSDist , _renameBracketsConcatAsBracketsJSInDist , _patchMinifiedCSSInDistIndex , releaseProd ,
638671 createDistCacheManifest , createDistTest , _cleanReleaseBuildArtefactsInSrc ) ;
672+ exports . releaseWebCache = series ( makeDistWebCache ) ;
639673exports . serve = series ( exports . build , serve ) ;
640674exports . zipTestFiles = series ( zipTestFiles ) ;
641675exports . serveExternal = series ( exports . build , serveExternal ) ;
0 commit comments