Skip to content

Instantly share code, notes, and snippets.

@cobyism
Created January 23, 2015 11:23
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 cobyism/e836a5ad9520318c8dcf to your computer and use it in GitHub Desktop.
Save cobyism/e836a5ad9520318c8dcf to your computer and use it in GitHub Desktop.
Reverse engineer *.js.map files to *.coffee
#!/usr/bin/env ruby
require "json"
require "fileutils"
# Find all *.js.map files in current directory
files = Dir["./**/*.js.map"]
# Parse out the JSON
mapfiles = files.map { |f| JSON.parse File.read(f) }
# Set where the output should go
export_directory = "./source"
# Nuke the previous output
exec "rm -rf #{export_directory}" if File.directory?(export_directory)
# Iterate over all the sources and resurrect them.
mapfiles.each do |mapfile|
mapfile["sources"].each_with_index do |source, index|
# Create a directory for each file.
outdir = File.dirname("#{export_directory}/#{source}")
FileUtils.mkdir_p(outdir) unless File.directory?(outdir)
# Create each file and write out the contents
outfile = "#{export_directory}/#{source}"
contents = mapfile["sourcesContent"][index]
File.open(outfile, "w") { |f| f.write contents }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment