Skip to content

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
BytesZero committed Dec 22, 2021
2 parents 0dd2f11 + 9954cba commit 106bbb3
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 22 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG-zh_CN.md
Original file line number Diff line number Diff line change
@@ -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` 目录
- 支持帮助说明查看
21 changes: 15 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion README-zh_CN.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
| [English](README.md) | 简体中文 |
| [English](https://github.com/yy1300326388/clear_flutter_build) | 简体中文 |
|-------|-------|

## cf
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
7 changes: 5 additions & 2 deletions bin/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ void main(List<String> 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
Expand Down Expand Up @@ -63,6 +63,9 @@ void main(List<String> arguments) {
case 'pods':
flutterCleanPods();
break;
case 'gradle':
flutterCleanGradle();
break;
default:
flutterCleanBuild();
}
Expand Down
85 changes: 74 additions & 11 deletions lib/cf_cli.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,29 @@
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<void> flutterCleanAll() async {
await forEachFlutterDir(
Directory.current.path,
clearBuild: true,
clearPods: true,
clearGradle: true,
);
print('🎉 All cleaned up');
}
Expand All @@ -31,36 +46,74 @@ Future<void> flutterCleanPods() async {
print('🎉 All cleaned up');
}

/// 清理 gradle
Future<void> flutterCleanGradle() async {
await forEachFlutterDir(
Directory.current.path,
clearBuild: false,
clearPods: false,
clearGradle: true,
);
print('🎉 All cleaned up');
}

/// 遍历 Flutter dir
Future<void> 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;
}
// 开始遍历
var fileList = Directory(path).listSync(followLinks: false);
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,
);
}
}
}
Expand All @@ -75,11 +128,21 @@ Future<void> runClean(String dirPath) async {
await Future.delayed(const Duration(milliseconds: 50));
}

// 执行 Pods 清理
// 执行 ios/Pods 清理
Future<void> 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<void> 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));
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Binary file removed release/cf
Binary file not shown.

0 comments on commit 106bbb3

Please sign in to comment.