generatePackages top-level property

FigGenerator generatePackages
final

Implementation

final FigGenerator generatePackages = FigGenerator(
  script: [
    'bash',
    '-c',
    "command find ~/.yalc/packages -maxdepth 4 -iname 'package.json'",
  ],
  postProcess: (String out, [List<String>? tokens]) {
    return out
        .split('\n')
        .map((path) {
          final pathArr = path.split('/');
          final packagesIndex = pathArr.indexOf('packages');
          if (packagesIndex == -1 || pathArr.length < 2) return null;

          final subPath = pathArr.sublist(
            packagesIndex + 1,
            pathArr.length - 2,
          );
          final version = pathArr[pathArr.length - 2];
          return '${subPath.join('/')}@$version';
        })
        .whereType<String>()
        .map((path) => FigSuggestion(
              name: path,
              icon: '📦',
              description: path,
            ))
        .toList();
  },
);