diff --git a/cmd/chromedp-gen/build.sh b/cmd/chromedp-gen/build.sh index fc7179b..398c1f6 100755 --- a/cmd/chromedp-gen/build.sh +++ b/cmd/chromedp-gen/build.sh @@ -1,30 +1,8 @@ #!/bin/bash -UPDATE=0 -LASTUPDATE=0 -if [ -f .last ]; then - LASTUPDATE=$(cat .last) -fi - -NOW=$(date +%s) -if (( "$NOW" >= $(($LASTUPDATE + 86400*5)) )); then - UPDATE=1 -fi - -if [[ "$UPDATE" == 1 ]]; then - go get -u \ - golang.org/x/tools/cmd/goimports \ - github.com/mailru/easyjson/easyjson \ - github.com/valyala/quicktemplate/qtc - - date +%s > .last -fi - set -ve go generate -gofmt -w -s templates/*.go - go build time ./chromedp-gen $@ diff --git a/cmd/chromedp-gen/domain-gen.go b/cmd/chromedp-gen/domain-gen.go index b1ac29f..5b9db65 100644 --- a/cmd/chromedp-gen/domain-gen.go +++ b/cmd/chromedp-gen/domain-gen.go @@ -61,6 +61,8 @@ func main() { const ( tpl = `package internal +// AUTOGENERATED. DO NOT EDIT. + import ( "fmt" "strconv" diff --git a/cmd/chromedp-gen/internal/domain.go b/cmd/chromedp-gen/internal/domain.go index 0f39e42..376623b 100644 --- a/cmd/chromedp-gen/internal/domain.go +++ b/cmd/chromedp-gen/internal/domain.go @@ -1,5 +1,7 @@ package internal +// AUTOGENERATED. DO NOT EDIT. + import ( "fmt" "strconv" diff --git a/cmd/chromedp-gen/main.go b/cmd/chromedp-gen/main.go index abfd6e5..bb88927 100644 --- a/cmd/chromedp-gen/main.go +++ b/cmd/chromedp-gen/main.go @@ -6,6 +6,7 @@ package main //go:generate go run domain-gen.go //go:generate qtc -dir templates -ext qtpl +//go:generate gofmt -w -s templates/ import ( "bytes" diff --git a/cmd/chromedp-gen/update.sh b/cmd/chromedp-gen/update.sh index 27eb646..0c59c93 100755 --- a/cmd/chromedp-gen/update.sh +++ b/cmd/chromedp-gen/update.sh @@ -22,7 +22,25 @@ curl -s $JS_PROTO | base64 -d > $JS_TMP # merge browser_protocol.json and js_protocol.json jq -s '[.[] | to_entries] | flatten | reduce .[] as $dot ({}; .[$dot.key] += $dot.value)' $BROWSER_TMP $JS_TMP > $OUT -# convert boolean values listed as strings to real booleans -# (this is not used in favor of using the custom Bool type that correctly JSON unmarshals the value) -# left here for completeness -#perl -pi -e 's/"\s*:\s*"(true|false)"/": \1/g' $OUT +UPDATE=0 +LASTUPDATE=0 +if [ -f .last ]; then + LASTUPDATE=$(cat .last) +fi + +NOW=$(date +%s) +if (( "$NOW" >= $(($LASTUPDATE + 86400*5)) )); then + UPDATE=1 +fi + +if [[ "$UPDATE" == 1 ]]; then + go get -u -d \ + github.com/knq/chromedp/cmd/chromedp-gen + + go get -u \ + golang.org/x/tools/cmd/goimports \ + github.com/mailru/easyjson/easyjson \ + github.com/valyala/quicktemplate/qtc + + date +%s > .last +fi