From 2f8ab3f0588c0af6e72a627634692f959dc8d430 Mon Sep 17 00:00:00 2001 From: Yegor Date: Thu, 10 Oct 2019 07:15:24 -0700 Subject: [PATCH] Add "felt clean" command (flutter/engine#13042) Add "felt clean" command --- engine/src/flutter/lib/web_ui/dev/clean.dart | 58 ++++++++++++++++++++ engine/src/flutter/lib/web_ui/dev/felt.dart | 2 + 2 files changed, 60 insertions(+) create mode 100644 engine/src/flutter/lib/web_ui/dev/clean.dart diff --git a/engine/src/flutter/lib/web_ui/dev/clean.dart b/engine/src/flutter/lib/web_ui/dev/clean.dart new file mode 100644 index 0000000000..41fd811947 --- /dev/null +++ b/engine/src/flutter/lib/web_ui/dev/clean.dart @@ -0,0 +1,58 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +import 'dart:async'; +import 'dart:io' as io; + +import 'package:args/command_runner.dart'; +import 'package:path/path.dart' as path; + +import 'environment.dart'; + +class CleanCommand extends Command { + CleanCommand() { + argParser + ..addFlag( + 'ninja', + defaultsTo: false, + help: 'Also clean up the engine out directory with ninja output.', + ); + } + + @override + String get name => 'clean'; + + bool get _alsoCleanNinja => argResults['ninja']; + + @override + String get description => 'Deletes build caches and artifacts.'; + + @override + FutureOr run() async { + final io.Directory assetsDir = io.Directory(path.join( + environment.webUiRootDir.path, 'lib', 'assets' + )); + final Iterable fontFiles = assetsDir + .listSync() + .whereType() + .where((io.File file) => file.path.endsWith('.ttf')); + + final List thingsToBeCleaned = [ + environment.webUiDartToolDir, + environment.webUiBuildDir, + io.File(path.join(environment.webUiRootDir.path, '.packages')), + io.File(path.join(environment.webUiRootDir.path, 'pubspec.lock')), + ...fontFiles, + if (_alsoCleanNinja) + environment.outDir, + ]; + + await Future.wait( + thingsToBeCleaned + .where((io.FileSystemEntity entity) => entity.existsSync()) + .map((io.FileSystemEntity entity) => entity.delete(recursive: true)) + ); + return true; + } +} diff --git a/engine/src/flutter/lib/web_ui/dev/felt.dart b/engine/src/flutter/lib/web_ui/dev/felt.dart index b1754c1e11..1830c051b9 100644 --- a/engine/src/flutter/lib/web_ui/dev/felt.dart +++ b/engine/src/flutter/lib/web_ui/dev/felt.dart @@ -7,6 +7,7 @@ import 'dart:io' as io; import 'package:args/command_runner.dart'; import 'build.dart'; +import 'clean.dart'; import 'licenses.dart'; import 'test_runner.dart'; @@ -14,6 +15,7 @@ CommandRunner runner = CommandRunner( 'felt', 'Command-line utility for building and testing Flutter web engine.', ) + ..addCommand(CleanCommand()) ..addCommand(LicensesCommand()) ..addCommand(TestCommand()) ..addCommand(BuildCommand());