1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-06-26 03:17:47 +02:00

added -y option to prebuild scripts using node_bin

similar to apt, -y assumes yes to all questions, specifically if
node_bin is correct here. This is necessary for goreleaser, as it is not
interactive.
This commit is contained in:
Harvey Tindall 2020-08-16 14:39:47 +01:00
parent dd0eabf157
commit 02183c7fcc
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2
3 changed files with 90 additions and 51 deletions

View File

@ -14,8 +14,8 @@ before:
- python3 config/generate_ini.py -i config/config-base.json -o data/config-default.ini - python3 config/generate_ini.py -i config/config-base.json -o data/config-default.ini
- python3 -m pip install libsass - python3 -m pip install libsass
- python3 scss/get_node_deps.py - python3 scss/get_node_deps.py
- python3 scss/compile.py - python3 scss/compile.py -y
- python3 mail/generate.py - python3 mail/generate.py -y
builds: builds:
- dir: ./ - dir: ./
env: env:

View File

@ -1,49 +1,60 @@
import subprocess import subprocess
import shutil import shutil
import os import os
import argparse
from pathlib import Path from pathlib import Path
parser = argparse.ArgumentParser()
parser.add_argument(
"-y", "--yes", help="use assumed node bin directory.", action="store_true"
)
def runcmd(cmd): def runcmd(cmd):
if os.name == "nt": if os.name == "nt":
return subprocess.check_output(cmd, shell=True) 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") out = runcmd("npm bin")
try: try:
node_bin = Path(out[0].decode('utf-8').rstrip()) node_bin = Path(out[0].decode("utf-8").rstrip())
except: except:
node_bin = Path(out.decode('utf-8').rstrip()) node_bin = Path(out.decode("utf-8").rstrip())
print(f"assuming npm bin directory \"{node_bin}\". Is this correct?") args = parser.parse_args()
if not args.yes:
print(f'assuming npm bin directory "{node_bin}". Is this correct?')
if input("[yY/nN]: ").lower() == "n": 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}\"") print(f'this? "{node_bin}"')
if input("[yY/nN]: ").lower() == "n": if input("[yY/nN]: ").lower() == "n":
node_bin = input("input bin directory: ") 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}")
fname = mjml.with_suffix(".html") fname = mjml.with_suffix(".html")
runcmd(f'{str(node_bin / "mjml")} {str(mjml)} -o {str(fname)}') runcmd(f'{str(node_bin / "mjml")} {str(mjml)} -o {str(fname)}')
if fname.is_file(): if fname.is_file():
print('Done.') print("Done.")
html = [f for f in local_path.iterdir() if f.is_file() and 'html' in f.suffix] html = [f for f in local_path.iterdir() if f.is_file() and "html" in f.suffix]
output = local_path.parent / 'data' output = local_path.parent / "data"
for f in html: for f in html:
shutil.copy(str(f), shutil.copy(str(f), str(output / f.name))
str(output / f.name)) print(f"Copied {f.name} to {str(output / f.name)}")
print(f'Copied {f.name} to {str(output / f.name)}') txtfile = f.with_suffix(".txt")
txtfile = f.with_suffix('.txt')
if txtfile.is_file(): if txtfile.is_file():
shutil.copy(str(txtfile), shutil.copy(str(txtfile), str(output / txtfile.name))
str(output / txtfile.name)) print(f"Copied {txtfile.name} to {str(output / txtfile.name)}")
print(f'Copied {txtfile.name} to {str(output / txtfile.name)}')
else: else:
print(f'Warning: {txtfile.name} does not exist. Text versions of emails should be supplied.') print(
f"Warning: {txtfile.name} does not exist. Text versions of emails should be supplied."
)

View File

@ -3,52 +3,80 @@ import sass
import subprocess import subprocess
import shutil import shutil
import os import os
import argparse
from pathlib import Path from pathlib import Path
parser = argparse.ArgumentParser()
parser.add_argument(
"-y", "--yes", help="use assumed node bin directory.", action="store_true"
)
def runcmd(cmd): def runcmd(cmd):
if os.name == "nt": if os.name == "nt":
return subprocess.check_output(cmd, shell=True) 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") out = runcmd("npm bin")
try: try:
node_bin = Path(out[0].decode('utf-8').rstrip()) node_bin = Path(out[0].decode("utf-8").rstrip())
except: except:
node_bin = Path(out.decode('utf-8').rstrip()) node_bin = Path(out.decode("utf-8").rstrip())
print(f"assuming npm bin directory \"{node_bin}\". Is this correct?") args = parser.parse_args()
if not args.yes:
print(f'assuming npm bin directory "{node_bin}". Is this correct?')
if input("[yY/nN]: ").lower() == "n": 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}\"") print(f'this? "{node_bin}"')
if input("[yY/nN]: ").lower() == "n": if input("[yY/nN]: ").lower() == "n":
node_bin = input("input bin directory: ") 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"
css = bsv / f'{bsv.name}-jf.css' css = bsv / f"{bsv.name}-jf.css"
min_css = bsv.parents[1] / 'data' / 'static' / f'{bsv.name}-jf.css' min_css = bsv.parents[1] / "data" / "static" / f"{bsv.name}-jf.css"
with open(css, 'w') as f: with open(css, "w") as f:
f.write(sass.compile(filename=str(scss.resolve()), f.write(
output_style='expanded', sass.compile(
precision=6)) filename=str(scss.resolve()), output_style="expanded", precision=6
)
)
if css.exists(): if css.exists():
print(f'{bsv.name}: Compiled.') print(f"{bsv.name}: Compiled.")
# postcss only excepts forwards slashes? weird. # postcss only excepts forwards slashes? weird.
cssPath = str(css.resolve()) cssPath = str(css.resolve())
if os.name == 'nt': if os.name == "nt":
cssPath = cssPath.replace('\\', '/') cssPath = cssPath.replace("\\", "/")
runcmd(f'{str((node_bin / "postcss").resolve())} {cssPath} --replace --use autoprefixer') runcmd(
print(f'{bsv.name}: Prefixed.') f'{str((node_bin / "postcss").resolve())} {cssPath} --replace --use autoprefixer'
runcmd(f'{str((node_bin / "cleancss").resolve())} --level 1 --format breakWith=lf --output {str(min_css.resolve())} {str(css.resolve())}') )
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(): if min_css.exists():
print(f'{bsv.name}: Minified and copied to {str(min_css.resolve())}.') print(f"{bsv.name}: Minified and copied to {str(min_css.resolve())}.")
for v in [('bootstrap', 'bs5'), ('bootstrap4', 'bs4')]:
new_path = str((local_path.parent / 'data' / 'static' / (v[1] + '.css')).resolve())
shutil.copy(str((local_path.parent / 'node_modules' / v[0] / 'dist' / 'css' / 'bootstrap.min.css').resolve()),
new_path)
print(f'Copied {v[1]} to {new_path}')
for v in [("bootstrap", "bs5"), ("bootstrap4", "bs4")]:
new_path = str((local_path.parent / "data" / "static" / (v[1] + ".css")).resolve())
shutil.copy(
str(
(
local_path.parent
/ "node_modules"
/ v[0]
/ "dist"
/ "css"
/ "bootstrap.min.css"
).resolve()
),
new_path,
)
print(f"Copied {v[1]} to {new_path}")