detectProjectType function

ProjectType detectProjectType(
  1. Directory directory
)

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:

  1. pubspec.yaml with a top-level flutter: key, or one depending on the Flutter SDK → ProjectType.flutter
  2. pubspec.yamlProjectType.dart
  3. package.json + tsconfig.jsonProjectType.typescript
  4. 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;
}