sassw: add support for building multiple files

This commit is contained in:
Frédéric Péters 2021-01-15 18:42:56 +01:00
parent 793419c97a
commit 80526c0055
1 changed files with 25 additions and 19 deletions

View File

@ -19,28 +19,32 @@ if os.path.isdir(filename):
scss_filenames = [x for x in os.listdir(filename) if not x.startswith('_') and x.endswith('.scss')]
if not scss_filenames:
print('Error: directory specified but no proper scss file within.', file=sys.stderr)
filename = os.path.join(filename, scss_filenames[0])
filenames = [os.path.join(filename, x) for x in scss_filenames]
else:
filenames = sys.argv[1:]
def build():
global sources, directories
result = subprocess.run(
['sassc', '-mauto', filename, filename.replace('.scss', '.css')],
capture_output=True,
text=True)
sys.stdout.write(result.stdout)
sys.stderr.write(result.stderr)
if result.returncode:
# error
with open(filename.replace('.scss', '.css'), 'w') as fd:
print('''body::before {
white-space: pre;
font-family: monospace;
content: "%s";
}''' % result.stderr.replace('\n', '\\A').replace('"', '\\"'),
file=fd)
basepath = os.path.abspath(os.path.dirname(filename))
sources = [os.path.abspath(os.path.join(basepath, x)) for x in json.load(open(filename.replace('.scss', '.css.map')))['sources']]
directories = set([os.path.dirname(x) for x in sources])
directories = set()
for filename in filenames:
result = subprocess.run(
['sassc', '-mauto', filename, filename.replace('.scss', '.css')],
capture_output=True,
text=True)
sys.stdout.write(result.stdout)
sys.stderr.write(result.stderr)
if result.returncode:
# error
with open(filename.replace('.scss', '.css'), 'w') as fd:
print('''body::before {
white-space: pre;
font-family: monospace;
content: "%s";
}''' % result.stderr.replace('\n', '\\A').replace('"', '\\"'),
file=fd)
basepath = os.path.abspath(os.path.dirname(filename))
sources = [os.path.abspath(os.path.join(basepath, x)) for x in json.load(open(filename.replace('.scss', '.css.map')))['sources']]
directories = directories.union(set([os.path.dirname(x) for x in sources]))
class EventManager(pyinotify.ProcessEvent):
def process_default(self, event):
@ -51,6 +55,8 @@ class EventManager(pyinotify.ProcessEvent):
build()
print(f' ({time.time() - t0:.2f}s)')
print('>>> Building %s' % ' '.join(filenames))
build()
wm = pyinotify.WatchManager()
notifier = pyinotify.Notifier(wm, default_proc_fun=EventManager())