Skip to content

Instantly share code, notes, and snippets.

@abepark01
Created November 20, 2020 22:40
Show Gist options
  • Save abepark01/13da5f470121ea3f3d54400db299b34d to your computer and use it in GitHub Desktop.
Save abepark01/13da5f470121ea3f3d54400db299b34d to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import os
import sys
if __name__=="__main__":
if len(sys.argv) > 1:
path = sys.argv[1]
else:
sys.exit("The folder path is required")
for subdirectories, directories, files in os.walk(path):
for filename in files:
fullpath = subdirectories + os.path.sep + filename
if fullpath.endswith('.css') or fullpath.endswith('.scss') or fullpath.endswith('.less'):
data = []
with open(fullpath, 'r') as fstream:
for line in fstream:
line = line.rstrip()
pieces = line.split(' ')
if len(pieces) > 0 and '@apply' in pieces:
updated_pieces = [item.replace('.', '', 1) for item in pieces]
data.append(' '.join(updated_pieces) + "\n")
else:
data.append(line + "\n")
with open(fullpath, 'w') as fstream:
fstream.writelines(data)
@RatnadeepBiswakarma
Copy link

this just saved me hours! thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment