@@ -1332,42 +1332,32 @@ class FlutterPlugin implements Plugin<Project> {
1332
1332
}
1333
1333
Task copyFlutterAssetsTask = addFlutterDeps(variant)
1334
1334
copyFlutterAssetsTask. doLast {
1335
- def content = " " ;
1335
+ def yaml = new Yaml ()
1336
1336
def outputDir = copyFlutterAssetsTask. destinationDir
1337
+
1338
+ // Read the shorebird.yaml file into a map.
1337
1339
def shorebirdYamlFile = new File (" ${ outputDir} /flutter_assets/shorebird.yaml" )
1340
+ def shorebirdYamlData = yaml. load(shorebirdYamlFile. text)
1338
1341
1339
- def usedFlavors = variant. flavorName != null && ! variant. flavorName. isEmpty();
1340
- if (usedFlavors) {
1341
- def flavor = variant. flavorName
1342
- def shorebirdYaml = new Yaml (). load(shorebirdYamlFile. text)
1343
- def flavorAppId = shorebirdYaml[' flavors' ][flavor]
1344
- if (flavorAppId == null ) {
1345
- throw new GradleException (" Cannot find app_id for ${ flavor} in shorebird.yaml" )
1346
- }
1347
- content + = ' app_id: ' + flavorAppId + ' \n ' ;
1348
- if (shorebirdYaml. containsKey(' base_url' )) {
1349
- content + = ' base_url: ' + shorebirdYaml[' base_url' ] + ' \n ' ;
1350
- }
1351
- if (shorebirdYaml. containsKey(' auto_update' )) {
1352
- content + = ' auto_update: ' + shorebirdYaml[' auto_update' ] + ' \n ' ;
1353
- }
1342
+ // Update the app_id to the correct flavor if one was provided.
1343
+ if (variant. flavorName != null && ! variant. flavorName. isEmpty()) {
1344
+ shorebirdYamlData[' app_id' ] = shorebirdYamlData. flavors[variant. flavorName]
1354
1345
}
1355
1346
1347
+ // Remove any flavors. This is a no-op if the flavors key doesn't exist.
1348
+ shorebirdYamlData. remove(' flavors' )
1349
+
1350
+ // Add a public key if one was provided via an env var.
1351
+ // Ideally we'd have a way to pass the key as a parameter, but
1352
+ // an env var was the easiest way to get this working.
1356
1353
def shorebirdPublicKeyEnvVar = System . getenv(' SHOREBIRD_PUBLIC_KEY' )
1357
1354
if (shorebirdPublicKeyEnvVar != null && ! shorebirdPublicKeyEnvVar. isEmpty()) {
1358
- // When a flavor were used, the content variable will already include
1359
- // the app_id and other attributes, since the code above makes sure of that
1360
- //
1361
- // But when no flavor was used, it will be empty, so we make sure that include
1362
- // the original file in the beginning
1363
- if (! usedFlavors) {
1364
- content + = shorebirdYamlFile. text;
1365
- }
1366
- content + = ' patch_public_key: ' + shorebirdPublicKeyEnvVar + ' \n ' ;
1367
- }
1368
- if (! content. isEmpty()) {
1369
- shorebirdYamlFile. write(content)
1355
+ shorebirdYamlData[' patch_public_key' ] = shorebirdPublicKeyEnvVar
1370
1356
}
1357
+
1358
+ // Write the updated map back to the shorebird.yaml file.
1359
+ def updatedYamlString = yaml. dumpAsMap(shorebirdYamlData)
1360
+ shorebirdYamlFile. write(updatedYamlString)
1371
1361
}
1372
1362
def variantOutput = variant. outputs. first()
1373
1363
def processResources = variantOutput. hasProperty(propProcessResourcesProvider) ?
0 commit comments