Created
November 20, 2020 22:40
-
-
Save abepark01/13da5f470121ea3f3d54400db299b34d to your computer and use it in GitHub Desktop.
Script to remove leading dots from @apply statements - https://tailwindcss.com/docs/upgrading-to-v2#remove-leading-dot-from-apply-statements
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 | |
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this just saved me hours! thanks!