aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/aedifex.lux
blob: d804fd552435898a90558759d47fa0dbe42ef34d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
(.module:
  [lux (#- Name)
   [abstract
    [monad (#+ do)]]
   [control
    [pipe (#+ do>)]
    ["." io (#+ IO)]
    ["." try (#+ Try) ("#\." functor)]
    ["." exception (#+ exception:)]
    [parser
     ["." cli (#+ program:)]
     ["<c>" code]]
    [security
     ["!" capability]]
    [concurrency
     ["." promise (#+ Promise) ("#\." monad)]]]
   [data
    [binary (#+ Binary)]
    ["." text
     ["%" format (#+ format)]
     ["." encoding]]
    [format
     ["." xml]]
    [collection
     ["." set]
     ["." dictionary (#+ Dictionary)]
     ["." list ("#\." functor)]]]
   [tool
    [compiler
     [language
      [lux
       ["." syntax]]]]]
   [world
    ["." environment (#+ Environment)]
    ["." shell (#+ Shell)]
    ["." console (#+ Console)]
    ["." file (#+ Path)
     ["." watch]]]]
  ["." / #_
   ["#" profile]
   ["#." action (#+ Action)]
   ["#." project (#+ Project)]
   ["#." input]
   ["#." parser]
   ["#." pom]
   ["#." cli]
   ["#." cache]
   ["#." repository (#+ Address Repository)]
   ["#." dependency #_
    ["#" resolution (#+ Resolution)]]
   ["#." command (#+ Command)
    ["#/." version]
    ["#/." clean]
    ["#/." pom]
    ["#/." install]
    ["#/." deps]
    ["#/." build]
    ["#/." test]
    ["#/." auto]
    ["#/." deploy]]])

(def: repositories
  (-> /.Profile (List (Repository Promise)))
  (|>> (get@ #/.repositories)
       set.to-list
       (list\map (|>> /repository.remote /repository.async))))

(def: (with-dependencies console command profile)
  (All [a]
    (-> (Console Promise)
        (-> (Console Promise) Environment (file.System Promise) (Shell Promise) Resolution (Command a))
        (Command a)))
  (do promise.monad
    [environment (promise.future environment.read)]
    (do /action.monad
      [resolution (/command/deps.do! console (file.async file.default) (..repositories profile) profile)]
      ((command console environment (file.async file.default) (shell.async shell.default) resolution) profile))))

(exception: (cannot-find-repository {repository Text}
                                    {options (Dictionary Text Address)})
  (exception.report
   ["Repository" (%.text repository)]
   ["Options" (exception.enumerate (function (_ [name repo])
                                     (format (%.text name) " := " (%.text repo)))
                                   (dictionary.entries options))]))

(program: [{[profile operation] /cli.command}]
  (do {! io.monad}
    [?console console.default]
    (case (try\map console.async ?console)
      (#try.Failure error)
      (wrap (log! error))

      (#try.Success console)
      (case operation
        #/cli.Version
        (exec (/command/version.do! console (\ /.monoid identity))
          (wrap []))

        _
        (do !
          [?profile (/input.read io.monad file.default profile)]
          (case ?profile
            (#try.Failure error)
            (wrap (log! error))

            (#try.Success profile)
            (case operation
              #/cli.Version
              (wrap [])
              
              #/cli.Clean
              (exec (/command/clean.do! console (file.async file.default) profile)
                (wrap []))

              #/cli.POM
              (exec (/command/pom.do! console (file.async file.default) profile)
                (wrap []))
              
              #/cli.Install
              (exec (/command/install.do! console (file.async file.default) profile)
                (wrap []))

              (#/cli.Deploy repository identity)
              (exec (case [(get@ #/.identity profile)
                           (dictionary.get repository (get@ #/.deploy-repositories profile))]
                      [(#.Some artifact) (#.Some repository)]
                      (/command/deploy.do! console
                                           (/repository.async (/repository.remote repository))
                                           (file.async file.default)
                                           identity
                                           artifact
                                           profile)

                      [#.None _]
                      (promise\wrap (exception.throw /.no-identity []))

                      [_ #.None]
                      (promise\wrap (exception.throw ..cannot-find-repository [repository (get@ #/.deploy-repositories profile)])))
                (wrap []))
              
              #/cli.Dependencies
              (exec (/command/deps.do! console (file.async file.default) (..repositories profile) profile)
                (wrap []))

              (#/cli.Compilation compilation)
              (case compilation
                #/cli.Build (exec (..with-dependencies console /command/build.do! profile)
                              (wrap []))
                #/cli.Test (exec (..with-dependencies console /command/test.do! profile)
                             (wrap [])))

              (#/cli.Auto auto)
              (do !
                [?watcher watch.default]
                (case ?watcher
                  (#try.Failure error)
                  (wrap (log! error))
                  
                  (#try.Success watcher)
                  (exec (case auto
                          #/cli.Build (..with-dependencies console (/command/auto.do! watcher /command/build.do!) profile)
                          #/cli.Test (..with-dependencies console (/command/auto.do! watcher /command/test.do!) profile))
                    (wrap [])))))
            ))))))