Skip to content

Instantly share code, notes, and snippets.

@hooptie45
Created August 13, 2016 18:47
Show Gist options
  • Save hooptie45/6f9a7e6251a120c8d2d04e75f9d73c0e to your computer and use it in GitHub Desktop.
Save hooptie45/6f9a7e6251a120c8d2d04e75f9d73c0e to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'open-uri'
require 'pathname'
require 'json'
def strip_hash(f)
ext = f.extname
if ext.include?("?")
f.sub_ext(ext.split("?").first)
else
f
end
end
sourcemap_url = ARGV[0] or "USAGE: sourcemap-extract.rb <source-map-url> [<destination>]"
destination = ARGV[1]
destination ||= "./tmp"
root = Pathname(destination || "./tmp").expand_path
sourcemap = open(sourcemap_url).read
files, contents = JSON(sourcemap).values_at(*%w(sources sourcesContent))
files = files.map { |f| f.sub("~", "./vendor") }
files = files.map { |f| root.join(f).expand_path }
files = files.map { |f| strip_hash(f) }
files.zip(contents).each_with_index do |(dest, source), index|
dest.dirname.mkpath
puts "[%4s] \t (%5s) \t WROTE %s" % [index, dest.write(source), dest.relative_path_from(Pathname(".").expand_path)]
end
puts "\nDESTINATION #{root}"
@adminy
Copy link

adminy commented Jan 25, 2023

./sourcemap-extract.rb:30:in zip': wrong argument type NilClass (must respond to :each) (TypeError) from ./sourcemap-extract.rb:30:in

'

{"version":3,"file":"service.js","mappings": ...

, "__webpack_module_cache__","__webpack_require__","moduleId","cachedModule","__webpack_modules__","__webpack_exports__"],"sourceRoot":""}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment