Skip to content

Instantly share code, notes, and snippets.

@mvasilkov
Last active December 19, 2015 06:48
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 mvasilkov/5913579 to your computer and use it in GitHub Desktop.
Save mvasilkov/5913579 to your computer and use it in GitHub Desktop.
Helper tool for Box2D-HTML5 conversion. Fucking kill Google, one Closure Library at a time.
import re
import sys
def wrap(filename):
print(filename)
with open(filename) as f:
text = f.read()
ms = re.findall(r"goog\.require\('(.+?)'\)", text)
if not ms:
ms = ['box2d']
if ms[0].startswith('goog'):
ms = ['box2d'] + ms
requirements = "', '".join(['goog'] + ms)
prelude = """// This wrapper was auto-generated.
define(['%s'], function (goog, box2d) {
""" % requirements
ending = """return box2d
})
// End auto-generated code.
"""
with open(filename, 'wb') as f:
f.write(prelude)
f.write(text)
f.write(ending)
if __name__ == '__main__':
for a in sys.argv[1:]:
wrap(a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment