#! /bin/sh

# Create wtstats.template.html file

t=__wt.$$
trap 'rm -f $t; exit 0' 0 1 2 3 13 15

out=wtstats.html.template
# We require npm which may not be installed.
type npm > /dev/null 2>&1 || {
        echo 's_wtstats: npm not found' >&2
        echo '    npm is part of node.js from http://nodejs.org' >&2
        exit 1
}

cd ../tools/template || exit 1
rm -f ./$out
# Note: we don't do the npm install here, it downloads files
test -d ./node_modules || {
        echo 's_wtstats: missing node_modules directory, install by:' >&2
        echo '    cd ../tools/template; npm install' >&2
        exit 1
}
npm run build >$t 2>&1 || {
        echo "s_wtstats: npm failed" >&2
        cat $t
        exit 1
}
test -f ./$out || {
        echo "s_wtstats: $out not created" >&2
        cat $t
        exit 1
}
f=../$out
cmp ./$out $f > /dev/null 2>&1 ||
        (echo "Building tools/$out" && rm -f $f && cp ./$out $f)
exit 0
