Created
December 6, 2010 13:08
-
-
Save orlin/730255 to your computer and use it in GitHub Desktop.
CoffeeScript + Jim bundles / Guard
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
guard 'coffeescript', :output => 'app/javascripts', :wrap => false, :shallow => false do | |
watch('^app/coffeescripts/(.*)\.coffee') | |
end | |
def jimify(bundles, why = nil) | |
bundles = Array(bundles) | |
message = "Jim bundle & compress (bundles: #{bundles.join(", ")})" | |
message += " due to #{why} change" if why | |
puts message | |
# just bundle them first, so that livereload happens faster | |
bundles.each { |name| puts %x[ jim bundle #{name} --force ] } | |
# compress to a different path, so that the bundled (development source) can be .gitignored | |
bundles.each { |name| puts %x[ jim compress #{name} --force --bundle-dir=public/javascripts] } | |
end | |
# convention over configuration: returns the names of all bundles without the "vendor" one | |
# TODO: check if Jim has a method for getting the list of bundles, otherwise extract from the Jimfile | |
def bundles | |
names = [] | |
Dir.chdir(File.dirname(__FILE__) + '/app/javascripts') do | |
Dir.glob("*") do |name| | |
names << name if File.directory?(name) && name != "shared" | |
end | |
end | |
names | |
end | |
guard 'shell' do | |
# vendored libs go to a separate bundle for performance reasons (faster development) | |
watch('^public/javascripts/vendor/.+\.js$') do |m| | |
jimify "vendor", m[0] | |
end | |
# javascript bundles source files are contained in a directory named after the bundle | |
watch('^app/javascripts/(.+)/.+\.js$') do |m| | |
if m[1] != "shared" | |
jimify m[1], m[0] | |
else | |
# shared across bundles code is faster to compress when bundle "vendor" is excluded | |
# all bundles have a corresponding dir in app/javascripts (the only extra dir being "shared") | |
# ideally, there could be a $ jim bundle / compress --exclude-bundles=list | |
jimify bundles, m[0] | |
end | |
end | |
end |
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
{ "bundle_dir": "public/javascripts/bundle" | |
, "vendor_dir": "public/javascripts/vendor" | |
, "bundles": | |
{ "vendor": | |
[ "underscore" | |
, "jquery" | |
] | |
, "development": | |
[ "jquery.lint" | |
, "app/javascripts/development/lint" | |
] | |
, "master": | |
[ "app/javascripts/shared/tardis" | |
, "app/javascripts/master/app" | |
] | |
} | |
, "compressor": "yui" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment