createFilepathsGenerator function

FigGenerator createFilepathsGenerator({
  1. List<String>? extensions,
  2. bool? directories,
  3. bool? files,
})

自定义文件路径生成器

Implementation

FigGenerator createFilepathsGenerator({
  List<String>? extensions,
  bool? directories,
  bool? files,
}) {
  return FigGenerator(
    template: ['filepaths'],
    filterTemplateSuggestions: (suggestions, context) {
      return suggestions.whereType<FigSuggestion>().where((suggestion) {
        final name = suggestion.nameSingle;
        if (name == null) return false;

        // 检查是否是目录(以 / 结尾)
        final isDirectory = name.endsWith('/');

        // 根据参数过滤
        if (directories != null && directories && !isDirectory) return false;
        if (files != null && files && isDirectory) return false;

        // 检查文件扩展名
        if (extensions != null && !isDirectory) {
          final hasExtension = extensions.any((ext) => name.endsWith(ext));
          if (!hasExtension) return false;
        }

        return true;
      }).toList();
    },
  );
}