diff options
author | Eduardo Julian | 2020-05-28 22:13:39 -0400 |
---|---|---|
committer | Eduardo Julian | 2020-05-28 22:13:39 -0400 |
commit | fcb1dcee2a4d502b41852a4c8e26b53ae7b2041e (patch) | |
tree | 704aa1808b8c27208a942f2af4cbd9adbc5f324a /stdlib/source/program/compositor/export.lux | |
parent | 2139e72d8e7c58cb355799d4a8412a0c38fb481c (diff) |
Can now export Lux code as library TAR files.
Diffstat (limited to '')
-rw-r--r-- | stdlib/source/program/compositor/export.lux | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/stdlib/source/program/compositor/export.lux b/stdlib/source/program/compositor/export.lux new file mode 100644 index 000000000..6e364800f --- /dev/null +++ b/stdlib/source/program/compositor/export.lux @@ -0,0 +1,60 @@ +(.module: + [lux #* + [abstract + ["." monad (#+ do)]] + [control + ["." try (#+ Try)] + [concurrency + ["." promise (#+ Promise) ("#@." monad)]] + [security + ["!" capability]]] + [data + [text + ["%" format (#+ format)]] + [collection + ["." dictionary] + ["." row]] + [format + ["." binary] + ["." tar]]] + [time + ["." instant]] + [tool + [compiler + [meta + ["." io #_ + ["#" context (#+ Extension)]]]]] + [world + ["." file]]] + [// + [cli (#+ Export)]]) + +(def: no-ownership + tar.Ownership + (let [commons (: tar.Owner + {#tar.name tar.anonymous + #tar.id tar.no-id})] + {#tar.user commons + #tar.group commons})) + +(def: #export (export system extension [sources target]) + (-> (file.System Promise) Extension Export (Promise (Try Any))) + (let [package (format target (:: system separator) "library.tar")] + (do (try.with promise.monad) + [package (: (Promise (Try (file.File Promise))) + (file.get-file promise.monad system package)) + files (io.enumerate system extension sources) + tar (|> (dictionary.entries files) + (monad.map try.monad + (function (_ [path source-code]) + (do try.monad + [path (tar.path path) + source-code (tar.content source-code)] + (wrap (#tar.Normal [path + (instant.from-millis +0) + tar.none + ..no-ownership + source-code]))))) + (:: try.monad map (|>> row.from-list (binary.run tar.writer))) + promise@wrap)] + (!.use (:: package over-write) tar)))) |