enable method

void enable()

Implementation

void enable() {
  if (_enabled) return;

  _backup(_pubspecPath);
  _backup(_testEntryPath, optional: true);

  final pubspec = File(_pubspecPath).readAsStringSync();
  final activated = _activatePubspec(pubspec);
  _pubspecChanged = activated != pubspec;
  if (_pubspecChanged) {
    File(_pubspecPath).writeAsStringSync(activated);
  }

  final testEntry = File(_testEntryPath);
  final testEntryExisted = testEntry.existsSync();
  _removeTestEntryOnRestore = !testEntryExisted;

  if (!testEntryExisted) {
    Directory(_testDirPath).createSync(recursive: true);
    testEntry.writeAsStringSync(
      testEntryContentsFor(_readPackageName()),
    );
  } else {
    final content = testEntry.readAsStringSync();
    if (content.trim() == legacyTestEntryContents.trim()) {
      final upgraded = testEntryContentsFor(_readPackageName());
      testEntry.writeAsStringSync(upgraded);
      _backups[_testEntryPath] = upgraded;
      _removeTestEntryOnRestore = false;
    }
  }

  _enabled = true;
}