discoverSlangPackages function

Future<List<SlangPackageInfo>> discoverSlangPackages(
  1. String projectPath
)

Scan all packages and return only those with slang implementations Returns packages sorted with main package first, then dependencies

Implementation

Future<List<SlangPackageInfo>> discoverSlangPackages(String projectPath) async {
  final allPackages = await getPackageConfig(projectPath);
  final slangPackages = <SlangPackageInfo>[];

  // Get the main package name from pubspec.yaml
  final mainPackageName = await _getMainPackageName(projectPath);

  for (final pkg in allPackages) {
    // Skip pvtro itself
    if (pkg.name == 'pvtro') continue;

    // Check if package has slang support
    if (!await hasSlangSupport(pkg.path)) continue;

    // Find the translations.g.dart file
    final importPath = await findStringsFile(pkg.path, pkg.name);
    if (importPath == null) continue;

    final isMain = pkg.name == mainPackageName;

    slangPackages.add(SlangPackageInfo(
      name: pkg.name,
      path: pkg.path,
      importPath: importPath,
      isMainPackage: isMain,
    ));
  }

  // Sort: main package first, then dependencies alphabetically
  slangPackages.sort((a, b) {
    if (a.isMainPackage) return -1;
    if (b.isMainPackage) return 1;
    return a.name.compareTo(b.name);
  });

  return slangPackages;
}