aboutsummaryrefslogtreecommitdiffstats
path: root/scss.py
blob: 2dbf179ed9f7db7a77dd1a6af7836a6fc6c90d45 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""
Single-file libsass wrapper that can compile SASS/SCSS files into CSS.

Usage: `python scss.py input.scss:output.css input2.scss:output2.css`
"""

import sys

import sass

if len(sys.argv) <= 1:
    print("Usage: python scss.py include_dir:input.scss:output.css import_dir:input2.sass:output2.sass")

for arg in sys.argv[1:]:
    include_dir, input_file, output_file = arg.split(":")
    source_map_file = f"{output_file}.map"

    try:
        compiled, source_map = sass.compile(
            filename=input_file,
            output_style="compressed",
            output_filename_hint=output_file,
            source_map_filename=source_map_file,
            include_paths=[include_dir]
        )
    except sass.CompileError as e:
        print(f"Failed to compile {input_file}\n\n{e}")
        exit(1)
    else:
        with open(output_file, "w") as out_fh:
            out_fh.write(compiled)

        with open(source_map_file, "w") as map_fh:
            map_fh.write(source_map)

        print(f"Compiled: {input_file} -> {output_file}")