ProjectInfoCollector constructor
ProjectInfoCollector()
Implementation
ProjectInfoCollector() {
String rootDir = p.current;
Set<PackageInfo> packages = HashSet();
Directory(rootDir)
.listSync(recursive: true)
.whereType<Directory>()
.forEach((dir) {
String pubspecPath = p.join(dir.path, "pubspec.yaml");
if (FileSystemEntity.isFileSync(pubspecPath)) {
final yamlNode = loadYamlNode(File(pubspecPath).readAsStringSync(),
sourceUrl: Uri.parse(pubspecPath));
final yamlMap = (yamlNode as YamlMap).nodes;
final dependencies = yamlMap["dependencies"] as YamlMap?;
final isFlutterProject =
dependencies != null && dependencies["flutter"] != null;
packages.add(PackageInfo(
name: yamlMap["name"]?.value ?? "unknown",
path: p.relative(dir.path, from: rootDir),
version: yamlMap["version"]?.value ?? "unknown",
description: yamlMap["description"]?.value ?? "unknown",
isFlutterProject: isFlutterProject,
));
}
});
bool projectHasPubspec =
FileSystemEntity.isFileSync(p.join(rootDir, "pubspec.yaml"));
bool isFlutterProject = false;
if (projectHasPubspec) {
final yamlNodeProject = loadYamlNode(
File(p.join(rootDir, "pubspec.yaml")).readAsStringSync(),
sourceUrl: Uri.parse(p.join(rootDir, "pubspec.yaml")));
final yamlMapProject = (yamlNodeProject as YamlMap).nodes;
final dependenciesProject = yamlMapProject["dependencies"] as YamlMap?;
isFlutterProject =
dependenciesProject != null && dependenciesProject["flutter"] != null;
}
projectInfo = ProjectInfo(
rootDir: rootDir,
packages: packages,
name: p.basename(rootDir),
hasPubspec: projectHasPubspec,
isFlutterProject: projectHasPubspec && isFlutterProject,
);
}