chore: change Flutter build mode to release in local.properties and add an empty line to JSON response schema
This commit is contained in:
100
tools/check_unused_assets.dart
Normal file
100
tools/check_unused_assets.dart
Normal file
@@ -0,0 +1,100 @@
|
||||
/// اسکریپت برای بررسی Assets استفاده نشده
|
||||
///
|
||||
/// استفاده:
|
||||
/// dart run tools/check_unused_assets.dart
|
||||
|
||||
import 'dart:io';
|
||||
|
||||
void main() async {
|
||||
print('🔍 در حال بررسی Assets استفاده نشده...\n');
|
||||
|
||||
// لیست تمام assets
|
||||
final assets = <String>[];
|
||||
|
||||
// خواندن assets از پوشهها
|
||||
final assetDirs = [
|
||||
'assets/icons',
|
||||
'assets/images',
|
||||
'assets/logos',
|
||||
'assets/vec',
|
||||
'assets/anim',
|
||||
];
|
||||
|
||||
for (final dir in assetDirs) {
|
||||
final directory = Directory(dir);
|
||||
if (await directory.exists()) {
|
||||
await for (final entity in directory.list(recursive: true)) {
|
||||
if (entity is File) {
|
||||
final relativePath = entity.path.replaceAll('\\', '/');
|
||||
assets.add(relativePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
print('📦 تعداد کل Assets: ${assets.length}\n');
|
||||
|
||||
// جستجو در کد
|
||||
final usedAssets = <String>{};
|
||||
final codeFiles = <File>[];
|
||||
|
||||
// جستجو در پوشه lib و packages
|
||||
await _findDartFiles(Directory('lib'), codeFiles);
|
||||
await _findDartFiles(Directory('packages'), codeFiles);
|
||||
|
||||
print('📝 در حال جستجو در ${codeFiles.length} فایل Dart...\n');
|
||||
|
||||
for (final file in codeFiles) {
|
||||
final content = await file.readAsString();
|
||||
|
||||
for (final asset in assets) {
|
||||
// استخراج نام فایل از مسیر
|
||||
final fileName = asset.split('/').last;
|
||||
final fileNameWithoutExt = fileName.split('.').first;
|
||||
|
||||
// جستجوی استفاده در کد
|
||||
if (content.contains(asset) ||
|
||||
content.contains(fileName) ||
|
||||
content.contains(fileNameWithoutExt) ||
|
||||
content.contains('Assets.${_getAssetCategory(asset)}')) {
|
||||
usedAssets.add(asset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// پیدا کردن assets استفاده نشده
|
||||
final unusedAssets = assets.where((asset) => !usedAssets.contains(asset)).toList();
|
||||
|
||||
print('✅ Assets استفاده شده: ${usedAssets.length}');
|
||||
print('❌ Assets استفاده نشده: ${unusedAssets.length}\n');
|
||||
|
||||
if (unusedAssets.isNotEmpty) {
|
||||
print('⚠️ لیست Assets استفاده نشده:\n');
|
||||
for (final asset in unusedAssets) {
|
||||
print(' - $asset');
|
||||
}
|
||||
print('\n💡 میتونید این فایلها رو حذف کنید تا حجم اپ کم بشه.');
|
||||
} else {
|
||||
print('🎉 همه Assets استفاده میشن!');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _findDartFiles(Directory dir, List<File> files) async {
|
||||
if (!await dir.exists()) return;
|
||||
|
||||
await for (final entity in dir.list(recursive: true)) {
|
||||
if (entity is File && entity.path.endsWith('.dart')) {
|
||||
files.add(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String _getAssetCategory(String assetPath) {
|
||||
if (assetPath.contains('icons/')) return 'icons';
|
||||
if (assetPath.contains('images/')) return 'images';
|
||||
if (assetPath.contains('logos/')) return 'logos';
|
||||
if (assetPath.contains('vec/')) return 'vec';
|
||||
if (assetPath.contains('anim/')) return 'anim';
|
||||
return 'unknown';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user