Last active
November 28, 2021 00:16
-
-
Save adisuryadi/2b938415b0fb598ce837 to your computer and use it in GitHub Desktop.
Run ES6/ES2016/ES2017 in Coderunner (using babel)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
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
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 thebabel-cli
package.Instructions should now read
npm install -g babel-cli
.