Created
October 23, 2018 21:33
-
-
Save alexjpaz/f4ae43f60c9f6dc2211a11fc63ac0e41 to your computer and use it in GitHub Desktop.
search / replace with awareness of relative module
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
#!/usr/bin/env python3 | |
import os | |
files = [ | |
] | |
for f in files: | |
cwd = os.getcwd() | |
path = os.path.dirname(f) | |
op = "" | |
for s in range(path.count("/")+1): | |
op = os.path.join(op, os.pardir) | |
import fileinput | |
for line in fileinput.input(f, inplace = 1): | |
output = line.replace("const logger = require('winston');", "const { logger } = require('%s/lib/logger')" % (op)) | |
output = output.rstrip() | |
print(output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment