(.module: [lux (#- Name) [abstract [monad (#+ do)]] [control ["." try (#+ Try)] ["." exception (#+ exception:)] ["." io (#+ IO)] [concurrency ["." promise (#+ Promise) ("#\." monad)]] [security ["!" capability]]] [data ["." product] ["." maybe] ["." text ("#\." equivalence) ["%" format (#+ format)]] [collection ["." list ("#\." functor)] ["." dictionary] ["." set]] [number ["i" int]]] [world [program (#+ Program)] ["." file (#+ Path)] ["." shell (#+ Shell)] ["." console (#+ Console)]]] ["." /// #_ ["#" profile] ["#." action] ["#." command (#+ Command)] ["#." local] ["#." cache] ["#." repository] ["#." runtime] ["#." dependency (#+ Dependency) ["#/." resolution (#+ Resolution)]] ["#." artifact (#+ Group Name Artifact) ["#/." type]]]) (type: Finder (-> Resolution (Maybe Dependency))) (def: (dependency-finder group name) (-> Group Name Finder) (|>> dictionary.entries (list.one (function (_ [dependency package]) (if (and (text\= group (get@ [#///dependency.artifact #///artifact.group] dependency)) (text\= name (get@ [#///dependency.artifact #///artifact.name] dependency))) (#.Some dependency) #.None))))) (def: #export lux-group Group "com.github.luxlang") (def: #export jvm-compiler-name Name "lux-jvm") (def: #export js-compiler-name Name "lux-js") (template [ ] [(def: Finder (..dependency-finder ..lux-group ))] [jvm-compiler ..jvm-compiler-name] [js-compiler ..js-compiler-name] ) (exception: #export no-available-compiler) (exception: #export no-specified-program) (exception: #export no-specified-target) (type: #export Compiler (#JVM Artifact) (#JS Artifact)) (def: (remove-dependency dependency) (-> Dependency (-> Resolution Resolution)) (|>> dictionary.entries (list.filter (|>> product.left (is? dependency) not)) (dictionary.from-list ///dependency.hash))) (def: (compiler resolution) (-> Resolution (Try [Resolution Compiler])) (case [(..jvm-compiler resolution) (..js-compiler resolution)] [(#.Some dependency) _] (#try.Success [(..remove-dependency dependency resolution) (#JVM (get@ #///dependency.artifact dependency))]) [_ (#.Some dependency)] (#try.Success [(..remove-dependency dependency resolution) (#JS (get@ #///dependency.artifact dependency))]) _ (exception.throw ..no-available-compiler []))) (def: (libraries fs) (All [!] (-> (file.System !) Resolution (List Path))) (|>> dictionary.keys (list.filter (|>> (get@ #///dependency.type) (text\= ///artifact/type.lux-library))) (list\map (|>> (get@ #///dependency.artifact) (///local.path fs))))) (def: (singular name) (-> Text Text (List Text)) (|>> (list name))) (def: (plural name) (-> Text (List Text) (List Text)) (|>> (list\map (|>> (list name))) list.concat)) (def: #export start "[BUILD STARTED]") (def: #export success "[BUILD ENDED]") (def: #export failure "[BUILD FAILED]") (def: #export (do! console program fs shell resolution profile) (-> (Console Promise) (Program Promise) (file.System Promise) (Shell Promise) Resolution (Command [Compiler Path])) (case [(get@ #///.program profile) (get@ #///.target profile)] [#.None _] (promise\wrap (exception.throw ..no-specified-program [])) [_ #.None] (promise\wrap (exception.throw ..no-specified-target [])) [(#.Some program-module) (#.Some target)] (do promise.monad [environment (\ program environment []) working-directory (\ program directory [])] (do ///action.monad [[resolution compiler] (promise\wrap (..compiler resolution)) #let [[command output] (let [[compiler output] (case compiler (#JVM artifact) [(///runtime.java (///local.path fs artifact)) "program.jar"] (#JS artifact) [(///runtime.node (///local.path fs artifact)) "program.js"])] [(format compiler " build") output]) / (\ fs separator) cache-directory (format working-directory / target)] _ (console.write-line ..start console) process (!.use (\ shell execute) [environment working-directory command (list.concat (list (..plural "--library" (..libraries fs resolution)) (..plural "--source" (set.to-list (get@ #///.sources profile))) (..singular "--target" cache-directory) (..singular "--module" program-module)))]) exit (!.use (\ process await) []) _ (console.write-line (if (i.= shell.normal exit) ..success ..failure) console)] (wrap [compiler (format cache-directory / output)])))))