Skip to content

Instantly share code, notes, and snippets.

@gcman105
Forked from unamashana/js2cs.rb
Created November 25, 2012 13:57
Show Gist options
  • Save gcman105/4143620 to your computer and use it in GitHub Desktop.
Save gcman105/4143620 to your computer and use it in GitHub Desktop.
Converting project files from Javascript to CoffeeScript
SRC_BASE_DIR = "."
DEST_BASE_DIR = "."
JS2COFFEE = "~/node_modules/js2coffee/bin/js2coffee"
dirs = []
files = []
Dir.glob("#{SRC_BASE_DIR}/**/*.js").each do |file|
files << file
dir = File.dirname(file).split(SRC_BASE_DIR)[1]
dirs << dir unless dirs.include?(dir)
end
puts dirs
dirs.each do |dir|
IO.popen("mkdir -p #{DEST_BASE_DIR}#{dir}")
end
files.each do |file|
# convert
relative_path = File.dirname(file).split(SRC_BASE_DIR)[1]
basename = File.basename(file, ".js")
output_file = "#{DEST_BASE_DIR}#{relative_path}/#{basename}.coffee"
puts "#{JS2COFFEE} #{file} > #{output_file}"
`#{JS2COFFEE} #{file} > #{output_file}`
puts "Removing #{file}"
`rm #{file}`
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment