(.module: [lux #* [abstract ["." monad (#+ do)]] [control ["." try (#+ Try)] [concurrency ["." promise (#+ Promise)]] [security ["!" capability]]] [data [collection ["." list] ["." set]]] [world [program (#+ Program)] [shell (#+ Shell)] ["." console (#+ Console)] ["." file (#+ Path) ["." watch (#+ Watcher)]]]] ["." // #_ ["/#" // #_ [command (#+ Command)] ["#" profile] ["#." action (#+ Action)] [dependency [resolution (#+ Resolution)]]]]) (def: (targets fs path) (-> (file.System Promise) Path (Promise (List Path))) (do {! promise.monad} [?root (!.use (\ fs directory) [path])] (case ?root (#try.Success root) (loop [root root] (do ! [subs (\ ! map (|>> (try.default (list))) (!.use (\ root directories) []))] (\ ! map (|>> list.concat (list& (!.use (\ root scope) []))) (monad.map ! recur subs)))) (#try.Failure error) (wrap (list))))) (def: #export delay Nat 1,000) (def: (pause delay) (-> Nat (Promise (Try Any))) (promise.delay delay (#try.Success []))) (def: #export (do! delay watcher command) (All [a] (-> Nat (Watcher Promise) (-> (Console Promise) (Program Promise) (file.System Promise) (Shell Promise) Resolution (Command a)) (-> (Console Promise) (Program Promise) (file.System Promise) (Shell Promise) Resolution (Command Any)))) (function (_ console program fs shell resolution) (function (_ profile) (with_expansions [ ((command console program fs shell resolution) profile)] (do {! promise.monad} [targets (|> profile (get@ #///.sources) set.to_list (monad.map ! (..targets fs)) (\ ! map list.concat))] (do {! ///action.monad} [_ (monad.map ! (\ watcher start watch.all) targets) _ ] (loop [_ []] (do ! [_ (..pause delay) events (\ watcher poll []) _ (case events (#.Cons _) (do ! [_ ] (wrap [])) #.Nil (wrap []))] (recur [])))))))))