Skip to content

Instantly share code, notes, and snippets.

@islandjoe
Forked from adisuryadi/compile.sh
Last active July 18, 2020 16:37
Show Gist options
  • Save islandjoe/a374b78096822964381792485354e20d to your computer and use it in GitHub Desktop.
Save islandjoe/a374b78096822964381792485354e20d to your computer and use it in GitHub Desktop.
Run ES6 in Coderunner via Babel
#!/bin/bash
#
# This script will create transpile ES6 (with JSX) support in babel
# to ES5 that evaluatable in regular node.js
# Script will create a filename.out file, evaluates it, then remove the file.
#
# First off, you'll need Node.js.
#
# Steps:
# 1) Install babel globally npm install -g babel-cli
# 2) Create new language in Coderunner preferences Eg. Babel
# 3) Check "Language uses compile script"
# 4) Click "Edit Script" button, which will create/open compile script
# 5) Copy and paste this file, save!
# 6) Reopen preferences of the new created language
# 7) Inside "Run Command" input, paste this line
# /usr/local/bin/node $compiler&&rm $compiler
#
out=`echo "$CR_FILENAME" | sed 's/\(.*\)\..*/\1/'`
if [ -d "$out" ]; then
out="$out.out"
fi
~/.npm-packages/bin/babel --stage 0 -o "$out" "$CR_FILENAME" "${@:1}"
status=$?
if [ $status -eq 0 ]
then
echo "$out"
fi
exit $status
@islandjoe
Copy link
Author

A "fix" for this error:

Library/Application Support/CodeRunner/Languages/Babel.crLanguage/Scripts/compile.sh: line 25: babel: command not found

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