Last active
March 7, 2016 21:14
-
-
Save mbildner/53754486a31f426477ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pry' | |
all_output = `ag -G ".jsx" "//= require"` | |
calls = all_output.lines.map do |line| | |
path = line.split(':').last | |
.gsub('//= ', '') | |
.gsub('require_tree ', '') | |
.gsub('require ', '') | |
.gsub(/\r/, '') | |
.gsub(/\n/, '') | |
file = line.gsub(/:.*$/, '') | |
.gsub(/\r/, '') | |
.gsub(/\n/, '') | |
[file, "require('#{path}')"] | |
end | |
calls.each{|c| puts c} | |
iife_wrapped = calls.map do |path, require_path| | |
collector = [] | |
last_was_require = false | |
was_already_wrapped = false | |
file_text = File.read(path) | |
file_text.lines.each do |line| | |
if line.start_with? "//= require" | |
collector << line | |
last_was_require = true | |
else | |
if last_was_require | |
if line == "\n" || line == "\r" | |
# lol noop | |
elsif !line.start_with? "(function()" | |
collector << "(function(){" | |
binding.pry | |
else | |
was_already_wrapped = true | |
end | |
last_was_require = false | |
end | |
collector << " " + line | |
end | |
end | |
if !was_already_wrapped | |
collector << "})();" | |
end | |
collector.join("") | |
end | |
iife_wrapped.each{|f|puts f} |
my eyes are literally bleeding
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
watch out for calls to global namespaces that have to be
require
d