blob: adec066a7299d20879adf4266285e14b086593a5 [file] [log] [blame]
#!/bin/bash
#
# Compiles code with DDC and runs the resulting code in node.js.
#
# The first script supplied should be the one with `main()`.
#
# Saves the output in the same directory as the sources for convenient
# inspection, modification or rerunning the code.
#
set -e
DDC_PATH=$( cd $( dirname "${BASH_SOURCE[0]}" )/.. && pwd )
BASENAME=$( basename "${1%.*}")
LIBROOT=$(cd $( dirname "${1%.*}") && pwd)
export NODE_PATH=$DDC_PATH/lib/js/common:$LIBROOT:$NODE_PATH
dart -c $DDC_PATH/bin/dartdevc.dart --modules=node --library-root=$LIBROOT \
--dart-sdk-summary=$DDC_PATH/lib/sdk/ddc_sdk.sum \
-o $LIBROOT/$BASENAME.js $*
pushd $LIBROOT > /dev/null
# TODO(jmesserly): we could have this output the same content as the devtool
# script, so you could debug the output without recompiling?
echo "
let sdk = require(\"dart_sdk\");
let main = require(\"./$BASENAME\").$BASENAME.main;
sdk.dart.ignoreWhitelistedErrors(false);
try {
sdk._isolate_helper.startRootIsolate(main, []);
} catch(e) {
console.error(e.toString(), sdk.dart.stackTrace(e).toString());
process.exit(1);
}" \
> $LIBROOT/$BASENAME.run.js
node $BASENAME.run.js || exit 1
popd > /dev/null