Strange Symphonies The whole is greater than the sum of its parts

29Jul/071

Remove Firebug JavaScript Console Calls on Deployment

One thing I keep forgetting to do when deploying a Rails application is to remove any Firebug JavaScript console calls I use for debugging.

You know, those:

console.log("Please execute");
console.info("Warning " + collections.length + " Areas found")

Or something like that.

When committing back to the repository, you simply forget to remove them. Thus when deploying your new code, for those people who don't have Firebug installed, the script will end in a premature death.

Oh noes!

This definitely isn't cool, and its just a minor thing you forgot to do...and its causing a hell lot of problems.

Lucky for us we can hook into the Capistrano after update code callback to comment/strip out those lines from the JavaScript file.

To Comment Out:

task :after_update_code, :roles => :app do
  javascript_path = File.join(release_path, 'public', 'javascripts', '*.js')
  run "sed -i -r 's/(\\/\\/|^)(\\s*console\\.(log|info|debug|warn|error).*)/\\/\\/\\2/i' #{javascript_path}"
end

To Strip Out:

task :after_update_code, :roles => :app do
  javascript_path = File.join(release_path, 'public', 'javascripts', '*.js')
  run "sed -i -r 's/(\\/\\/|^)(\\s*console\\.(log|info|debug|warn|error).*)//i' #{javascript_path}"
end

So instead of removing those debugging calls from the file, just leave them there and let Capistrano and sed strip them out for ya!

Talk about an easy life :3.

Note: This only works in the top level javascripts directory.

Related posts

Tags

Comments (1) Trackbacks (0)
  1. I keep geting the error, In IE how do I remove firebug?


Leave a comment


No trackbacks yet.