Add jsonpath support for checkver and hash extraction

Unravel if-blocks in checkver

Use new jsonpath for openssl, nuget, dart and bfg
This commit is contained in:
Richard Kuhnt
2017-03-03 21:15:37 +01:00
parent 314a27e598
commit 825f19aa52
8 changed files with 192 additions and 95 deletions

View File

@@ -86,3 +86,30 @@ Function ConvertToPrettyJson {
$output
}
}
function json_path([Object] $json, [String] $jsonpath, [String] $basename) {
$result = $json
$isJsonPath = $jsonpath.StartsWith("`$")
$jsonpath.split(".") | ForEach-Object {
$el = $_
# substitute the base filename into the jsonpath
if($el.StartsWith("`$basename")) {
$el = $el.Replace("`$basename", $basename)
}
# skip $ if it's jsonpath format
if($el -eq "`$" -and $isJsonPath) {
return
}
if($el -match "^(?<property>\w+)\[(?<index>\d+)\]$") {
$property = $matches['property']
$result = $result.$property[$matches['index']]
return
}
$result = $result.$el
}
return $result
}