#!/bin/sh
set -e
# adapted from node-bn.js
# notice the / at end in order to load this module
PACKAGE='ecc-jsbn'
SEDCMD="s,require\(\"./index.js\"\),require('$PACKAGE'),g"

tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' EXIT INT TERM HUP

cp test.js $tmpdir
find -name 'test.js' -not -path "./.pc/*" -print0 | \
    xargs -0 -n1  \
	  sh -c 'set -e; echo "Create: $3"; sed -E "$1" < "$3" > "$2/$3"' sedtape "$SEDCMD" "$tmpdir"
# avoid false that does not work outside build dir
find $tmpdir -maxdepth 1 -name 'test.js' -print0 | xargs -0 -n1 nodejs
