From 9e9f46d97b6869ddab784fc9dfd1f845121718e8 Mon Sep 17 00:00:00 2001 From: Harvey Tindall Date: Mon, 26 Aug 2024 16:55:08 +0100 Subject: [PATCH] build: remove compile_mjml script, no python! if I had taken a second to actually read the documentation, i'd have realized the mjml command can process a bunch of files at once. On my machine, cuts time down from ~800ms to ~500ms. While there are still some scripts using python, none are needed to build the software anymore, so no python build deps! --- Makefile | 14 +++-------- config/README.md | 4 ---- config/README.txt | 1 + scripts/compile_mjml.py | 52 ----------------------------------------- 4 files changed, 4 insertions(+), 67 deletions(-) delete mode 100644 config/README.md create mode 100644 config/README.txt delete mode 100755 scripts/compile_mjml.py diff --git a/Makefile b/Makefile index 3a1e46f..dfcef82 100644 --- a/Makefile +++ b/Makefile @@ -108,7 +108,6 @@ CONFIG_DEFAULT = $(DATA)/config-default.ini # $(CONFIG_DESCRIPTION) &: $(CONFIG_BASE) # $(info Fixing config-base) # -mkdir -p $(DATA) -# python3 scripts/enumerate_config.py -i config/config-base.json -o $(DATA)/config-base.json $(DATA): mkdir -p $(DATA) @@ -128,7 +127,9 @@ EMAIL_ALL = $(EMAIL_HTML) $(EMAIL_TXT) EMAIL_TARGET = mail/confirmation.html $(EMAIL_TARGET): $(EMAIL_SRC_MJML) $(EMAIL_SRC_TXT) $(info Generating email html) - python3 scripts/compile_mjml.py -o $(DATA)/ + npx mjml mail/*.mjml -o $(DATA)/ + $(info Copying plaintext mail) + cp mail/*.txt $(DATA)/ TYPESCRIPT_FULLSRC = $(shell find ts/ -type f -name "*.ts") TYPESCRIPT_SRC = $(wildcard ts/*.ts) @@ -228,15 +229,6 @@ compile: $(GO_TARGET) compress: upx --lzma build/jfa-go -# internal-files: -# python3 scripts/embed.py internal -# -# external-files: -# python3 scripts/embed.py external -# -mkdir -p build -# $(info copying internal data into build/) -# cp -r data build/ - install: cp -r build $(DESTDIR)/jfa-go diff --git a/config/README.md b/config/README.md deleted file mode 100644 index b8fba25..0000000 --- a/config/README.md +++ /dev/null @@ -1,4 +0,0 @@ -### fixconfig - -Python's `json` library retains the order of data in a JSON file, which meant settings sent to the web page would be in the right order. Go's `encoding/json` and maps do not retain order, so `enumerate/enumerate_config.py` opens the json file, and for each section, adds an "order" array which tells the web page in which order to display settings. -Specify the input and output files with `-i` and `-o` respectively. diff --git a/config/README.txt b/config/README.txt new file mode 100644 index 0000000..c650e62 --- /dev/null +++ b/config/README.txt @@ -0,0 +1 @@ +The two python scripts here, `config-json-to-new-yaml.py` and `gen-rough-schema.py` were used to convert the old format, which was stored in a JSON file, to the new format in YAML. The latter script is used to get the possible values for settings and sections, so they could be properly defined in common/config.go. diff --git a/scripts/compile_mjml.py b/scripts/compile_mjml.py deleted file mode 100755 index fc5e09d..0000000 --- a/scripts/compile_mjml.py +++ /dev/null @@ -1,52 +0,0 @@ -import subprocess -import shutil -import os -import argparse -from pathlib import Path -from multiprocessing import Process - -parser = argparse.ArgumentParser() -parser.add_argument("-o", "--output", help="output directory for .html and .txt files") - -args = parser.parse_args() - -def runcmd(cmd): - if os.name == "nt": - return subprocess.check_output(cmd, shell=True) - with subprocess.Popen(cmd.split(), stdout=subprocess.PIPE) as proc: - return proc.communicate() - -def compile(mjml: Path): - fname = mjml.with_suffix(".html") - runcmd(f"npx mjml {str(mjml)} -o {str(fname)}") - if fname.is_file(): - print(f"Compiled {mjml.name}") - -local_path = Path("mail") - -threads = [] - -for mjml in [f for f in local_path.iterdir() if f.is_file() and "mjml" in f.suffix]: - p = Process(target=compile, args=(mjml,)) - p.start() - threads.append(p) - -for thread in threads: - thread.join() - -html = [f for f in local_path.iterdir() if f.is_file() and "html" in f.suffix] - -output = Path(args.output) # local_path.parent / "build" / "data" -output.mkdir(parents=True, exist_ok=True) - -for f in html: - shutil.copy(str(f), str(output / f.name)) - print(f"Copied {f.name} to {str(output / f.name)}") - txtfile = f.with_suffix(".txt") - if txtfile.is_file(): - shutil.copy(str(txtfile), str(output / txtfile.name)) - print(f"Copied {txtfile.name} to {str(output / txtfile.name)}") - else: - print( - f"Warning: {txtfile.name} does not exist. Text versions of emails should be supplied." - )