docs_graph_helper.cljs 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. (ns ^:nbb-compatible frontend.test.docs-graph-helper
  2. "Helper fns for running tests against docs graph"
  3. (:require ["fs" :as fs]
  4. ["child_process" :as child-process]
  5. [clojure.string :as string]))
  6. (defn- slurp
  7. "Like clojure.core/slurp"
  8. [file]
  9. (str (fs/readFileSync file)))
  10. (defn- sh
  11. "Run shell cmd synchronously and print to inherited streams by default. Aims
  12. to be similar to babashka.tasks/shell"
  13. [cmd opts]
  14. (child-process/spawnSync (first cmd)
  15. (clj->js (rest cmd))
  16. (clj->js (merge {:stdio "inherit"} opts))))
  17. (defn build-graph-files
  18. [dir]
  19. (let [files (->> (str (.-stdout (sh ["git" "ls-files"]
  20. {:cwd dir :stdio nil})))
  21. string/split-lines
  22. (filter #(re-find #"^(pages|journals)" %))
  23. (map #(str dir "/" %)))]
  24. (mapv #(hash-map :file/path % :file/content (slurp %)) files)))
  25. (defn clone-docs-repo-if-not-exists
  26. [dir]
  27. (when-not (.existsSync fs dir)
  28. (sh ["git" "clone" "--depth" "1" "-b" "v0.6.7" "-c" "advice.detachedHead=false"
  29. "https://github.com/logseq/docs" dir] {})))