clean method

void clean()

Removes any of the dart build artifacts so you have a clean directory. We do this recursively so all subdirectories will also be purged.

Deletes: pubspec.lock ./packages .dart_tools

Any exes for scripts in the directory.

Implementation

void clean() {
  NamedLock.guard(
    name: _lockName,
    execution: ExecutionCall<void, PubGetException>(
      callable: () {
        try {
          find(
            '.packages',
            types: [Find.file],
            workingDirectory: pathToProjectRoot,
          ).forEach(delete);

          /// we cant delete directories whilst recusively scanning them.
          final toBeDeleted = <String>[];
          find(
            '.dart_tool',
            types: [Find.directory],
            workingDirectory: pathToProjectRoot,
          ).forEach(toBeDeleted.add);

          _deleteDirs(toBeDeleted);

          find('pubspec.lock', workingDirectory: pathToProjectRoot)
              .forEach(delete);

          find('*.dart', workingDirectory: pathToProjectRoot)
              .forEach((scriptPath) {
            final script = DartScript.fromFile(scriptPath);
            if (exists(script.pathToExe)) {
              delete(script.pathToExe);
            }
          });
        } on PubGetException {
          print(
              red("\ndcli clean failed due to the 'pub get' call failing."));
        }
      },
    ),
    waiting: 'Waiting for clean to complete...',
  );
}