 (ns clojurescript.core
   (:require [clojure.string :as string]
+            [cljs.tools.reader.reader-types :as rt]
             [cljs.nodejs :as nodejs]
             [cljs.js :as cljsjs]
             [replumb.repl :as replumbrepl]

;; TODO not sure if process.cwd is a good default
(establish-load-path)

(defn ^:export eval [in-str]
  (replumb/read-eval-call
    (merge
      {:no-pr-str-on-value true
       :init-fn! replumbjs/init-fn!}
      (replumb/options
        :node
        (make-load-fn
          *load-paths*
          (fn [filename source-cb]
            (source-cb
              (cond 
                (re-find #"\.jar/" filename)
                (let [[jar-path path] (string/split filename ".jar/")
                      zip (AdmZip. (str jar-path ".jar"))]
                  (if (.getEntry zip path)
                    (.readAsText zip path)))
                (.existsSync fs filename)
                (node-read-file-sync filename)))))))
    handle-result
    in-str))


  (cljsjs/compile-str
    replumbrepl/st
    in-str ""
    (compile-options in-str)
    handle-result))

(set! *main-cli-fn* (fn []))