Skip to content

Instantly share code, notes, and snippets.

@christiangenco
Last active December 28, 2015 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christiangenco/7494725 to your computer and use it in GitHub Desktop.
Save christiangenco/7494725 to your computer and use it in GitHub Desktop.
Convert .js files to .coffee files in batch.
#!/usr/bin/env ruby
# Usage:
# $ coffify app/*/*
# Depends on http://js2coffee.org/
# npm install js2coffee
ARGV.each{|filepath|
# skip this file if it's not a .js file
next unless filepath.index(/\.js$/)
# compute the destination .coffee filepath
# perhaps overly verbose.
dir = File.dirname(filepath)
coffeename = File.basename(filepath).sub(/\.js$/, '.coffee')
destination = File.join(dir, coffeename)
if File.exists?(destination)
print "\"#{destination}\" already exists. Overwrite? (y/n) "
answer = $stdin.gets.downcase
next unless answer.index('y')
end
if system("js2coffee #{filepath} > #{destination}")
system("rm #{filepath}")
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment