Skip to content

Instantly share code, notes, and snippets.

@alexjpaz
Created October 23, 2018 21:33
Show Gist options
  • Save alexjpaz/f4ae43f60c9f6dc2211a11fc63ac0e41 to your computer and use it in GitHub Desktop.
Save alexjpaz/f4ae43f60c9f6dc2211a11fc63ac0e41 to your computer and use it in GitHub Desktop.
search / replace with awareness of relative module
#!/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