Convert roam namespaces to cljs

The clj functionality was only for tests and those tests no longer
exist for clj. Also removed unused dependency
pull/5192/head
Gabriel Horner 2022-05-04 15:14:09 -04:00
parent 823b8ec39e
commit ca9cc2454f
3 changed files with 37 additions and 53 deletions

View File

@ -1,7 +1,6 @@
{:paths ["src/main" "src/electron" "src/workspaces" "templates"] {:paths ["src/main" "src/electron" "src/workspaces" "templates"]
:deps :deps
{org.clojure/clojure {:mvn/version "1.10.0"} {org.clojure/clojure {:mvn/version "1.10.0"}
cheshire/cheshire {:mvn/version "5.10.0"}
rum/rum {:mvn/version "0.12.9"} rum/rum {:mvn/version "0.12.9"}
datascript/datascript {:mvn/version "1.3.8"} datascript/datascript {:mvn/version "1.3.8"}
datascript-transit/datascript-transit {:mvn/version "0.3.0"} datascript-transit/datascript-transit {:mvn/version "0.3.0"}

View File

@ -1,6 +1,4 @@
(ns frontend.external (ns frontend.external
;; Wonky cljs detection
#_:clj-kondo/ignore
(:require [frontend.external.roam :refer [->Roam]] (:require [frontend.external.roam :refer [->Roam]]
[frontend.external.protocol :as protocol])) [frontend.external.protocol :as protocol]))

View File

@ -1,12 +1,6 @@
(ns frontend.external.roam (ns frontend.external.roam
;; TODO: Convert this ns and upstream dependents to .cljs. .clj was only for tests (:require [cljs-bean.core :as bean]
;; and those tests have been removed
(:require #?(:cljs [cljs-bean.core :as bean]
:clj [cheshire.core :as json])
;; TODO: clj-kondo incorrectly thinks these requires are unused
#_:clj-kondo/ignore
[frontend.external.protocol :as protocol] [frontend.external.protocol :as protocol]
#_:clj-kondo/ignore
[frontend.date :as date] [frontend.date :as date]
[medley.core :as medley] [medley.core :as medley]
[clojure.walk :as walk] [clojure.walk :as walk]
@ -42,12 +36,8 @@
(defn macro-transform (defn macro-transform
[text] [text]
(string/replace text macro-pattern (fn [[original text]] (string/replace text macro-pattern (fn [[original text]]
;; Disable clj warning since clj is unused
#_:clj-kondo/ignore
(let [[name arg] (gp-util/split-first ":" text)] (let [[name arg] (gp-util/split-first ":" text)]
(if name (if name
;; TODO: Why unresolved var
#_:clj-kondo/ignore
(let [name (text/page-ref-un-brackets! name)] (let [name (text/page-ref-un-brackets! name)]
(util/format "{{%s %s}}" name arg)) (util/format "{{%s %s}}" name arg))
original))))) original)))))
@ -109,48 +99,45 @@
(defn json->edn (defn json->edn
[raw-string] [raw-string]
#?(:cljs (-> raw-string js/JSON.parse bean/->clj) (-> raw-string js/JSON.parse bean/->clj))
:clj (-> raw-string json/parse-string clojure.walk/keywordize-keys)))
#?(:cljs (defn ->file
(do [page-data]
(defn ->file (let [{:keys [create-time title children edit-time]} page-data
[page-data] initial-level 1
(let [{:keys [create-time title children edit-time]} page-data text (when (seq children)
initial-level 1 (when-let [text (children->text children (dec initial-level))]
text (when (seq children) (let [journal? (date/valid-journal-title? title)
(when-let [text (children->text children (dec initial-level))] front-matter (if journal?
(let [journal? (date/valid-journal-title? title) ""
front-matter (if journal? (util/format "---\ntitle: %s\n---\n\n" title))]
"" (str front-matter (transform text)))))]
(util/format "---\ntitle: %s\n---\n\n" title))] (when (and (not (string/blank? title))
(str front-matter (transform text)))))] text)
(when (and (not (string/blank? title)) {:title title
text) :created-at create-time
{:title title :last-modified-at edit-time
:created-at create-time :text text})))
:last-modified-at edit-time
:text text})))
(defn ->files (defn ->files
[edn-data] [edn-data]
(load-all-refed-uids! edn-data) (load-all-refed-uids! edn-data)
(let [files (map ->file edn-data) (let [files (map ->file edn-data)
files (remove #(nil? (:title %)) files) files (remove #(nil? (:title %)) files)
files (group-by (fn [f] (string/lower-case (:title f))) files (group-by (fn [f] (string/lower-case (:title f)))
files)] files)]
(map (map
(fn [[_ [fst & others]]] (fn [[_ [fst & others]]]
(assoc fst :text (assoc fst :text
(->> (map :text (cons fst others)) (->> (map :text (cons fst others))
(interpose "\n") (interpose "\n")
(apply str)))) (apply str))))
files))) files)))
(defrecord Roam [] (defrecord Roam []
protocol/External protocol/External
(toMarkdownFiles [_this content _config] (toMarkdownFiles [_this content _config]
(-> content json->edn ->files))))) (-> content json->edn ->files)))
(comment (comment
(defonce test-roam-json (frontend.db/get-file "same.json")) (defonce test-roam-json (frontend.db/get-file "same.json"))