diff --git a/CHANGELOG-zh_CN.md b/CHANGELOG-zh_CN.md new file mode 100644 index 0000000..b41ccff --- /dev/null +++ b/CHANGELOG-zh_CN.md @@ -0,0 +1,20 @@ +| [English](https://github.com/yy1300326388/clear_flutter_build/CHANGELOG.md) | 简体中文 | +|-------|-------| + +## 1.2.0 + +- 优化显示清理文件夹全路径 +- 优化处理 `package/example` 的情况 +- 新增 `android/.gradle` 文件夹的清理,使用 `cf -m gradle` + +## 1.1.0 + +- 优化 mode 的执行 +- 支持 pub 安装 + +## 1.0.0 + +- 完成第一个版本 +- 支持清理 `build` 目录 +- 支持清理 `ios/Pods` 目录 +- 支持帮助说明查看 diff --git a/CHANGELOG.md b/CHANGELOG.md index 98e0b15..59e475b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,11 +1,20 @@ +| English | [简体中文](https://github.com/yy1300326388/clear_flutter_build/CHANGELOG-zh_CN.md) | +|-------|-------| + +## 1.2.0 + +- Optimize the display of the full path of the cleanup folder +- Optimize the handling of `package/example` +- Added cleaning of `android/.gradle` folder, use `cf - m gradle` + ## 1.1.0 -- 优化 mode 的执行 -- 支持 pub 安装 +- Optimize the execution of mode +- Support pub installation ## 1.0.0 -- 完成第一个版本 -- 支持清理 build 目录 -- 支持清理 ios/Pods 目录 -- 支持帮助说明查看 +- Complete the first version +- Support cleaning up the `build` directory +- Support cleaning up the `ios/Pods` directory +- Support help description view diff --git a/README-zh_CN.md b/README-zh_CN.md index 735f4da..eca8c33 100644 --- a/README-zh_CN.md +++ b/README-zh_CN.md @@ -1,4 +1,4 @@ -| [English](README.md) | 简体中文 | +| [English](https://github.com/yy1300326388/clear_flutter_build) | 简体中文 | |-------|-------| ## cf diff --git a/README.md b/README.md index d79012a..388e7dc 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ -| English | [简体中文](README-zh_CN.md) | +| English | [简体中文](https://github.com/yy1300326388/clear_flutter_build/README-zh_CN.md) | |-------|-------| ## cf(Clean Flutter) +![](https://img.shields.io/pub/v/cf_cli?logo=Dart&logoColor=FFFFFF) ![](https://img.shields.io/pub/v/cf_cli?logo=Dart&logoColor=FFFFFF) diff --git a/bin/main.dart b/bin/main.dart index 8c25d00..43aca09 100644 --- a/bin/main.dart +++ b/bin/main.dart @@ -13,9 +13,9 @@ void main(List arguments) { 'mode', abbr: 'm', defaultsTo: 'build', - allowed: ['build', 'pods', 'all'], + allowed: ['build', 'pods', 'gradle', 'all'], help: - '🚀 Set the cleanup mode build is the build folder, pods is the ios/Pods folder, all folders', + '🚀 Set the cleanup mode build is the build folder, pods is the ios/Pods folder, gradle is the android/.gradle folder, all folders', ); // 添加 version @@ -63,6 +63,9 @@ void main(List arguments) { case 'pods': flutterCleanPods(); break; + case 'gradle': + flutterCleanGradle(); + break; default: flutterCleanBuild(); } diff --git a/lib/cf_cli.dart b/lib/cf_cli.dart index 5fe8426..e81bb12 100644 --- a/lib/cf_cli.dart +++ b/lib/cf_cli.dart @@ -3,7 +3,21 @@ import 'dart:io'; /// cli 版本号 -const String kCliVersion = '1.1.0'; +const String kCliVersion = '1.2.0'; + +// pubspec.yaml +const String kPubspecYaml = 'pubspec.yaml'; +// example +const String kExampleDir = 'example'; + +// build +const String kBuildDir = 'build'; + +// ios/Pods +const String kIosPodsDir = 'ios/Pods'; + +// android/.gradle +const String kAndroidDir = 'android/.gradle'; /// 清理全部 Future flutterCleanAll() async { @@ -11,6 +25,7 @@ Future flutterCleanAll() async { Directory.current.path, clearBuild: true, clearPods: true, + clearGradle: true, ); print('🎉 All cleaned up'); } @@ -31,16 +46,29 @@ Future flutterCleanPods() async { print('🎉 All cleaned up'); } +/// 清理 gradle +Future flutterCleanGradle() async { + await forEachFlutterDir( + Directory.current.path, + clearBuild: false, + clearPods: false, + clearGradle: true, + ); + print('🎉 All cleaned up'); +} + /// 遍历 Flutter dir Future forEachFlutterDir(String path, - {bool clearBuild = true, bool clearPods = false}) async { + {bool clearBuild = true, + bool clearPods = false, + bool clearGradle = false}) async { // 不是文件夹退出 if (!await FileSystemEntity.isDirectory(path)) { return; } // 隐藏文件退出 if (path.split(Platform.pathSeparator).last.startsWith('.')) { - print('🙈 Hidden folder skip'); + // print('🙈 Hidden folder skip'); return; } // 开始遍历 @@ -48,19 +76,44 @@ Future forEachFlutterDir(String path, var fileNameList = fileList.map((e) => e.path.split(Platform.pathSeparator).last).toList(); // 检查 Flutter 目录 - if (fileNameList.contains('pubspec.yaml')) { + if (fileNameList.contains(kPubspecYaml)) { + // 处理 package 有 example 的情况 + if (fileNameList.contains(kExampleDir)) { + String exampleDirPath = '$path${Platform.pathSeparator}$kExampleDir'; + if (Directory(exampleDirPath).existsSync()) { + await forEachFlutterDir( + exampleDirPath, + clearBuild: clearBuild, + clearPods: clearPods, + clearGradle: clearGradle, + ); + return; + } + } // 清理 build - if (clearBuild && fileNameList.contains('build')) { + if (clearBuild && fileNameList.contains(kBuildDir)) { await runClean(path); } // 清理 Pods - if (clearPods && Directory('$path/ios/Pods').existsSync()) { + if (clearPods && + Directory('$path${Platform.pathSeparator}$kIosPodsDir').existsSync()) { await runPodsClean(path); } + + // 清理 gradle + if (clearGradle && + Directory('$path${Platform.pathSeparator}$kAndroidDir').existsSync()) { + await runGradleClean(path); + } } else { - // print('没有 Flutter 目录,继续遍历:$path'); + // 没有 Flutter 目录,继续遍历:$path for (var file in fileList) { - forEachFlutterDir(file.path); + await forEachFlutterDir( + file.path, + clearBuild: clearBuild, + clearPods: clearPods, + clearGradle: clearGradle, + ); } } } @@ -75,11 +128,21 @@ Future runClean(String dirPath) async { await Future.delayed(const Duration(milliseconds: 50)); } -// 执行 Pods 清理 +// 执行 ios/Pods 清理 Future runPodsClean(String dirPath) async { - print('🧹 Cleaning up Pods:$dirPath'); + print('🧹 Cleaning up Pods:$dirPath${Platform.pathSeparator}$kIosPodsDir'); + var result = + await Process.run('rm', ['-rf', kIosPodsDir], workingDirectory: dirPath); + print(result.stdout); + // 延迟 50 毫秒 + await Future.delayed(const Duration(milliseconds: 50)); +} + +// 执行 android/.gradle 清理 +Future runGradleClean(String dirPath) async { + print('🧹 Cleaning up gradle:$dirPath${Platform.pathSeparator}$kAndroidDir'); var result = - await Process.run('rm', ['-rf', 'ios/Pods'], workingDirectory: dirPath); + await Process.run('rm', ['-rf', kAndroidDir], workingDirectory: dirPath); print(result.stdout); // 延迟 50 毫秒 await Future.delayed(const Duration(milliseconds: 50)); diff --git a/pubspec.yaml b/pubspec.yaml index 4959f25..ba19fe0 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: cf_cli description: Clean up the [build, ios/Pods] directory of Flutter projects in batches, optimize computer space -version: 1.1.0 #在 lib/cf.dart kCliVersion 设置版本 +version: 1.2.0 #在 lib/cf.dart kCliVersion 设置版本 homepage: https://github.com/yy1300326388 environment: diff --git a/release/cf b/release/cf deleted file mode 100755 index bbfbc34..0000000 Binary files a/release/cf and /dev/null differ