Skip to content

Instantly share code, notes, and snippets.

@adisuryadi
Last active November 28, 2021 00:16
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save adisuryadi/2b938415b0fb598ce837 to your computer and use it in GitHub Desktop.
Save adisuryadi/2b938415b0fb598ce837 to your computer and use it in GitHub Desktop.
Run ES6/ES2016/ES2017 in Coderunner (using babel)
#!/bin/bash
#
# This script will transplie our code using babel and evaluates it using node.js
#
# Steps:
# 1) Install babel globally:
# npm install -g babel-cli
# or
# yarn global add babel-cli
# 2) Create a new language in Coderunner preferences (eg. Javascript (Babel)).
# 3) In the "Run Command" input, paste this line:
# node $compiler&&rm $compiler
# 4) Check "Language uses compile script" checkbox.
# 5) Click "Edit Script" beside it, which will open a script editor.
# 6) Copy and paste this gist to the editor and save it.
#
out=`echo "$CR_FILENAME" | sed 's/\(.*\)\..*/\1/'`
if [ -d "$out" ]; then
out="$out.out"
fi
# replace [babel_binary_path] below with the output of this command on terminal:
# which babel
# eg. /usr/local/bin/babel
[babel_binary_path] -o "$out" "$CR_FILENAME" "${@:1}"
status=$?
if [ $status -eq 0 ]
then
echo "$out"
fi
exit $status
@bramus
Copy link

bramus commented Aug 1, 2017

Thanks for this script. Was looking for this :)

Do note that the babel package no longer contains the CLI compiler. The CLI compiler ships in the babel-cli package.
Instructions should now read npm install -g babel-cli.

@keeprock
Copy link

keeprock commented Sep 5, 2017

Also, if you use NVM or similar software, don't forget to put your npm path in step 7. Like this:

/Users/alex/.nvm/versions/node/v8.4.0/bin/node $compiler&&rm $compiler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment