From 2b909032e7a0bd10cd7db52067d2fb701bfa95e5 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Tue, 6 Jul 2021 21:34:21 -0400 Subject: Simplified the API for file-system operations. --- stdlib/source/program/aedifex/command/auto.lux | 45 ++++++++---------- stdlib/source/program/aedifex/command/clean.lux | 56 ++++++++++------------- stdlib/source/program/aedifex/command/deps.lux | 4 +- stdlib/source/program/aedifex/command/install.lux | 13 ++++-- stdlib/source/program/aedifex/command/pom.lux | 33 ++++++------- 5 files changed, 68 insertions(+), 83 deletions(-) (limited to 'stdlib/source/program/aedifex/command') diff --git a/stdlib/source/program/aedifex/command/auto.lux b/stdlib/source/program/aedifex/command/auto.lux index 5f3d95631..398fb26cf 100644 --- a/stdlib/source/program/aedifex/command/auto.lux +++ b/stdlib/source/program/aedifex/command/auto.lux @@ -13,32 +13,26 @@ [world [program (#+ Program)] [shell (#+ Shell)] - ["." console (#+ Console)] - ["." file (#+ Path) + [console (#+ Console)] + ["." file ["." watch (#+ Watcher)]]]] ["." // #_ ["/#" // #_ [command (#+ Command)] ["#" profile] - ["#." action (#+ Action)] + ["#." action] [dependency [resolution (#+ Resolution)]]]]) (def: (targets fs path) - (-> (file.System Promise) Path (Promise (List Path))) - (do {! promise.monad} - [?root (\ fs directory [path])] - (case ?root - (#try.Success root) - (loop [root root] - (do ! - [subs (\ ! map (|>> (try.default (list))) - (\ root directories []))] - (\ ! map (|>> list.concat (list& (\ root scope))) - (monad.map ! recur subs)))) - - (#try.Failure error) - (wrap (list))))) + (-> (file.System Promise) file.Path (Promise (List file.Path))) + (let [! promise.monad] + (|> path + (\ fs sub_directories) + (\ ! map (|>> (try.default (list)) + (monad.map ! (targets fs)))) + (\ ! join) + (\ ! map (|>> list.concat (list& path)))))) (def: #export delay Nat @@ -68,13 +62,12 @@ (loop [_ []] (do ! [_ (..pause delay) - events (\ watcher poll []) - _ (case events - (#.Cons _) - (do ! - [_ ] - (wrap [])) + events (\ watcher poll [])] + (case events + (#.Cons _) + (do ! + [_ ] + (recur [])) - #.Nil - (wrap []))] - (recur []))))))))) + #.Nil + (recur [])))))))))) diff --git a/stdlib/source/program/aedifex/command/clean.lux b/stdlib/source/program/aedifex/command/clean.lux index 142451113..c37c46367 100644 --- a/stdlib/source/program/aedifex/command/clean.lux +++ b/stdlib/source/program/aedifex/command/clean.lux @@ -3,54 +3,46 @@ [abstract ["." monad (#+ do)]] [control - ["." try (#+ Try)] - ["." exception] + [try (#+ Try)] [concurrency ["." promise (#+ Promise)]]] [data [text ["%" format (#+ format)]]] [world - ["." file (#+ Path File Directory)] + ["." file (#+ Path)] ["." console (#+ Console)]]] ["." /// #_ [command (#+ Command)] ["#" profile] ["#." action (#+ Action)]]) -(def: (clean_files! root) - (-> (Directory Promise) (Promise (Try Any))) - (do {! ///action.monad} - [nodes (: (Promise (Try (List (File Promise)))) - (\ root files [])) - _ (monad.map ! (function (_ node) - (\ node delete [])) - nodes)] - (wrap []))) +(def: (clean_files! fs root) + (-> (file.System Promise) Path (Promise (Try Any))) + (let [! ///action.monad] + (|> root + (\ fs directory_files) + (\ ! map (monad.map ! (\ fs delete))) + (\ ! join)))) -(def: #export (success path) +(def: #export success (-> ///.Target Text) - (format "Successfully cleaned target directory: " path)) + (|>> (format "Successfully cleaned target directory: "))) (def: #export (do! console fs profile) (-> (Console Promise) (file.System Promise) (Command Any)) - (do promise.monad + (do {! promise.monad} [#let [target (get@ #///.target profile)] - root (: (Promise (Try (Directory Promise))) - (\ fs directory target))] - (case root - (#try.Success root) - (do {! ///action.monad} - [_ (loop [root root] + ? (\ fs directory? target) + _ (let [! ///action.monad] + (if ? + (loop [root target] (do ! - [_ (..clean_files! root) - subs (: (Promise (Try (List (Directory Promise)))) - (\ root directories [])) - _ (monad.map ! recur subs)] - (\ root discard [])))] - (console.write_line (..success target) console)) - - (#try.Failure error) - (if (exception.match? file.cannot_find_directory error) - (console.write_line (..success target) console) - (\ promise.monad wrap (#try.Failure error)))))) + [_ (..clean_files! fs root) + _ (|> root + (\ fs sub_directories) + (\ ! map (monad.map ! recur)) + (\ ! join))] + (\ fs delete root))) + (\ ! wrap [])))] + (console.write_line (..success target) console))) diff --git a/stdlib/source/program/aedifex/command/deps.lux b/stdlib/source/program/aedifex/command/deps.lux index 36a129bd1..de4817ba8 100644 --- a/stdlib/source/program/aedifex/command/deps.lux +++ b/stdlib/source/program/aedifex/command/deps.lux @@ -39,8 +39,8 @@ (-> (Console Promise) (Repository Promise) (List (Repository Promise)) (Command Resolution)) (do promise.monad [#let [dependencies (set.to_list (get@ #///.dependencies profile))] - [local_successes local_failures cache] (///dependency/resolution.all (list local) dependencies ///dependency/resolution.empty) - [remote_successes remote_failures resolution] (///dependency/resolution.all remotes dependencies cache)] + [local_successes local_failures cache] (///dependency/resolution.all console (list local) dependencies ///dependency/resolution.empty) + [remote_successes remote_failures resolution] (///dependency/resolution.all console remotes dependencies cache)] (do ///action.monad [cached (|> (dictionary.keys cache) (list\fold dictionary.remove resolution) diff --git a/stdlib/source/program/aedifex/command/install.lux b/stdlib/source/program/aedifex/command/install.lux index 4b6b96e3e..64830c4d2 100644 --- a/stdlib/source/program/aedifex/command/install.lux +++ b/stdlib/source/program/aedifex/command/install.lux @@ -21,7 +21,7 @@ ["." xml]]] [world [program (#+ Program)] - ["." file (#+ Path File)] + ["." file] ["." console (#+ Console)]]] [program [compositor @@ -49,13 +49,18 @@ (def: #export failure "Failure: No 'identity' defined for the project.") -(def: #export (do! console system repository profile) +(def: #export (do! console fs repository profile) (-> (Console Promise) (file.System Promise) (Repository Promise) (Command Any)) (case (get@ #/.identity profile) (#.Some identity) (do ///action.monad - [package (export.library system (set.to_list (get@ #/.sources profile))) - pom (\ promise.monad wrap (///pom.write profile)) + [package (|> profile + (get@ #/.sources) + set.to_list + (export.library fs)) + pom (|> profile + ///pom.write + (\ promise.monad wrap)) _ (///dependency/deployment.one repository [identity ///artifact/type.lux_library] (let [pom_data (|> pom diff --git a/stdlib/source/program/aedifex/command/pom.lux b/stdlib/source/program/aedifex/command/pom.lux index b8a728904..00427ee39 100644 --- a/stdlib/source/program/aedifex/command/pom.lux +++ b/stdlib/source/program/aedifex/command/pom.lux @@ -3,38 +3,33 @@ [abstract [monad (#+ do)]] [control - ["." try (#+ Try)] + ["." try ("#\." functor)] [concurrency ["." promise (#+ Promise) ("#\." monad)]]] [data - ["." text + [text ["%" format (#+ format)] [encoding ["." utf8]]] [format ["." xml]]] [world - ["." file (#+ Path File)] + ["." file] ["." console (#+ Console)]]] - ["." // #_ - ["#." clean] - ["/#" // #_ - [command (#+ Command)] - ["#." action (#+ Action)] - ["#." pom]]]) + ["." /// #_ + [command (#+ Command)] + ["#." action] + ["#." pom]]) (def: #export success (format "Successfully created POM file: " ///pom.file)) (def: #export (do! console fs profile) - (-> (Console Promise) (file.System Promise) (Command Path)) + (-> (Console Promise) (file.System Promise) (Command Any)) (do ///action.monad - [pom (promise\wrap (///pom.write profile)) - file (: (Promise (Try (File Promise))) - (file.get_file promise.monad fs ///pom.file)) - outcome (|> pom - (\ xml.codec encode) - (\ utf8.codec encode) - (\ file over_write)) - _ (console.write_line ..success console)] - (wrap ///pom.file))) + [content (|> (///pom.write profile) + (try\map (|>> (\ xml.codec encode) + (\ utf8.codec encode))) + promise\wrap) + _ (\ fs write content ///pom.file)] + (console.write_line ..success console))) -- cgit v1.2.3