cleanDartPubGetGeneratedFiles method

Future<bool> cleanDartPubGetGeneratedFiles({
  1. required String confirmProjectName,
  2. bool verbose = false,
})

Deletes files generated by dart pub get:

  • confirmProjectName the project name at pubspec.yaml, to confirm cleanup.

Deleted Files:

  • %projectDirectory/pubspec.lock
  • %projectDirectory/.packages
  • %projectDirectory/.dart_tool/**

Implementation

Future<bool> cleanDartPubGetGeneratedFiles(
    {required String confirmProjectName, bool verbose = false}) async {
  var projDir = await projectDirectory;

  if (!projDir.existsSync()) {
    return false;
  }

  var packageName = await projectPackageName;
  if (packageName != confirmProjectName) {
    return false;
  }

  var filePubspecLock = await projectSubFile('pubspec.lock');
  var filePackages = await projectSubFile('.packages');
  var dirDartTools = await projectSubDirectory('.dart_tool');

  deleteFile(projDir, filePubspecLock, verbose: verbose);
  deleteFile(projDir, filePackages, verbose: verbose);

  if (dirDartTools.existsSync()) {
    deleteDirectory(projDir, dirDartTools, recursive: true, verbose: verbose);
  }

  return true;
}