From 80526c0055ff0c685e5a4fb8fa876c27b6ac0c5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Fri, 15 Jan 2021 18:42:56 +0100 Subject: [PATCH] sassw: add support for building multiple files --- bin/sassw | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/bin/sassw b/bin/sassw index 1c2210a..0aa0b35 100755 --- a/bin/sassw +++ b/bin/sassw @@ -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())