aboutsummaryrefslogtreecommitdiff
path: root/meta.jq
blob: 8f7d7886d9af7e527153c6e459e30383257bce70 (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
def apply_optional: if has("rules") then
    {
        "rules": [.rules[] | {
            "action": .action,
            "match": del(.action)
        }],
        "value": del(.rules)
    } as $optional
    | if $optional.rules[].match | inside($info[0]) then
        $optional.value
    else
        empty
    end
end;

def replace_placeholders: {
    "version_name": .id,
    "version_type": .type,

    "assets_index_name": .assets,

    "classpath": (. as $root | [
        .libraries[] | apply_optional | "${libraries_directory}/" + .downloads.artifact.path
    ] + ["${versions_directory}/\($root.id)/client.jar"] | join(":")),
    "clientid": "idfk",

    # log4j config path
    "path": "${versions_directory}/\(.id)/log4j.xml"
} as $strings | walk(if type == "string" then
    gsub("\\${(?<key>.*)}"; "\($strings[.key] // "${\(.key)}")")
end);

replace_placeholders | {
    "args": .arguments | to_entries | [.[] | {
        "key": .key,
        "value": .value | [
            .[] | if type == "object" then
                apply_optional | .value
            end
        ] | flatten
    }] | from_entries, # as $args | $args + {"jvm": [.logging.client.argument] + $args.jvm}),
    "libraries": [.libraries[] | apply_optional | {
        "name": .name,
        "path": .downloads.artifact.path,
        "url": .downloads.artifact.url
    }],
    "version": .id,
    "asset_index": .assetIndex.url,
    "java_version": .javaVersion.majorVersion,
    "client_url": .downloads.client.url,
    "main_class": .mainClass,
    "logging_config": .logging.client.file.url
}