-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate-repo-cache.nu
executable file
·88 lines (76 loc) · 2 KB
/
generate-repo-cache.nu
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
#!/usr/bin/env nu
let REQUIRED_ATTRIBUTES = ["author" "name" "os" "short-desc" "raw-url" "url" "version"]
let DEFAULT_ATTRIBUTES = {"pre-install-msg": "",
"post-install-msg": "",
"keywords": [],
"nu-dependencies": [],
"installer": "",
"os": ["android" "macos" "linux" "windows"]
}
# returns record containing script metadata
def get-metadata [
json: path
] {
open $json
|sort
}
def check-required-attributes [
metadata: record
] {
let missing_columns = ($REQUIRED_ATTRIBUTES|where $it not-in ($metadata|columns)|str collect ", ")
if (not ($missing_columns|is-empty)) {
error make --unspanned {
msg: $"Required columns: ($missing_columns) not present in metadata"
}
}
$REQUIRED_ATTRIBUTES
|each { |attribute|
$metadata
|each { |entry|
if ($entry|get $attribute|is-empty) {
error make --unspanned {msg: $"($entry) lacks required attribute: ($attribute)"}
}
}
}
echo $metadata
}
def add-optional-attributes [
metadata: record
] {
let attr = (
$DEFAULT_ATTRIBUTES
|merge {$metadata}
)
if "long-desc" not-in ($attr|columns) {
$attr
|insert "long-desc" $attr.short-desc
} else {
$attr
}
}
def get-metadata-jsons [] {
ls packages
|where type == dir
|get name
|path basename
|each {|dir|
["packages" $dir "metadata.json"]
|path join
}
}
get-metadata-jsons
|each {|json|
let metadata = (check-required-attributes (add-optional-attributes (get-metadata $json)))
# otherwise the developer has to manually insert a checksum for their installer
if ($metadata.installer|is-empty) {
$metadata
|upsert checksum {open --raw ($json | str replace "metadata.json" (($metadata.name | into string) + ".nu")) | hash sha256}
|sort
|save $json
}
$metadata
|sort
|upsert checksum {open --raw $json | hash sha256}
}
|sort
|save repo-cache.json