aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/aedifex.lux
blob: b046a7ace11d466bc906ac94629cce3f411a3d4b (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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
(.module:
  [library
   [lux (#- Name)
    [program (#+ program:)]
    ["." debug]
    [abstract
     [monad (#+ do)]]
    [control
     [pipe (#+ do>)]
     ["." io (#+ IO)]
     ["." try (#+ Try) ("#\." functor)]
     ["." exception (#+ exception:)]
     [parser
      [environment (#+ Environment)]]
     [concurrency
      ["." promise (#+ Promise) ("#\." monad)]]]
    [data
     [binary (#+ Binary)]
     ["." text
      ["%" format (#+ format)]
      [encoding
       ["." utf8]]]
     [format
      ["." xml]]
     [collection
      ["." set]
      ["." dictionary (#+ Dictionary)]
      ["." list ("#\." functor)]]]
    [tool
     [compiler
      [language
       [lux
        ["." syntax]]]]]
    [world
     ["." shell (#+ Exit Shell)]
     ["." console (#+ Console)]
     ["." program (#+ Program)]
     ["." file (#+ Path)
      ["." watch]]
     [net
      ["." http #_
       ["#" client]]]]]]
  ["." / #_
   ["#" profile]
   ["#." action (#+ Action)]
   ["#." project (#+ Project)]
   ["#." input]
   ["#." parser]
   ["#." pom]
   ["#." cli]
   ["#." dependency #_
    ["#" resolution (#+ Resolution)]]
   ["#." repository (#+ Repository)
    ["#/." remote (#+ Address)]
    ["#/." local]]
   ["#." 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 http.default #.None) /repository.async))))

(def: (with_dependencies program console command profile)
  (All [a]
    (-> (Program Promise) (Console Promise)
        (-> (Console Promise) (Program Promise) (file.System Promise) (Shell Promise) Resolution (Command [Exit a]))
        (Command a)))
  (do /action.monad
    [resolution (/command/deps.do! console
                                   (/repository/local.repository program (file.async file.default))
                                   (..repositories profile)
                                   (|>> (/repository/remote.repository http.default #.None)
                                        /repository.async)
                                   profile)
     [exit_code output] ((command console program (file.async file.default) (shell.async shell.default) resolution) profile)
     _ (case exit_code
         (^ (static shell.normal))
         (wrap [])

         _
         (do promise.monad
           [_ (\ program exit exit_code)]
           (wrap (#try.Failure ""))))]
    (wrap output)))

(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))]))

(def: succeed!
  (IO Any)
  (\ program.default exit shell.normal))

(def: (fail! error)
  (-> Text (IO Any))
  (exec
    (debug.log! error)
    (\ program.default exit shell.error)))

(def: (command action)
  (All [a] (-> (Promise (Try a)) (IO Any)))
  (exec (do promise.monad
          [outcome action]
          (promise.future
           (case outcome
             (#try.Success _)
             ..succeed!

             (#try.Failure error)
             (..fail! error))))
    (\ io.monad wrap [])))

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

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

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

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

                #/cli.POM
                (..command
                 (/command/pom.do! console (file.async file.default) profile))
                
                #/cli.Install
                (..command
                 (let [fs (file.async file.default)]
                   (/command/install.do! console fs (/repository/local.repository program fs) profile)))

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

                   [#.None _]
                   (promise\wrap (exception.throw /.no_identity []))

                   [_ #.None]
                   (promise\wrap (exception.throw ..cannot_find_repository [repository (get@ #/.deploy_repositories profile)]))))
                
                #/cli.Dependencies
                (..command
                 (/command/deps.do! console
                                    (/repository/local.repository program (file.async file.default))
                                    (..repositories profile)
                                    (|>> (/repository/remote.repository http.default #.None)
                                         /repository.async)
                                    profile))

                (#/cli.Compilation compilation)
                (case compilation
                  #/cli.Build (..command
                               (..with_dependencies program console /command/build.do! profile))
                  #/cli.Test (..command
                              (..with_dependencies program console /command/test.do! profile)))

                (#/cli.Auto auto)
                (do !
                  [?watcher watch.default]
                  (case ?watcher
                    (#try.Failure error)
                    (..fail! error)
                    
                    (#try.Success watcher)
                    (..command
                     (case auto
                       #/cli.Build (..with_dependencies program console (/command/auto.do! /command/auto.delay watcher /command/build.do!) profile)
                       #/cli.Test (..with_dependencies program console (/command/auto.do! /command/auto.delay watcher /command/test.do!) profile)))))

                _
                (undefined)))
            ))))))