OLD | NEW |
(Empty) | |
| 1 #!/bin/bash |
| 2 # |
| 3 # Compiles code with DDC and runs the resulting code in node.js with devtool, |
| 4 # an Electron-based debugger and browser environment. |
| 5 # |
| 6 # The first script supplied should be the one with `main()`. |
| 7 # |
| 8 # Saves the output in the same directory as the sources for convenient |
| 9 # inspection, modification or rerunning the code. |
| 10 # |
| 11 set -e |
| 12 DDC_PATH=$( cd $( dirname "${BASH_SOURCE[0]}" )/.. && pwd ) |
| 13 BASENAME=$( basename "${1%.*}") |
| 14 LIBROOT=$(cd $( dirname "${1%.*}") && pwd) |
| 15 export NODE_PATH=$DDC_PATH/lib/js/common:$LIBROOT:$NODE_PATH |
| 16 dart -c $DDC_PATH/bin/dartdevc.dart --modules=node --library-root=$LIBROOT \ |
| 17 --dart-sdk-summary=$DDC_PATH/lib/sdk/ddc_sdk.sum \ |
| 18 -o $LIBROOT/$BASENAME.js $* |
| 19 pushd $LIBROOT > /dev/null |
| 20 echo " |
| 21 // Fix the node.js search paths that Electron cleared out. |
| 22 const Module = require('module'); |
| 23 const originalResolveFilename = Module._resolveFilename; |
| 24 Module._resolveFilename = function (request, parent, isMain) { |
| 25 let paths = parent.paths; |
| 26 const ddcPath = \"$DDC_PATH/lib/js/common\"; |
| 27 if (paths[0] != ddcPath) { |
| 28 paths.splice(0, 0, ddcPath, \"$LIBROOT\"); |
| 29 } |
| 30 return originalResolveFilename(request, parent, isMain); |
| 31 }; |
| 32 let sdk = require(\"dart_sdk\"); |
| 33 let main = require(\"$BASENAME\").$BASENAME.main; |
| 34 sdk._isolate_helper.startRootIsolate(main, []);" \ |
| 35 > $LIBROOT/$BASENAME.run.js |
| 36 devtool $LIBROOT/$BASENAME.run.js |
| 37 popd > /dev/null |
OLD | NEW |