update static method

Future<File> update(
  1. FrameGuardReport report,
  2. String name, {
  3. String directory = defaultDirectory,
  4. bool overwrite = false,
})

Writes a baseline for report only when overwrite is true.

Refuses to clobber an existing file unless overwrite is set.

Implementation

static Future<File> update(
  FrameGuardReport report,
  String name, {
  String directory = defaultDirectory,
  bool overwrite = false,
}) async {
  final dir = Directory(directory);
  if (!dir.existsSync()) {
    await dir.create(recursive: true);
  }
  final file = File(p.join(directory, '$name.json'));
  if (file.existsSync() && !overwrite) {
    throw StateError(
      'Baseline already exists: ${file.path}\n'
      'Refusing to overwrite. Pass overwrite: true or use:\n'
      '  dart run frameguard baseline update <report.json> --out ${file.path} --force',
    );
  }
  final baseline = FrameGuardBaseline.fromReport(report);
  await baseline.write(file);
  return file;
}