-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #426 from Workiva/compile_run_script_for_better_pe…
…rf_followup Compile the `dart_dev` run script for better performance
- Loading branch information
Showing
9 changed files
with
317 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import 'dart:async'; | ||
import 'dart:io'; | ||
|
||
import 'package:dart_dev/src/utils/logging.dart'; | ||
import 'package:io/io.dart'; | ||
|
||
import '../dart_dev_tool.dart'; | ||
import '../utils/dart_dev_paths.dart' show DartDevPaths; | ||
|
||
class CleanTool extends DevTool { | ||
@override | ||
final String? description = 'Cleans up temporary files used by dart_dev.'; | ||
|
||
@override | ||
FutureOr<int?> run([DevToolExecutionContext? context]) { | ||
final cache = Directory(DartDevPaths().cache()); | ||
if (cache.existsSync()) { | ||
log.info('Deleting ${cache.path}'); | ||
cache.deleteSync(recursive: true); | ||
} else { | ||
log.info('Nothing to do: no ${cache.path} found'); | ||
} | ||
return ExitCode.success.code; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import 'package:collection/collection.dart'; | ||
|
||
/// Return the contents of the enquoted portion of the import statements in the | ||
/// file. Not 100% accurate, since we use regular expressions instead of the | ||
/// Dart AST to extract the imports. | ||
Iterable<String> parseImports(String fileContents) => | ||
_importRegex.allMatches(fileContents).map((m) => m.group(1)).whereNotNull(); | ||
|
||
final _importRegex = | ||
RegExp(r'''^import ['"]([^'"]+)['"];?$''', multiLine: true); | ||
|
||
/// Return a set of package names given a list of imports. | ||
Set<String> computePackageNamesFromImports(Iterable<String> imports) => imports | ||
.map((i) => _packageNameFromImportRegex.matchAsPrefix(i)?.group(1)) | ||
.whereNotNull() | ||
.toSet(); | ||
|
||
final _packageNameFromImportRegex = RegExp(r'package:([^/]+)/.+'); |
Oops, something went wrong.