allDependenciesGenerator top-level property

FigGenerator allDependenciesGenerator
final

Implementation

final FigGenerator allDependenciesGenerator = FigGenerator(
  script: ['yarn', 'list', '--depth=0', '--json'],
  postProcess: (String out, [List<String>? tokens]) {
    if (out.trim().isEmpty) return <FigSuggestion>[];

    try {
      final packageContent = jsonDecode(out) as Map<String, dynamic>;
      final trees = packageContent['data']?['trees'] as List<dynamic>?;

      if (trees == null) return <FigSuggestion>[];

      return trees.map<FigSuggestion>((dependency) {
        final name =
            (dependency as Map<String, dynamic>)['name']?.toString() ?? '';
        final packageName = name.split('@')[0];
        return FigSuggestion(
          name: packageName,
          icon: '📦',
        );
      }).toList();
    } catch (e) {
      print('Error in allDependenciesGenerator: $e');
      return <FigSuggestion>[];
    }
  },
);