Created
March 7, 2012 15:43
-
-
Save EtienneLem/1993872 to your computer and use it in GitHub Desktop.
Compile CoffeeScript to JS
This file contains 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
<?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 && !in_src_folder | |
error = `coffee -c #{ENV['TM_FILEPATH']} 2>&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>&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
Précision… c’est qu’en Ruby, les backticks (
`
) servent à retourner la valeur de standard output. Mais dans le script, on veut utiliser standard error, donc la façon de le retourner c’est en le redirigeant vers standard output.