fix: crates-io-simple indexer

This commit is contained in:
DavHau 2022-08-31 12:10:05 +02:00
parent bc454bfe9d
commit 3caf3a8a67
3 changed files with 20 additions and 3 deletions

View File

@ -13,6 +13,10 @@
number = 5;
};
crates-io = {};
crates-io-simple = {
sortBy = "name";
maxPages = 1;
};
};
packageOverrides = {
"^.*$".disable-build = {

View File

@ -4,10 +4,11 @@
coreutils,
curl,
jq,
python3,
...
}:
utils.writePureShellScript
[coreutils curl jq]
[coreutils curl jq python3]
''
input=''${1:?"please provide an input as a JSON file"}
@ -19,9 +20,8 @@
maxPages=$(jq '.maxPages' -c -r $input)
for currentPage in $(seq 1 $maxPages); do
jqQuery="$(jq '.' -c -r "$tmpFile") + (.crates | map(\"crates-io:\" + .name + \"\/\" + .max_stable_version))"
url="https://crates.io/api/v1/crates?page=$currentPage&per_page=100&sort=$sortBy"
curl -k "$url" | jq "$jqQuery" -r > "$tmpFile"
curl -k "$url" | python3 ${./process-result.py} > "$tmpFile"
done
mv "$tmpFile" "$(realpath $outFile)"

View File

@ -0,0 +1,13 @@
import json
import sys
input = json.load(sys.stdin)
projects = []
for package in input['crates']:
projects.append(dict(
id=f"{package['name']}-{package['max_stable_version']}",
name=package['name'],
version=package['max_stable_version'],
translator='crates-io',
))
print(json.dumps(projects, indent=2))