Skip to content

Commit e4a7017

Browse files
committed
fix: cache version upgrade script
1 parent 2bd38f4 commit e4a7017

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

gulpfile.js/index.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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 = /<script>window\.PHOENIX_APP_CACHE_VERSION="(\d+(\.\d+)*)";<\/script>/;
209+
function containsPhoenixAppCacheVersion(str) {
210+
return PHOENIX_CACHE_VERSION_REGEX.test(str);
211+
}
212+
202213
function _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
}

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
<!-- start inline javascript and non module bootstrap scripts. you must add module scripts to the
5050
javascript module section only!!-->
5151
<!-- The app cache version is set by the pipeline version update script. Do not update manually.-->
52-
<script>window.PHOENIX_APP_CACHE_VERSION="LATEST";</script>
52+
<script>window.PHOENIX_APP_CACHE_VERSION="3.4.5";</script>
5353
<!-- The app cache version is set by the pipeline version update script. Do not update manually.-->
5454
<script>
5555
if(["dev.phcode.dev", "staging.phcode.dev"].includes(location.hostname)

0 commit comments

Comments
 (0)