Last active
March 3, 2023 19:37
-
-
Save zs-dima/7c295a09c88515fb35e39ad9950755b3 to your computer and use it in GitHub Desktop.
Flutter Web - Runtime Docker variables - prepare_app_to_start
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
// Compose app version by adding build_number and environment type | |
final versionJsonFile = File(versionJsonPath); | |
final versionJson = jsonDecode(await versionJsonFile.readAsString()); | |
final appVersion = '${versionJson['version']}b${versionJson['build_number']}${appEnvironment[0]}'.trim(); | |
// Save environment json file | |
final envFile = File(envJsonPath); | |
final envFileContent = const JsonEncoder.withIndent(' ').convert(envJson); | |
final envFileMd5 = md5.convert(utf8.encode(envFileContent)).toString(); | |
await envFile.writeAsString(envFileContent); | |
* * * | |
// Update flutter_service_worker.js file by specifying environment.json MD5 hash | |
final workerJsFile = File(workerJsPath); | |
final workerJsContent = await workerJsFile.readAsString(); | |
final workerJsReplaced = workerJsContent.replaceAll( | |
RegExp('"assets/asset/$envFileName": "[0-9a-f]{32}"'), | |
'"assets/asset/$envFileName": "$envFileMd5"', | |
); | |
await workerJsFile.writeAsString(workerJsReplaced); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment