#!/bin/sh
# Validate AMP HTML with at $1.
# Returns 0 and message on stdout on success, else 1 and stderr diagnostics.
#
# Wrapper around npm amphtml-validator.
#
# On V1.0.23 as of 2018/12/24.
#
# Note that the maxOS version is installed in a bizarre location
# as of V1.0.23.
#
# Ensure that /usr/local/bin is on the PATH for 'node' at al.
. script/NPM.loc
PATH="$PATH:$NPMBIN"
export PATH

# Expected location of validator.
AV=$NPMBIN/amphtml-validator

# V1.0.23 install is in bizarre location.
if [ -x /usr/local/lib/node_modules/node/bin/amphtml-validator ]; then
    AV=/usr/local/lib/node_modules/node/bin/amphtml-validator
fi

if [ ! -x $AV ]; then
    echo "ERROR: amphtml-validator not found at $AV." 1>&2
    exit 1
fi

exec $AV --format text $1
