(.require [library [lux (.except) [abstract ["[0]" monad (.only do)]] [control ["[0]" try (.only Try)] [concurrency ["[0]" async (.only Async)]]] [data [collection ["[0]" list] ["[0]" set]]] [world [environment (.only Environment)] [shell (.only Exit Shell)] [console (.only Console)] ["[0]" file (.only) ["[0]" watch (.only Watcher)]]]]] ["[0]" // ["/[1]" // [command (.only Command)] ["[1]" profile] ["[1][0]" action] [dependency [resolution (.only Resolution)]]]]) (def (targets fs path) (-> (file.System Async) file.Path (Async (List file.Path))) (let [! async.monad] (|> path (at fs sub_directories) (at ! each (|>> (try.else (list)) (monad.each ! (targets fs)))) (at ! conjoint) (at ! each (|>> list.together (list.partial path)))))) (def .public delay Nat 1,000) (def (pause delay) (-> Nat (Async (Try Any))) (async.after delay {try.#Success []})) (def .public (do! delay watcher command) (All (_ a) (-> Nat (Watcher Async) (-> (Console Async) (Environment Async) (file.System Async) (Shell Async) Resolution (Command [Exit a])) (-> (Console Async) (Environment Async) (file.System Async) (Shell Async) Resolution (Command [Exit Any])))) (function (_ console environment fs shell resolution) (function (_ profile) (with_expansions [ ((command console environment fs shell resolution) profile)] (do [! async.monad] [targets (|> profile (the ///.#sources) set.list (monad.each ! (..targets fs)) (at ! each list.together))] (do [! ///action.monad] [_ (monad.each ! (at watcher start watch.modification) targets) _ ] (loop (again [_ []]) (do ! [_ (..pause delay) events (at watcher poll [])] (when events {.#Item _} (do ! [_ ] (again [])) {.#End} (again []))))))))))