run method
Runs this command.
The return value is wrapped in a Future
if necessary and returned by
CommandRunner.runCommand
.
Implementation
@override
void run() async {
bool fastMode = argResults?['fast'] ?? false;
// Memuat file pubspec.yaml
var pubspecFile = File('pubspec.yaml');
if (!pubspecFile.existsSync()) {
MsgUtils.showError("pubspec.yaml file not found in the project.");
return;
}
var pubspecContent = pubspecFile.readAsStringSync();
var yamlMap = loadYaml(pubspecContent);
// Memuat dependencies dari pubspec.yaml
var dependencies = yamlMap['dependencies']?.keys.toList() ?? [];
if (dependencies.isEmpty) {
MsgUtils.showError("No dependencies found in pubspec.yaml.");
return;
}
print("---------------------------------------");
String projectName = yamlMap['name'];
print(" SCANNING PROJECT $projectName");
print("---------------------------------------");
// Scan dependencies yang digunakan di project
var unusedDependencies = <String>[];
MsgUtils.showInfo("Scanning unused dependencies...");
for (var dependency in dependencies) {
var result = await scanDependency(dependency);
if (!result) {
unusedDependencies.add(dependency);
}
}
// Menampilkan hasil scan
if (unusedDependencies.isEmpty) {
MsgUtils.showSuccess("All dependencies are in use.");
return;
} else {
MsgUtils.showInfo("Unused dependencies found...");
print("---------------------------------------");
unusedDependencies.asMap().forEach((i, dep) {
MsgUtils.showList("${i + 1}. $dep");
});
print("---------------------------------------");
if (fastMode) {
removeDependencies(unusedDependencies);
} else {
// Removing options
await showOptions(unusedDependencies);
}
}
}