Skip to content

Instantly share code, notes, and snippets.

@andrejewski
Created July 27, 2016 18:09
Show Gist options
  • Save andrejewski/92e486ecd855d539e6c4c5f07515d84e to your computer and use it in GitHub Desktop.
Save andrejewski/92e486ecd855d539e6c4c5f07515d84e to your computer and use it in GitHub Desktop.
# DeCoffeeScript script
if [[ -z "$1" ]] ; then
echo 'decaf error: pass a basename'
exit 1
fi
coffee_file=$1.coffee
js_file=$1.js
coffee -c $coffee_file
mv $coffee_file _$coffee_file # keep around for reference
sed -i '' 's/ / /g' ${js_file} # 2 spaces to 4
sed -i '' 's/^ //g' ${js_file} # remove first indent
sed -i '' 's/: function(/(/g' ${js_file} # method syntax
sed -i '' 's/function(/function (/g' ${js_file} # keyword spacing
sed -i '' '/ var /d' ${js_file} # remove var declarations
sed -i '' '/^var /d' ${js_file} # remove var declarations
# remove the iife
sed -i '' '1,2d' ${js_file}
sed -i '' '$d' ${js_file}
sed -i '' '$d' ${js_file}
git add $coffee_file
git add $js_file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment