chromedp/cmd/chromedp-gen/update.sh

55 lines
1.4 KiB
Bash
Raw Normal View History

2017-01-24 15:09:23 +00:00
#!/bin/bash
2017-08-03 05:37:27 +00:00
BROWSER_VER=${1:-"master"}
JS_VER=${2:-"master"}
2017-01-24 15:09:23 +00:00
# updates protocol.json to the latest from the chromium source tree
SRC=$(realpath $(cd -P "$( dirname "${BASH_SOURCE[0]}" )" && pwd ))
HAR_PROTO="$SRC/har.json"
2017-01-24 15:09:23 +00:00
BASE_URL="https://chromium.googlesource.com"
2017-08-03 05:37:27 +00:00
BROWSER_PROTO="$BASE_URL/chromium/src/+/$BROWSER_VER/third_party/WebKit/Source/core/inspector/browser_protocol.json?format=TEXT"
JS_PROTO="$BASE_URL/v8/v8/+/$JS_VER/src/inspector/js_protocol.json?format=TEXT"
2017-01-24 15:09:23 +00:00
OUT=$SRC/protocol.json
TMP=$(mktemp -d /tmp/chromedp-gen.XXXXXX)
BROWSER_TMP="$TMP/browser_protocol.json"
JS_TMP="$TMP/js_protocol.json"
2017-08-03 05:37:27 +00:00
echo "BROWSER_PROTO: $BROWSER_PROTO"
echo "JS_PROTO: $JS_PROTO"
2017-01-24 15:09:23 +00:00
set -ve
# download
curl -s $BROWSER_PROTO | base64 -d > $BROWSER_TMP
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 $HAR_PROTO > $OUT
2017-01-24 15:09:23 +00:00
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
2017-06-25 01:38:47 +00:00
#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