detectProjectType function
Detects the ProjectType of directory — which manifest the directory
carries, not which pipeline gg should run on it. For the latter, use
checkProjectType.
Detection rules, in order:
pubspec.yamlwith a top-levelflutter:key, or one depending on the Flutter SDK → ProjectType.flutterpubspec.yaml→ ProjectType.dartpackage.json+tsconfig.json→ ProjectType.typescript- otherwise → ProjectType.none
Note that rule 2 also catches hybrids: a repo with both manifests reports its Dart side here, which is exactly what callers keeping the two sides in lock-step need (version files, manifest bumps).
Implementation
ProjectType detectProjectType(Directory directory) {
final pubspec = File('${directory.path}/pubspec.yaml');
if (pubspec.existsSync()) {
final content = pubspec.readAsStringSync();
if (_hasTopLevelFlutterKey(content) || _dependsOnFlutterSdk(content)) {
return ProjectType.flutter;
}
return ProjectType.dart;
}
final packageJson = File('${directory.path}/package.json');
final tsconfig = File('${directory.path}/tsconfig.json');
if (packageJson.existsSync() && tsconfig.existsSync()) {
return ProjectType.typescript;
}
return ProjectType.none;
}