go-nostr/nip90/justfile

100 lines
2.5 KiB
Makefile

generate: dvm_repo
#!/usr/bin/env fish
echo 'package nip90
type Job struct {
InputKind int
OutputKind int
Name string
Description string
InputType string
Params []string
}
' > kinds.go
for kindf in (ls data-vending-machines/kinds)
echo "> $kindf"
set file "data-vending-machines/kinds/$kindf"
set kind (echo $kindf | rg -o '\d+')
set okind (echo $kind | jq -r '. + 1000')
set title (rg --replace '$1' '^title: *(.*)$' $file | string trim)
set desc (rg --replace '$1' '^description: *(.*)$' $file | string trim)
set inputtype (rg --replace '$1' '(\[ *"i".*\])[^]]*$' $file | jq -nr 'input // [0, 0, ""] | .[2]')
set params (fq '
def drill_to_code:
if (type == "object" and .children) then
.children
| map(drill_to_code)
else
select
( (type == "object") and (.type == "code")
)
| .literal
end
;
.children
| . as $sections
|
( $sections
| map(.type == "heading" and .children == ["Params"])
| index(true)
) as $startParams
| if $startParams == null
then []
else
( $sections[($startParams + 1):]
| map(.type == "heading" and .level == ($sections[$startParams].level))
| index(true)
| . + $startParams + 1
) as $endParams
| ( $sections[($startParams + 1):$endParams]
| map
( .children
| select(.)
| map(drill_to_code)
)
| flatten
| select(. | length > 1)
| unique
)
end
| .[]
' -d markdown -r $file
)
echo "var Job$kind = Job{
InputKind: $kind,
OutputKind: $okind,
Name: \"$title\",
Description: \"$desc\",
InputType: \"$inputtype\",
Params: []string{" >> kinds.go
for param in $params
echo "\"$param\"", >> kinds.go
end
echo "},
}
" >> kinds.go
end
echo "var Jobs = []Job{" >> kinds.go
for kindf in (ls data-vending-machines/kinds)
set kind (echo $kindf | rg -o '\d+')
echo "Job$kind," >> kinds.go
end
echo "}" >> kinds.go
go fmt kinds.go
dvm_repo:
#!/usr/bin/env fish
if [ ! -d data-vending-machines ]
git clone https://github.com/nostr-protocol/data-vending-machines.git
end
cd data-vending-machines
git reset --hard HEAD
git pull