Last active
March 3, 2023 17:14
-
-
Save zs-dima/a867631c3a53d35e88f0c1df5d44f80c to your computer and use it in GitHub Desktop.
Check application version prepare_app_to_start program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Path to the web root | |
const webRoot = '/usr/share/nginx/html'; | |
// Locations of the Web application files we are going to update | |
const indexHtmlPath = '$webRoot/index.html'; | |
const flutterJsPath = '$webRoot/flutter.js'; | |
const versionJsonPath = '$webRoot/version.json'; | |
// Compose app version by adding build_number | |
final versionJsonFile = File(versionJsonPath); | |
final versionJson = jsonDecode(await versionJsonFile.readAsString()); | |
final appVersion = '${versionJson['version']}b${versionJson['build_number']}'.trim(); | |
// Update flutter.js file by specifying app version to the main.dart.js | |
final flutterJsFile = File(flutterJsPath); | |
final flutterJsContent = await flutterJsFile.readAsString(); | |
final flutterJsReplaced = flutterJsContent.replaceAll('main.dart.js', 'main.dart.js?$appVersion'); | |
await flutterJsFile.writeAsString(flutterJsReplaced); | |
// Update index.html file by specifying app version to the flutter.js file | |
final indexHtmlFile = File(indexHtmlPath); | |
final indexHtml = await indexHtmlFile.readAsString(); | |
final indexHtmlReplaced = indexHtml.replaceAll('"flutter.js"', '"flutter.js?$appVersion"'); | |
await indexHtmlFile.writeAsString(indexHtmlReplaced); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment