diff --git a/mail/generate.py b/mail/generate.py index 349f7be..04c462f 100755 --- a/mail/generate.py +++ b/mail/generate.py @@ -1,13 +1,28 @@ import subprocess import shutil +import os from pathlib import Path def runcmd(cmd): + if os.name == "nt": + return subprocess.check_output(cmd, shell=True) proc = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) return proc.communicate() local_path = Path(__file__).resolve().parent -node_bin = local_path.parent / 'node_modules' / '.bin' +out = runcmd("npm bin") + +try: + node_bin = Path(out[0].decode('utf-8').rstrip()) +except: + node_bin = Path(out.decode('utf-8').rstrip()) + +print(f"assuming npm bin directory \"{node_bin}\". Is this correct?") +if input("[yY/nN]: ").lower() == "n": + node_bin = local_path.parent / 'node_modules' / '.bin' + print(f"this? \"{node_bin}\"") + if input("[yY/nN]: ").lower() == "n": + node_bin = input("input bin directory: ") for mjml in [f for f in local_path.iterdir() if f.is_file() and 'mjml' in f.suffix]: print(f'Compiling {mjml.name}') diff --git a/scss/compile.py b/scss/compile.py index 28cb299..8431211 100755 --- a/scss/compile.py +++ b/scss/compile.py @@ -2,14 +2,29 @@ import sass import subprocess import shutil +import os from pathlib import Path def runcmd(cmd): + if os.name == "nt": + return subprocess.check_output(cmd, shell=True) proc = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) return proc.communicate() local_path = Path(__file__).resolve().parent -node_bin = local_path.parent / 'node_modules' / '.bin' +out = runcmd("npm bin") + +try: + node_bin = Path(out[0].decode('utf-8').rstrip()) +except: + node_bin = Path(out.decode('utf-8').rstrip()) + +print(f"assuming npm bin directory \"{node_bin}\". Is this correct?") +if input("[yY/nN]: ").lower() == "n": + node_bin = local_path.parent / 'node_modules' / '.bin' + print(f"this? \"{node_bin}\"") + if input("[yY/nN]: ").lower() == "n": + node_bin = input("input bin directory: ") for bsv in [d for d in local_path.iterdir() if 'bs' in d.name]: scss = bsv / f'{bsv.name}-jf.scss' @@ -21,7 +36,11 @@ for bsv in [d for d in local_path.iterdir() if 'bs' in d.name]: precision=6)) if css.exists(): print(f'{bsv.name}: Compiled.') - runcmd(f'{str((node_bin / "postcss").resolve())} {str(css.resolve())} --replace --use autoprefixer') + # postcss only excepts forwards slashes? weird. + cssPath = str(css.resolve()) + if os.name == 'nt': + cssPath = cssPath.replace('\\', '/') + runcmd(f'{str((node_bin / "postcss").resolve())} {cssPath} --replace --use autoprefixer') print(f'{bsv.name}: Prefixed.') runcmd(f'{str((node_bin / "cleancss").resolve())} --level 1 --format breakWith=lf --output {str(min_css.resolve())} {str(css.resolve())}') if min_css.exists(): diff --git a/scss/get_node_deps.py b/scss/get_node_deps.py index a048e6b..befa1d3 100644 --- a/scss/get_node_deps.py +++ b/scss/get_node_deps.py @@ -1,17 +1,26 @@ #!/usr/bin/env python3 import subprocess +import os from pathlib import Path + def runcmd(cmd): + if os.name == "nt": + return subprocess.check_output(cmd, shell=True) proc = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) return proc.communicate() + print('Installing npm packages') root_path = Path(__file__).parents[1] -runcmd(f'npm install --prefix {root_path}') +if os.name == 'nt': + root_path /= 'node_modules' -if (root_path / 'node_modules' / 'cleancss').exists(): +runcmd('npm install') + +if (root_path / 'node_modules' / 'cleancss').exists() or (root_path / 'cleancss').exists(): print(f'Installed successfully in {str((root_path / "node_modules").resolve())}.') +