Skip to content

Instantly share code, notes, and snippets.

@hmdne
Created August 17, 2020 02:15
Show Gist options
  • Select an option

  • Save hmdne/6e8b70683b60fcc71d5a3ae3e4679a95 to your computer and use it in GitHub Desktop.

Select an option

Save hmdne/6e8b70683b60fcc71d5a3ae3e4679a95 to your computer and use it in GitHub Desktop.
Move all stubs from an opal file to a runtime call.
require 'set'
f = File.read(ARGV[0])
stubs = Set.new
f = f.gsub /^ Opal\.add_stubs\(\[(.*?)\]\)/ do
stubs += $1.gsub("'", '').split(', ')
""
end
stubs = stubs.map{|i|"'#{i}'"}.join(",")
f = f.gsub %r<// Instantiate the main object>,
"Opal.add_stubs([#{stubs}]);"
print f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment