Skip to content

Commit

Permalink
Fix: vendor parser + move it to _firn/bin in setup
Browse files Browse the repository at this point in the history
  • Loading branch information
teesloane committed Mar 24, 2020
1 parent 31c0525 commit b9259f7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 18 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
[cli-matic "0.3.11"]
[org.clojure/clojure "1.9.0"]]


:resource-paths ["resources"]

:native-image {:name "firn" ;; name of output image, optional
:graal-bin "/Users/tees/Downloads/graalvm-ce-java11-20.0.0/Contents/Home/bin/native-image" ;; path to GraalVM home, optional
Expand Down
31 changes: 17 additions & 14 deletions src/firn/build.clj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
[firn.util :as u])
(:gen-class))

(def PARSER-PATH "resources/parser")

(defn- prepare-config
"Takes a path to files (or CWD) and makes a config with it."
[{:keys [path]}]
Expand All @@ -33,16 +31,20 @@
(s/replace (re-pattern files-dirname) (str out-comb))))) ;; < str to make linter happy.

(defn new-site
"Creates the folders needed for a new site in your wiki directory."
([opts]
(println "Creating a _firn site in this directory.")
(let [config (-> opts prepare-config)]
(fs/mkdirs (config :layouts-dir))
(fs/mkdirs (config :partials-dir))))
([_ config]
(fs/mkdirs (config :layouts-dir))
(fs/mkdirs (config :partials-dir))))
"Creates the folders needed for a new site in your wiki directory.
Copies the parser bin into the _firn site At least until graal is avail."
[cmds & args]
(let [new-config (-> cmds prepare-config)
existing-config (first args)
config (if (nil? cmds) existing-config new-config)
parser-out-path (io/file (str (config :bin-dir) "/parser"))]

(fs/mkdirs (config :layouts-dir))
(fs/mkdirs (config :bin-dir))
(fs/mkdirs (config :partials-dir))
;; copy parser from /resources into _firn/bin/ and make it executable.
(-> "parser/bin/parser" io/resource io/input-stream (io/copy parser-out-path))
(fs/chmod "+x" parser-out-path)))

(defn setup
"Creates folders for output, slurps in layouts and partials.
Expand All @@ -62,8 +64,9 @@

(defn parse!
"Shells out to the rust binary to parse the org-mode file."
[file-str]
(let [res (sh/sh PARSER-PATH file-str)]
[config file-str]
(let [parser (str (config :bin-dir) "/parser")
res (sh/sh parser file-str)]
(if-not (= (res :exit) 0)
(prn "Orgize failed to parse file." file-str res)
(res :out))))
Expand All @@ -72,7 +75,7 @@
"Pulls :curr-file from config > parses > put into config with new vals"
[config]
(let [file-orig (-> config :curr-file :original)
file-parsed (->> file-orig slurp parse!)
file-parsed (->> file-orig slurp (parse! config))
file-name (-> file-orig .getName (s/split #"\.") (first))]
(config/update-curr-file config {:name file-name :as-json file-parsed})))

Expand Down
1 change: 1 addition & 0 deletions src/firn/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
(merge starting-config
{:layouts-dir (str files-dir "/_firn/layouts/")
:partials-dir (str files-dir "/_firn/partials/")
:bin-dir (str files-dir "/_firn/bin/")
:media-dir (str files-dir "/" (starting-config :media-dir))
:out-media-dir (str files-dir "/_firn/_site/" (starting-config :media-dir))
:out-dirpath (str files-dir "/" (starting-config :out-dirname))
Expand Down
File renamed without changes.
6 changes: 3 additions & 3 deletions test/firn/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
(fs/delete-dir (config-sample :out-dirpath)) ; clear it out!
(build/all-files {:path dir-to-build}))

(main-runner wiki-dir)
;; (main-runner test-dir)
;; (main-runner wiki-dir)
(main-runner test-dir)


(build/new-site {:path wiki-dir})
(build/new-site {:path test-dir})

0 comments on commit b9259f7

Please sign in to comment.