(.module: [lux (#- Source) [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 (#+ Source Export)]]) (def: file "library.tar") (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 (library system sources) (-> (file.System Promise) (List Source) (Promise (Try tar.Tar))) (do (try.with promise.monad) [files (io.enumerate system sources)] (|> (dictionary.entries files) (monad.map try.monad (function (_ [path source-code]) (do try.monad [path (|> path (text.replace-all (:: system separator) .module-separator) tar.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) (:: promise.monad wrap)))) (def: #export (export system [sources target]) (-> (file.System Promise) Export (Promise (Try Any))) (do (try.with promise.monad) [tar (..library system sources) package (: (Promise (Try (file.File Promise))) (file.get-file promise.monad system (format target (:: system separator) ..file)))] (|> tar (binary.run tar.writer) (!.use (:: package over-write)))))