From fcb1dcee2a4d502b41852a4c8e26b53ae7b2041e Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Thu, 28 May 2020 22:13:39 -0400 Subject: Can now export Lux code as library TAR files. --- stdlib/source/program/compositor/export.lux | 60 +++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 stdlib/source/program/compositor/export.lux (limited to 'stdlib/source/program/compositor/export.lux') 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)))) -- cgit v1.2.3