diff options
author | Eduardo Julian | 2017-12-05 22:55:11 -0400 |
---|---|---|
committer | Eduardo Julian | 2017-12-05 22:55:11 -0400 |
commit | 2e86fefe6f15877e8c46a45411a9cbd04b26e2e3 (patch) | |
tree | c95f8c1391b907a3e9076f4eadb831aa274cfbea /new-luxc/source/luxc/io.jvm.lux | |
parent | 0b87f118978e9971828d2c9ccabe685b0c5e4c35 (diff) |
- WIP: Caching.
Diffstat (limited to 'new-luxc/source/luxc/io.jvm.lux')
-rw-r--r-- | new-luxc/source/luxc/io.jvm.lux | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/new-luxc/source/luxc/io.jvm.lux b/new-luxc/source/luxc/io.jvm.lux index ef4a7fc8a..c932472f3 100644 --- a/new-luxc/source/luxc/io.jvm.lux +++ b/new-luxc/source/luxc/io.jvm.lux @@ -19,6 +19,7 @@ (exception: #export File-Not-Found) (exception: #export Module-Not-Found) +(exception: #export Cannot-Prepare-Module) (def: sanitize (-> Text Text) @@ -49,7 +50,11 @@ (#e.Error error) right))) -(def: #export (read-module dirs name) +(def: #export blob-to-text + (-> Blob Text) + (|>> [] String::new)) + +(def: #export (read dirs name) (-> (List File) Text (Process [File Text])) (do io.Monad<Process> [[path file] (: (Process [Text File]) @@ -58,9 +63,9 @@ (find-source dirs (format name lux-extension)) (io.fail (Module-Not-Found name)))) blob (file.read file)] - (wrap [path (String::new blob)]))) + (wrap [path (blob-to-text blob)]))) -(def: (platform-target root-target) +(def: #export (platform-target root-target) (-> File File) (format root-target "/" (for {"JVM" "jvm" "JS" "js"}))) @@ -72,11 +77,16 @@ (file.make-dir (sanitize (platform-target target-dir))))) (def: #export (prepare-module target-dir module-name) - (-> File Text (Process Bool)) - (|> module-name - (format (platform-target target-dir) "/") - sanitize - file.make-dir)) + (-> File Text (Process Unit)) + (do io.Monad<Process> + [made-dir? (|> module-name + (format (platform-target target-dir) "/") + sanitize + file.make-dir)] + (if made-dir? + (wrap []) + (io.fail (Cannot-Prepare-Module (format "Module: " module-name "\n" + "Target: " target-dir "\n")))))) (def: #export (write target name content) (-> File Text Blob (Process Unit)) @@ -84,3 +94,19 @@ (format (platform-target target) "/") sanitize (file.write content))) + +(def: #export (module target-dir module-dir) + (-> File File (Maybe Text)) + (case (text.split-with target-dir module-dir) + (#.Some ["" post]) + (let [raw (text.replace-all file.separator "/" post)] + (if (text.starts-with? "/" raw) + (text.clip' +1 raw) + (#.Some raw))) + + _ + #.None)) + +(def: #export (file target-dir file-name) + (-> File Text File) + (format target-dir file.separator (sanitize file-name))) |