resolve static method

(GradleProjectInfo?, String?) resolve(
  1. String projectType,
  2. String cwd
)

Resolves GradleProjectInfo for projectType ('react-native' or 'kotlin') under cwd. Returns (null, error) with a user-facing message when the project doesn't match the expected layout.

Implementation

static (GradleProjectInfo?, String?) resolve(String projectType, String cwd) {
  if (projectType == 'react-native') {
    if (!File(p.join(cwd, 'package.json')).existsSync()) {
      return (null, 'Not a React Native project — package.json not found.');
    }
    final gradlePath = GradleParser.resolvePath(cwd);
    if (gradlePath == null) {
      return (
        null,
        'android/app/build.gradle(.kts) not found.\n'
            '  Run appflight init from your React Native project root.',
      );
    }
    final pkgJson = jsonDecode(
      File(p.join(cwd, 'package.json')).readAsStringSync(),
    ) as Map<String, dynamic>;
    return (
      _buildInfo(gradlePath, pkgJson['name'] as String? ?? '', 'android/app'),
      null,
    );
  }

  final gradlePath = GradleParser.resolvePath(cwd, projectType: 'kotlin');
  if (gradlePath == null) {
    return (
      null,
      'app/build.gradle(.kts) not found.\n'
          '  Run appflight init from your Android project root.',
    );
  }
  return (_buildInfo(gradlePath, p.basename(cwd), 'app'), null);
}