Skip to content

Instantly share code, notes, and snippets.

@juliandescottes
Last active December 26, 2019 14:42
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 juliandescottes/ec6d9f630117f2d5345231745b7c70b0 to your computer and use it in GitHub Desktop.
Save juliandescottes/ec6d9f630117f2d5345231745b7c70b0 to your computer and use it in GitHub Desktop.
import os, re
devtools_root = os.path.abspath(".");
print devtools_root, ": DEVTOOLS ROOT\n"
def path_repl(matchobj):
print "REPL MATCHOBJ", matchobj.group(1)
fullpath = os.path.join(current_root, matchobj.group(1))
print "REPL FULLPATH", fullpath
print "REPL ABSPATH", os.path.abspath(fullpath)
processed_path = re.sub(devtools_root, "devtools", os.path.abspath(fullpath))
print "PROCESSED PATH", processed_path
return "require(\"" + processed_path;
from os.path import join, getsize
for path, dirs, files in os.walk('.'):
current_root = path
print path, "traversing...\n"
if '.hg' in dirs:
dirs.remove('.hg') # skip hg folders
if 'node_modules' in dirs:
dirs.remove('node_modules') # skip node_modules folders
if 'debugger' in dirs:
dirs.remove('debugger') # skip debugger folders
if 'node' in dirs:
dirs.remove('node') # skip node test folders
if 'build' in dirs:
dirs.remove('build') # skip a debugger build folder
if 'vendor' in dirs:
dirs.remove('vendor') # skip vendored libs
for filename in files:
fullpath = os.path.join(path, filename)
with open(fullpath, 'r') as f:
data = re.sub(
r"require\(\"(\.[^\"]*)",
path_repl,
f.read()
)
with open(fullpath, 'w') as f:
f.write(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment