cleanup method

Future<void> cleanup()

Run tool/dev_build_cleanup.dart when found (devBuildCleanupPath), then delete the runCiCleanupTopDirs created since prepareCleanup, unless PackageRunCiOptions.noCleanup.

Its errors are reported and ignored.

Implementation

Future<void> cleanup() async {
  if (isWorkspaceRoot || options.noCleanup) {
    return;
  }
  if (File(join(path, devBuildCleanupPath)).existsSync()) {
    try {
      await runScript('''
        # Cleanup
        dart run $devBuildCleanupPath
      ''');
    } catch (e) {
      stderr.writeln('(ignored) $devBuildCleanupPath failed: $e');
    }
  }
  var missingTopDirs = _cleanupMissingTopDirs;
  _cleanupMissingTopDirs = null;
  if (missingTopDirs == null) {
    return;
  }
  for (var dir in missingTopDirs) {
    if (options.dryRun) {
      stdout.writeln('# Delete $dir/ if created');
      continue;
    }
    var dirPath = join(path, dir);
    if (isDirectoryNotLinkSynk(dirPath)) {
      stdout.writeln('# Cleanup: delete $dir/ (created)');
      try {
        await Directory(dirPath).delete(recursive: true);
      } catch (e) {
        stderr.writeln('(ignored) deleting $dirPath failed: $e');
      }
    }
  }
}