1
0
Эх сурвалжийг харах

enhance: option to ignore built-ins for graph export

useful for lambda which has buggy built-in pages
Gabriel Horner 7 сар өмнө
parent
commit
5c07ff3fe7

+ 5 - 2
deps/db/script/diff_graphs.cljs

@@ -48,12 +48,15 @@
           (-> m
               (update :classes update-vals (fn [m]
                                              (update m :build/class-properties sort)))
-              ;; TODO: fix built-in views
+              ;; TODO: fix built-in views for schema export
               (update :pages-and-blocks (fn [pbs]
                                           (vec (remove #(= (:block/title (:page %)) common-config/views-page-name) pbs))))))
         diff (->> (data/diff (prepare-export-to-diff export-map) (prepare-export-to-diff export-map2))
                   butlast)]
-    (pprint/pprint diff)))
+    (if (= diff [nil nil])
+      (println "The two graphs are equal!")
+      (do (pprint/pprint diff)
+          (js/process.exit 1)))))
 
 (when (= nbb/*file* (nbb/invoked-file))
   (-main *command-line-args*))

+ 11 - 5
deps/db/script/export_graph.cljs

@@ -39,6 +39,8 @@
    :exclude-namespaces {:alias :e
                         :coerce #{}
                         :desc "Namespaces to exclude from properties and classes"}
+   :ignore-built-ins? {:alias :i
+                       :desc "Ignore built-in pages"}
    :export-options {:alias :E
                     :desc "Raw options map to pass to export"}})
 
@@ -51,13 +53,17 @@
             (js/process.exit 1))
         [dir db-name] (get-dir-and-db-name graph-dir)
         conn (sqlite-cli/open-db! dir db-name)
-        export-options (merge (select-keys options [:include-timestamps? :exclude-namespaces])
+        export-options (merge (select-keys options [:include-timestamps? :exclude-namespaces :ignore-built-ins?])
                               (edn/read-string (:export-options options)))
         export-map (sqlite-export/build-export @conn {:export-type :graph :graph-options export-options})]
-    (when (:file options)
-      (fs/writeFileSync (resolve-path (:file options))
-                        (with-out-str (pprint/pprint export-map))))
-    (pprint/pprint export-map)))
+    (if (:file options)
+      (do
+        (println "Exported" (count (:properties export-map)) "properties,"
+                 (count (:properties export-map)) "classes and"
+                 (count (:pages-and-blocks export-map)) "pages")
+        (fs/writeFileSync (resolve-path (:file options))
+                          (with-out-str (pprint/pprint export-map))))
+      (pprint/pprint export-map))))
 
 (when (= nbb/*file* (nbb/invoked-file))
   (-main *command-line-args*))

+ 6 - 1
deps/db/src/logseq/db/sqlite/export.cljs

@@ -519,7 +519,12 @@
                                ;; TODO: Configure so that no ontologies are exported
                                (build-page-export* db eid page-blocks* (merge options {:include-uuid-fn (constantly true)}))))
                            page-ids)
-        pages-export {:pages-and-blocks (mapcat :pages-and-blocks page-exports)
+        pages-and-blocks* (mapcat :pages-and-blocks page-exports)
+        pages-and-blocks (if (:ignore-built-ins? options)
+                           (vec (remove #(get-in % [:page :build/properties :logseq.property/built-in?])
+                                        pages-and-blocks*))
+                           pages-and-blocks*)
+        pages-export {:pages-and-blocks pages-and-blocks
                       :pvalue-uuids (set (mapcat :pvalue-uuids page-exports))}]
     pages-export))