Skip to content

Commit

Permalink
[#2] make cli app work with local files
Browse files Browse the repository at this point in the history
  • Loading branch information
krvital committed Jul 17, 2024
1 parent 6c192ad commit acce0bc
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 25 deletions.
30 changes: 27 additions & 3 deletions src/aidbox_sdk/core.clj
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
(ns aidbox-sdk.core
(:gen-class)
(:require
[clojure.tools.cli :as cli]
[clojure.java.io :as io]
[aidbox-sdk.generator :as generator]))

(defn url
"Safe version of as-url function"
[s]
(try
(io/as-url s)
(catch java.net.MalformedURLException _ nil)
(catch java.net.URISyntaxException _ nil)))

(defn resource [path]
(or (url path)
(io/as-file path)))

(defn -main [& args]
(let [[source target] (cli/parse-opts args nil)]
(generator/build-all! nil)))
(let [[input output] args]
(cond
(nil? input)
(binding [*out* *err*]
(println "Error: please provide an input argument"))

(nil? output)
(binding [*out* *err*]
(println "Error: please provide an output argument"))

:else
(generator/build-all!
(resource input)
(io/as-file output)))))
46 changes: 24 additions & 22 deletions src/aidbox_sdk/generator.clj
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,6 @@

(defn get-directory-files [path]
(->> path
io/file
file-seq
(remove #(.isDirectory %))))

Expand Down Expand Up @@ -722,29 +721,32 @@
(map (fn [[_url same-url-schemas]]
(apply merge same-url-schemas)))))

(defn retrieve-schemas' [source]
(->>
(fetch-packages source)
(map parse-ndjson-gz)
(flatten)
(remove #(nil? (:package-meta %)))
(map (fn [schema]
(assoc schema :package (get-in schema [:package-meta :name]))))
(merge-duplicates)))

(defn retrieve-search-params [source])

(defn build-all! [source-dir target-dir]
(let [search-parameters-dir (io/file target-dir "search")
all-schemas (retrieve-schemas' source-dir)
(defmulti retrieve-schemas class)

(defmethod retrieve-schemas java.io.File
[source]
(->> (fetch-packages source)
(map parse-ndjson-gz)
(flatten)
(remove #(nil? (:package-meta %)))
(map (fn [schema]
(assoc schema :package (get-in schema [:package-meta :name]))))
(merge-duplicates)))

(defmethod retrieve-schemas java.net.URL
[source] (do "something"))

(defn build-all! [input output]
(let [search-parameters-dir (io/file output "search")
all-schemas (retrieve-schemas input)
;; search-params-schemas (retrieve-search-params source-dir)
search-params-schemas all-schemas
constraints (->> all-schemas
(filter #(and
(constraint? %)
(not (from-extension? %)))))]

(prepare-target-directory! target-dir)
(prepare-target-directory! output)

;; create base namespace (all FHIR datatypes) file
(->> all-schemas
Expand All @@ -753,7 +755,7 @@
(sort-by :base)
(generate-base-namespace)
(save-to-file!
(io/file target-dir "Base.cs")))
(io/file output "Base.cs")))

;; create spezialization files
(doseq [item (->> all-schemas
Expand All @@ -766,7 +768,7 @@
(update schema :base #(str % ", IResource"))))))))]

(save-to-file!
(io/file target-dir (package->directory (:package item)) (str (:name item) ".cs"))
(io/file output (package->directory (:package item)) (str (:name item) ".cs"))
(generate-resource-namespace item)))

;; create resource map file
Expand All @@ -784,7 +786,7 @@
:name (->pascal-case (url->resource-type (:url %)))))
(generate-utils-namespace)
(save-to-file!
(io/file target-dir "ResourceMap.cs")))
(io/file output "ResourceMap.cs")))

;; create search parameters classes
(doseq [item (search-parameters-classes search-params-schemas
Expand All @@ -810,8 +812,8 @@
(assoc schema
:url name'))})))]
(save-to-file!
(io/file target-dir (package->directory (:package schema)) (str (->pascal-case (url->resource-type name)) ".cs"))
(io/file output (package->directory (:package schema)) (str (->pascal-case (url->resource-type name)) ".cs"))
file-content))

(doseq [file dotnettpl/files]
(spit (io/file target-dir (:name file)) (:content file)))))
(spit (io/file output (:name file)) (:content file)))))

0 comments on commit acce0bc

Please sign in to comment.