1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-22 17:10:10 +00:00

Add windows build support from jf-accounts

This commit is contained in:
Harvey Tindall 2020-08-04 18:24:11 +01:00
parent 5329f02768
commit 8a8fe65192
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
3 changed files with 48 additions and 5 deletions

View File

@ -1,13 +1,28 @@
import subprocess import subprocess
import shutil import shutil
import os
from pathlib import Path from pathlib import Path
def runcmd(cmd): def runcmd(cmd):
if os.name == "nt":
return subprocess.check_output(cmd, shell=True)
proc = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) proc = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
return proc.communicate() return proc.communicate()
local_path = Path(__file__).resolve().parent local_path = Path(__file__).resolve().parent
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' 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]: for mjml in [f for f in local_path.iterdir() if f.is_file() and 'mjml' in f.suffix]:
print(f'Compiling {mjml.name}') print(f'Compiling {mjml.name}')

View File

@ -2,14 +2,29 @@
import sass import sass
import subprocess import subprocess
import shutil import shutil
import os
from pathlib import Path from pathlib import Path
def runcmd(cmd): def runcmd(cmd):
if os.name == "nt":
return subprocess.check_output(cmd, shell=True)
proc = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) proc = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
return proc.communicate() return proc.communicate()
local_path = Path(__file__).resolve().parent local_path = Path(__file__).resolve().parent
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' 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]: for bsv in [d for d in local_path.iterdir() if 'bs' in d.name]:
scss = bsv / f'{bsv.name}-jf.scss' 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)) precision=6))
if css.exists(): if css.exists():
print(f'{bsv.name}: Compiled.') 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.') 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())}') runcmd(f'{str((node_bin / "cleancss").resolve())} --level 1 --format breakWith=lf --output {str(min_css.resolve())} {str(css.resolve())}')
if min_css.exists(): if min_css.exists():

View File

@ -1,17 +1,26 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import subprocess import subprocess
import os
from pathlib import Path from pathlib import Path
def runcmd(cmd): def runcmd(cmd):
if os.name == "nt":
return subprocess.check_output(cmd, shell=True)
proc = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) proc = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE)
return proc.communicate() return proc.communicate()
print('Installing npm packages') print('Installing npm packages')
root_path = Path(__file__).parents[1] 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())}.') print(f'Installed successfully in {str((root_path / "node_modules").resolve())}.')