From 2c417fb8398eda685c5dd1f7b1bec811757dc562 Mon Sep 17 00:00:00 2001 From: Marin Ivanov Date: Wed, 21 Aug 2024 04:00:28 +0300 Subject: make build system --- Makefile | 9 ++++----- build.py | 28 ++++++++++++++++++++++++++++ toml2json.py | 4 ---- 3 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 build.py delete mode 100644 toml2json.py diff --git a/Makefile b/Makefile index e92fc58..7526c9d 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ -all: main.js main.css config.js +all: main.css main.js +.PHONY: build main.js: ka.js app.js cat $^ | esbuild --minify --loader=js > $@ @@ -6,8 +7,6 @@ main.js: ka.js app.js main.css: style.css cat $^ | esbuild --minify --loader=css > $@ -config.js: config.toml - echo -n "config=" > $@ - python3 ./toml2json.py < $< >> $@ - echo -n ";" >> $@ +build: config.toml main.js main.css + python3 ./build.py diff --git a/build.py b/build.py new file mode 100644 index 0000000..e0b0134 --- /dev/null +++ b/build.py @@ -0,0 +1,28 @@ +import sys, json, tomllib, zlib + +inputs = ["config.toml", "main.css", "main.js", "index.html"] +files = {} +for name in inputs: + with open(name,'r') as f: + files[name] = f.read() + +config = tomllib.loads(files["config.toml"]) +configjson = json.dumps(config, separators=(',',':')) + +index = files["index.html"] +index = index.replace('', f'') +index = index.replace('', '') +index = index.replace('', '') +index = index.replace('', f'') + +data = zlib.compress(index.encode('utf-8')) +out = ', '.join(hex(x) for x in data) +print(f""" +#include +#include "webif-fs.h" + +const char index_html_data[] PROGMEM = {{ {out} }}; +uint16_t index_html_size = {len(data)}; +""") + + diff --git a/toml2json.py b/toml2json.py deleted file mode 100644 index 320b414..0000000 --- a/toml2json.py +++ /dev/null @@ -1,4 +0,0 @@ -import sys, json, tomllib - -data = tomllib.load(open(0,'rb',closefd=False)) -json.dump(data, sys.stdout, separators=(',',':')) -- cgit v1.2.3