diff --git a/package.json b/package.json index 8cc23d5139..5d10d9cf75 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "dev-release-app": "run-s cljs:dev-release-app gulp:build", "clean": "gulp clean", "test": "run-s cljs:test cljs:run-test", + "report": "run-s cljs:report", "gulp:watch": "gulp watch", "gulp:build": "NODE_ENV=production gulp build", "cljs:watch": "clojure -M:cljs watch app publishing", @@ -43,6 +44,7 @@ "codemirror": "^5.58.1", "diff": "^4.0.2", "dropbox": "^5.2.0", + "ignore": "^5.1.8", "jszip": "^3.5.0", "localforage": "^1.7.3", "mousetrap": "^1.6.5", diff --git a/src/main/frontend/handler/file.cljs b/src/main/frontend/handler/file.cljs index 224ef70c8a..d99c56d4f5 100644 --- a/src/main/frontend/handler/file.cljs +++ b/src/main/frontend/handler/file.cljs @@ -16,7 +16,8 @@ [clojure.string :as string] [frontend.history :as history] [frontend.handler.project :as project-handler] - [lambdaisland.glogi :as log])) + [lambdaisland.glogi :as log] + ["ignore" :as Ignore])) (defn load-file [repo-url path] @@ -225,3 +226,10 @@ (let [path (:file/path file) content (db/get-file path)] (alter-file repo path content {:re-render-root? true})))) + +(defn ignore-files + [pattern paths] + (-> (Ignore) + (.add pattern) + (.filter (bean/->js paths)) + (bean/->clj))) diff --git a/src/main/frontend/handler/web/nfs.cljs b/src/main/frontend/handler/web/nfs.cljs index 39216bd1e8..36e2a76fe7 100644 --- a/src/main/frontend/handler/web/nfs.cljs +++ b/src/main/frontend/handler/web/nfs.cljs @@ -7,6 +7,7 @@ [frontend.util :as util] ["/frontend/utils" :as utils] [frontend.handler.repo :as repo-handler] + [frontend.handler.file :as file-handler] [frontend.idb :as idb] [frontend.state :as state] [clojure.string :as string] @@ -17,6 +18,22 @@ [frontend.config :as config] [lambdaisland.glogi :as log])) +(defn remove-ignore-files + [files] + (let [files (remove (fn [f] + (string/starts-with? (:file/path f) ".git/")) + files)] + (if-let [ignore-file (some #(when (= (:file/name %) ".gitignore") + %) files)] + (if-let [file (:file/file ignore-file)] + (p/let [content (.text file)] + (when content + (let [paths (set (file-handler/ignore-files content (map :file/path files)))] + (when (seq paths) + (filter (fn [f] (contains? paths (:file/path f))) files))))) + (p/resolved files)) + (p/resolved files)))) + (defn- ->db-files [dir-name result] (let [result (flatten (bean/->clj result))] @@ -25,7 +42,8 @@ get-attr #(gobj/get file %) path (-> (get-attr "webkitRelativePath") (string/replace-first (str dir-name "/") ""))] - {:file/path path + {:file/name (get-attr "name") + :file/path path :file/last-modified-at (get-attr "lastModified") :file/size (get-attr "size") :file/type (get-attr "type") @@ -61,7 +79,8 @@ _ (fs/add-nfs-file-handle! root-handle-path root-handle) _ (set-files! @path-handles) result (nth result 1) - files (->db-files dir-name result) + files (-> (->db-files dir-name result) + remove-ignore-files) markup-files (filter-markup-and-built-in-files files)] (-> (p/all (map (fn [file] (p/let [content (.text (:file/file file))] @@ -160,7 +179,8 @@ (fn [path handle] (swap! path-handles assoc path handle))) _ (set-files! @path-handles) - new-files (->db-files dir-name files-result) + new-files (-> (->db-files dir-name files-result) + remove-ignore-files) get-file-f (fn [path files] (some #(when (= (:file/path %) path) %) files)) {:keys [added modified deleted] :as diffs} (compute-diffs old-files new-files) ;; Use the same labels as isomorphic-git @@ -204,9 +224,16 @@ (defn- refresh! [repo] (when repo - (p/let [verified? (check-directory-permission! repo)] - (when verified? - (reload-dir! repo))))) + (reload-dir! repo) + ;; check permission is too slow + ;; (-> + ;; (p/let [verified? (check-directory-permission! repo)] + ;; (prn {:verified? verified?}) + ;; (when verified? + ;; (reload-dir! repo))) + ;; (p/catch (fn [error] + ;; (log/error :nfs/refresh-error error)))) +)) (defn supported? [] diff --git a/yarn.lock b/yarn.lock index 680fa53471..5877c7f355 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2131,7 +2131,7 @@ ignore@^4.0.3: resolved "https://registry.yarnpkg.com/ignore/-/ignore-4.0.6.tgz#750e3db5862087b4737ebac8207ffd1ef27b25fc" integrity sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg== -ignore@^5.1.4: +ignore@^5.1.4, ignore@^5.1.8: version "5.1.8" resolved "https://registry.yarnpkg.com/ignore/-/ignore-5.1.8.tgz#f150a8b50a34289b33e22f5889abd4d8016f0e57" integrity sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==