-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathweb_cache_invalidation.py
More file actions
27 lines (23 loc) · 1.12 KB
/
web_cache_invalidation.py
File metadata and controls
27 lines (23 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import json
# Path to the web root
webRoot = './build/web'
# Locations of the Web application files we are going to update
indexHtmlPath = f'{webRoot}/index.html'
flutterJsPath = f'{webRoot}/flutter.js'
versionJsonPath = f'{webRoot}/version.json'
# Compose app version by adding build_number
with open(versionJsonPath, 'r') as versionJsonFile:
versionJson = json.load(versionJsonFile)
appVersion = f"{versionJson['version']}b{versionJson['build_number']}".strip()
# Update flutter.js file by specifying app version to the main.dart.js
with open(flutterJsPath, 'r') as flutterJsFile:
flutterJsContent = flutterJsFile.read()
flutterJsReplaced = flutterJsContent.replace('main.dart.js', f'main.dart.js?{appVersion}')
with open(flutterJsPath, 'w') as flutterJsFile:
flutterJsFile.write(flutterJsReplaced)
# Update index.html file by specifying app version to the flutter.js file
with open(indexHtmlPath, 'r') as indexHtmlFile:
indexHtml = indexHtmlFile.read()
indexHtmlReplaced = indexHtml.replace('"flutter.js"', f'"flutter.js?{appVersion}"')
with open(indexHtmlPath, 'w') as indexHtmlFile:
indexHtmlFile.write(indexHtmlReplaced)