|
| 1 | +#!/bin/fish |
| 2 | + |
| 3 | +set --local jobs 12 |
| 4 | + |
| 5 | +# source files |
| 6 | +set --local input ~/git/atoz/json |
| 7 | + |
| 8 | +# output directory for nim |
| 9 | +set --local output ~/git/atoz/src/atoz |
| 10 | + |
| 11 | +# temp file to hold our parallel jobs |
| 12 | +set --local pfile (mktemp) |
| 13 | + |
| 14 | +# make sure our output dir works |
| 15 | +mkdir --parents "$output" |
| 16 | + |
| 17 | +# the list of input files |
| 18 | +set --local inputs (find $input -name \*.json -print) |
| 19 | + |
| 20 | +set --local sfile (mktemp) |
| 21 | + |
| 22 | +for n in $inputs |
| 23 | + # full-path |
| 24 | + set --local fp (realpath "$n") |
| 25 | + # serial number (a date) |
| 26 | + set --local ser (basename $n) |
| 27 | + # directory named after the api |
| 28 | + set --local api (basename (dirname "$n")) |
| 29 | + set --local target (basename (dirname "$n")) |
| 30 | + set --local target (string replace "-" "_" "$target") |
| 31 | + set --local target (string replace "." "_" "$target") |
| 32 | + # just the date cleaned up, eg. 20200202 |
| 33 | + set --local justser (echo "$ser" | cut -f 1 -d\.) |
| 34 | + # output nim file |
| 35 | + set --local target (string join "_" "$output/$target" "$justser.nim") |
| 36 | + |
| 37 | + set --local intime (stat --format="%Y" "$fp") |
| 38 | + set --local outtime 0 |
| 39 | + if test -f "$target" |
| 40 | + set outtime (stat --format="%Y" "$target") |
| 41 | + end |
| 42 | + echo "$api" >> $sfile |
| 43 | + if test $intime -gt $outtime |
| 44 | + if test $jobs -ne 1 |
| 45 | + echo "./build.nims atoz.nim '$fp' '$output/$ser' '$api' '$ser'" >> $pfile |
| 46 | + else |
| 47 | + if ! ./build.nims atoz.nim $fp $output/$ser $api $ser |
| 48 | + break |
| 49 | + end |
| 50 | + end |
| 51 | + end |
| 52 | +end |
| 53 | + |
| 54 | +if test $jobs -ne 1 |
| 55 | + parallel -j $jobs < $pfile |
| 56 | +end |
| 57 | + |
| 58 | +set --local uniques (sort < $sfile | uniq | wc -l | xargs echo) |
| 59 | +echo $uniques services |
| 60 | + |
| 61 | +if test -f $pfile; rm $pfile; end |
| 62 | +if test -f $sfile; rm $sfile; end |
0 commit comments