aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/aedifex.lux
blob: f23ac26da3a7934753d09db187d555257e08747b (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
(.module:
  [lux (#- Name)
   [abstract
    [monad (#+ do)]]
   [control
    [pipe (#+ do>)]
    ["." try (#+ Try)]
    ["." io (#+ IO)]
    [parser
     ["." cli (#+ program:)]
     ["<c>" code]]
    [security
     ["!" capability]]
    [concurrency
     ["." promise (#+ Promise)]]]
   [data
    [binary (#+ Binary)]
    ["." text
     ["%" format (#+ format)]
     ["." encoding]]
    [format
     ["." xml]]
    [collection
     ["." set]]]
   [tool
    [compiler
     [language
      [lux
       ["." syntax]]]]]
   [world
    ["." file (#+ Path)]]]
  ["." / #_
   [action (#+ Action)]
   ["#" profile]
   ["#." project (#+ Project)]
   ["#." parser]
   ["#." pom]
   ["#." cli]
   ["#." local]
   ["#." dependency #_
    ["#" resolution]]
   [command
    ["#." build]
    ["#." test]
    ["#." auto]
    ["#." deploy]]])

(def: (read-file! path)
  (-> Path (IO (Try Binary)))
  (do (try.with io.monad)
    [project-file (!.use (:: file.system file) [path])]
    (!.use (:: project-file content) [])))

(def: (read-code source-code)
  (-> Text (Try Code))
  (let [parse (syntax.parse ""
                            syntax.no-aliases
                            (text.size source-code))
        start (: Source
                 [["" 0 0] 0 source-code])]
    (case (parse start)
      (#.Left [end error])
      (#try.Failure error)
      
      (#.Right [end lux-code])
      (#try.Success lux-code))))

(def: (write-pom!' path profile)
  (-> Path /.Profile (IO (Try Any)))
  (do (try.with io.monad)
    [file (!.use (:: file.system file) [path])
     pom (:: io.monad wrap (/pom.write profile))]
    (|> pom
        (:: xml.codec encode)
        encoding.to-utf8
        (!.use (:: file over-write)))))

(def: (write-pom! profile)
  (-> /.Profile (IO Any))
  (do io.monad
    [outcome (write-pom!' /pom.file profile)]
    (case outcome
      (#try.Success value)
      (wrap (log! "Successfully wrote POM file!"))
      
      (#try.Failure error)
      (wrap (log! (format "Could not write POM file:" text.new-line
                          error))))))

(def: (install! profile)
  (-> /.Profile (Promise Any))
  (do promise.monad
    [outcome (/local.install (file.async file.system) profile)]
    (wrap (case outcome
            (#try.Success _)
            (log! "Successfully installed locally!")
            
            (#try.Failure error)
            (log! (format "Could not install locally:" text.new-line
                          error))))))

(def: (fetch-dependencies! profile)
  (-> /.Profile (Promise Any))
  (do promise.monad
    [outcome (do (try.with promise.monad)
               [cache (/local.all-cached (file.async file.system)
                                         (set.to-list (get@ #/.dependencies profile))
                                         /dependency.empty)
                resolution (promise.future
                            (/dependency.resolve-all (set.to-list (get@ #/.repositories profile))
                                                     (set.to-list (get@ #/.dependencies profile))
                                                     cache))]
               (/local.cache-all (file.async file.system)
                                 resolution))]
    (wrap (case outcome
            (#try.Success _)
            (log! "Successfully resolved dependencies!")
            
            (#try.Failure error)
            (log! (format "Could not resolve dependencies:" text.new-line
                          error))))))

(def: project
  (-> Binary (Try Project))
  (|>> (do> try.monad
            [encoding.from-utf8]
            [..read-code]
            [(list) (<c>.run /parser.project)])))

(program: [{[profile operation] /cli.command}]
  (do {@ io.monad}
    [data (..read-file! /.file)]
    (case (do try.monad
            [data data
             project (..project data)]
            (/project.profile profile project))
      (#try.Success profile)
      (case operation
        #/cli.POM
        (..write-pom! profile)
        
        #/cli.Dependencies
        (exec (..fetch-dependencies! profile)
          (wrap []))

        #/cli.Install
        (exec (..install! profile)
          (wrap []))

        (#/cli.Deploy repository user password)
        (exec (/deploy.do! repository user password profile)
          (wrap []))

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

        (#/cli.Auto auto)
        (exec (case auto
                #/cli.Build (/auto.do! /build.do! profile)
                #/cli.Test (/auto.do! /test.do! profile))
          (wrap [])))
      
      (#try.Failure error)
      (wrap (log! error)))))