aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/aedifex/artifact.lux
blob: 631de6ebe9b7c7e31782d1c70f804b0f727155b1 (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
(.module:
  [library
   [lux (#- Name)
    [abstract
     [equivalence (#+ Equivalence)]
     [order (#+ Order)]
     [hash (#+ Hash)]]
    [data
     ["." product]
     ["." text ("#\." order)
      ["%" format (#+ Format)]]
     [collection
      ["." list ("#\." monoid)]]]
    [world
     ["." file (#+ Path)]
     [net
      ["." uri (#+ URI)]]]]])

(type: #export Group
  Text)

(type: #export Name
  Text)

(type: #export Version
  Text)

(type: #export Artifact
  {#group Group
   #name Name
   #version Version})

(def: #export hash
  (Hash Artifact)
  ($_ product.hash
      text.hash
      text.hash
      text.hash
      ))

(def: #export equivalence
  (Equivalence Artifact)
  (\ ..hash &equivalence))

(implementation: #export order
  (Order Artifact)

  (def: &equivalence
    ..equivalence)

  (def: (< reference subject)
    (<| (or (text\< (get@ #group reference)
                    (get@ #group subject)))

        (and (text\= (get@ #group reference)
                     (get@ #group subject)))
        (or (text\< (get@ #name reference)
                    (get@ #name subject)))
        
        (and (text\= (get@ #name reference)
                     (get@ #name subject)))
        (text\< (get@ #version reference)
                (get@ #version subject)))))

(template [<separator> <definition>]
  [(def: <definition>
     Text
     <separator>)]

  ["." group_separator]
  ["-" version_separator]
  [":" identity_separator]
  )

(def: #export (identity artifact)
  (-> Artifact Text)
  (%.format (get@ #name artifact)
            ..version_separator
            (get@ #version artifact)))

(def: #export (format value)
  (Format Artifact)
  (%.format (get@ #group value)
            ..identity_separator
            (..identity value)))

(def: #export (directory separator group)
  (-> Text Group Text)
  (|> group
      (text.split_all_with ..group_separator)
      (text.join_with separator)))

(def: #export (uri version artifact)
  (-> Version Artifact URI)
  (let [/ uri.separator
        group (..directory / (get@ #group artifact))
        name (get@ #name artifact)
        ## version (get@ #version artifact)
        identity (..identity artifact)]
    (%.format group / name / version / identity)))

(def: #export (local artifact)
  (-> Artifact (List Text))
  (list\compose (|> artifact
                    (get@ #group)
                    (text.split_all_with ..group_separator))
                (list (get@ #name artifact)
                      (get@ #version artifact))))