Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save iamjoshbinder/5569780 to your computer and use it in GitHub Desktop.

Select an option

Save iamjoshbinder/5569780 to your computer and use it in GitHub Desktop.
Compile CoffeeScript to JS
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>beforeRunningCommand</key>
<string>saveActiveFile</string>
<key>command</key>
<string>#!/usr/bin/env ruby
# encoding: utf-8
in_assets_folder = ENV['TM_FILEPATH'].match(/assets\//)
in_src_folder = ENV['TM_FILEPATH'].match(/src\/(.)+\.coffee/)
# Automagically compile .coffee to .js if:
# · Not in `assets/` folder
# · Not direct child of `src/`
if !in_assets_folder &amp;&amp; !in_src_folder
error = `coffee -c #{ENV['TM_FILEPATH']} 2&gt;&amp;1`
if error == ''
puts "✓ compiled #{ENV['TM_FILEPATH'].sub(/\.coffee$/, '.js')}"
else
puts "✗ #{error}"
end
# Automagically compile `src/abc.coffee` to `lib/abc.js` if:
# · Is a direct child of `src/`
elsif in_src_folder
error = `coffee -co ../lib #{ENV['TM_FILEPATH']} 2&gt;&amp;1`
if error == ''
puts "✓ compiled to #{ENV['TM_FILEPATH'].sub(/\.coffee$/, '.js').sub(/src/, 'lib')}"
else
puts "✗ #{error}"
end
end</string>
<key>input</key>
<string>none</string>
<key>keyEquivalent</key>
<string>@s</string>
<key>name</key>
<string>Compile CoffeeScript to JS</string>
<key>output</key>
<string>showAsTooltip</string>
<key>scope</key>
<string>source.coffee</string>
<key>uuid</key>
<string>CC66EEF5-C60D-4EDC-AE88-500095838FE7</string>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment