clean method
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. @Throwing(ArgumentError) @Throwing(DeleteDirException)
Implementation
Future<void> clean() async {
print('Cleaning project: $pathToProjectRoot');
await NamedLock(name: _lockName, timeout: _lockTimeout).withLockAsync(
() async {
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...',
);
}