Last active
December 26, 2019 14:42
-
-
Save juliandescottes/ec6d9f630117f2d5345231745b7c70b0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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