sassw: add support for building multiple files
This commit is contained in:
parent
793419c97a
commit
80526c0055
44
bin/sassw
44
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')]
|
scss_filenames = [x for x in os.listdir(filename) if not x.startswith('_') and x.endswith('.scss')]
|
||||||
if not scss_filenames:
|
if not scss_filenames:
|
||||||
print('Error: directory specified but no proper scss file within.', file=sys.stderr)
|
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():
|
def build():
|
||||||
global sources, directories
|
global sources, directories
|
||||||
result = subprocess.run(
|
directories = set()
|
||||||
['sassc', '-mauto', filename, filename.replace('.scss', '.css')],
|
for filename in filenames:
|
||||||
capture_output=True,
|
result = subprocess.run(
|
||||||
text=True)
|
['sassc', '-mauto', filename, filename.replace('.scss', '.css')],
|
||||||
sys.stdout.write(result.stdout)
|
capture_output=True,
|
||||||
sys.stderr.write(result.stderr)
|
text=True)
|
||||||
if result.returncode:
|
sys.stdout.write(result.stdout)
|
||||||
# error
|
sys.stderr.write(result.stderr)
|
||||||
with open(filename.replace('.scss', '.css'), 'w') as fd:
|
if result.returncode:
|
||||||
print('''body::before {
|
# error
|
||||||
white-space: pre;
|
with open(filename.replace('.scss', '.css'), 'w') as fd:
|
||||||
font-family: monospace;
|
print('''body::before {
|
||||||
content: "%s";
|
white-space: pre;
|
||||||
}''' % result.stderr.replace('\n', '\\A').replace('"', '\\"'),
|
font-family: monospace;
|
||||||
file=fd)
|
content: "%s";
|
||||||
basepath = os.path.abspath(os.path.dirname(filename))
|
}''' % result.stderr.replace('\n', '\\A').replace('"', '\\"'),
|
||||||
sources = [os.path.abspath(os.path.join(basepath, x)) for x in json.load(open(filename.replace('.scss', '.css.map')))['sources']]
|
file=fd)
|
||||||
directories = set([os.path.dirname(x) for x in sources])
|
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):
|
class EventManager(pyinotify.ProcessEvent):
|
||||||
def process_default(self, event):
|
def process_default(self, event):
|
||||||
|
@ -51,6 +55,8 @@ class EventManager(pyinotify.ProcessEvent):
|
||||||
build()
|
build()
|
||||||
print(f' ({time.time() - t0:.2f}s)')
|
print(f' ({time.time() - t0:.2f}s)')
|
||||||
|
|
||||||
|
|
||||||
|
print('>>> Building %s' % ' '.join(filenames))
|
||||||
build()
|
build()
|
||||||
wm = pyinotify.WatchManager()
|
wm = pyinotify.WatchManager()
|
||||||
notifier = pyinotify.Notifier(wm, default_proc_fun=EventManager())
|
notifier = pyinotify.Notifier(wm, default_proc_fun=EventManager())
|
||||||
|
|
Loading…
Reference in New Issue