(ns render
  (:require [clojure.edn :as edn]
            [reagent.dom.server :as dom]
            ["fs" :as fs]))

(defn main [args]
  (try
    (if-let [file-path (first args)]
      (let [content (fs/readFileSync file-path "utf8")
            hiccup (edn/read-string content)]
        (println (dom/render-to-static-markup hiccup)))
      (throw (js/Error. "No input file provided.")))
    (catch :default e
      (.error js/console (str "Error: " (.-message e)))
      (js/process.exit 1))))

(main *command-line-args*)
