Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.