detectProject method
Scans the directory at path and returns a ProjectInfo describing it.
Implementation
Future<ProjectInfo> detectProject(String path) async {
final dir = Directory(path);
if (!await dir.exists()) {
return ProjectInfo(
name: _dirName(path),
type: ProjectType.unknown,
rootPath: path,
);
}
// Try each detector in priority order.
final pubspec = File('$path/pubspec.yaml');
if (await pubspec.exists()) {
return _detectDartProject(path, pubspec);
}
final packageJson = File('$path/package.json');
if (await packageJson.exists()) {
return _detectNodeProject(path, packageJson);
}
final cargoToml = File('$path/Cargo.toml');
if (await cargoToml.exists()) {
return _detectRustProject(path, cargoToml);
}
final goMod = File('$path/go.mod');
if (await goMod.exists()) {
return _detectGoProject(path, goMod);
}
final pomXml = File('$path/pom.xml');
if (await pomXml.exists()) {
return _detectJavaProject(path, pomXml, isMaven: true);
}
final buildGradle = File('$path/build.gradle');
final buildGradleKts = File('$path/build.gradle.kts');
if (await buildGradle.exists() || await buildGradleKts.exists()) {
return _detectJavaProject(path, buildGradle, isMaven: false);
}
final gemfile = File('$path/Gemfile');
if (await gemfile.exists()) {
return _detectRubyProject(path, gemfile);
}
// Python — multiple markers.
final pyProject = File('$path/pyproject.toml');
final requirements = File('$path/requirements.txt');
final setupPy = File('$path/setup.py');
if (await pyProject.exists() ||
await requirements.exists() ||
await setupPy.exists()) {
return _detectPythonProject(path);
}
final packageSwift = File('$path/Package.swift');
if (await packageSwift.exists()) {
return _detectSwiftProject(path);
}
return ProjectInfo(
name: _dirName(path),
type: ProjectType.unknown,
rootPath: path,
);
}