From 93c96cf6fad64d45c55a2f23438e248fa8b3a96d Mon Sep 17 00:00:00 2001
From: David Taylor <david@taylorhq.com>
Date: Mon, 9 Oct 2023 12:03:02 +0100
Subject: [PATCH] DEV: Filter files included by theme DirectoryImporter
 (#23842)

To match discourse_theme CLI behavior, we should skip hidden files/directories (e.g. `.git`), and two regular directories: `node_modules/` and `src/`.

Without these excludes, it's very easy for a theme to hit the file count limit. e.g. when trying this with discourse-kanban-board, I got:

> The number of files (20366) in the theme has exceeded the maximum allowed number of files (1024)
---
 lib/theme_store/directory_importer.rb | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/theme_store/directory_importer.rb b/lib/theme_store/directory_importer.rb
index 50c041e406c..c8cbbe5a0a5 100644
--- a/lib/theme_store/directory_importer.rb
+++ b/lib/theme_store/directory_importer.rb
@@ -8,7 +8,10 @@ module ThemeStore
 
     def import!
       FileUtils.mkdir_p(temp_folder)
-      FileUtils.cp_r("#{@theme_dir}/.", temp_folder)
+      Dir.glob("*", base: @theme_dir) do |entry|
+        next if %w[node_modules src spec].include?(entry)
+        FileUtils.cp_r(File.join(@theme_dir, entry), temp_folder)
+      end
     end
   end
 end