@@ -199,16 +199,27 @@ function _majorVersionBumpConfigFile(fileName) {
199199 fs . writeFileSync ( fileName , JSON . stringify ( config , null , 4 ) ) ;
200200}
201201
202+ // This regular expression matches the pattern
203+ // It looks for the specific script tag and version number format
204+ // \d+ matches one or more digits
205+ // \. matches the dot literally
206+ // (\.\d+)* matches zero or more occurrences of ".[digits]"
207+ // Test the string against the regex
208+ const PHOENIX_CACHE_VERSION_REGEX = / < s c r i p t > w i n d o w \. P H O E N I X _ A P P _ C A C H E _ V E R S I O N = " ( \d + ( \. \d + ) * ) " ; < \/ s c r i p t > / ;
209+ function containsPhoenixAppCacheVersion ( str ) {
210+ return PHOENIX_CACHE_VERSION_REGEX . test ( str ) ;
211+ }
212+
202213function _patchIndexHTML ( ) {
203214 let indexHtmlPath = './src/index.html' ;
204215 let config = JSON . parse ( fs . readFileSync ( './package.json' , 'utf8' ) ) ;
205216 let indexHTML = fs . readFileSync ( indexHtmlPath , 'utf8' ) ;
206217 let version = config . apiVersion ;
207- const replaceStr = '<script>window.PHOENIX_APP_CACHE_VERSION="LATEST ";</script>' ;
208- if ( ! indexHTML . includes ( replaceStr ) ) {
218+ const replaceStr = '<script>window.PHOENIX_APP_CACHE_VERSION="<version> ";</script>' ;
219+ if ( ! containsPhoenixAppCacheVersion ( indexHTML ) ) {
209220 throw new Error ( "Expected index.html to include " + replaceStr ) ;
210221 }
211- indexHTML = indexHTML . replace ( replaceStr ,
222+ indexHTML = indexHTML . replace ( PHOENIX_CACHE_VERSION_REGEX ,
212223 `<script>window.PHOENIX_APP_CACHE_VERSION="${ version } ";</script>` ) ;
213224 fs . writeFileSync ( indexHtmlPath , indexHTML ) ;
214225}
0 commit comments