diff options
| author | Marin Ivanov <[email protected]> | 2024-08-21 04:00:28 +0300 |
|---|---|---|
| committer | Marin Ivanov <[email protected]> | 2024-08-21 04:00:28 +0300 |
| commit | 2c417fb8398eda685c5dd1f7b1bec811757dc562 (patch) | |
| tree | b2abfbeeaeed5f284629e29d0e991e3d4445e5f2 | |
| parent | 8354a7fae28e0bcc7a0eb1b6337f6da0d0769c94 (diff) | |
make build system
| -rw-r--r-- | Makefile | 9 | ||||
| -rw-r--r-- | build.py | 28 | ||||
| -rw-r--r-- | toml2json.py | 4 |
3 files changed, 32 insertions, 9 deletions
@@ -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('<link rel="stylesheet" href="style.css">', f'<style>{files["main.css"]}</style>') +index = index.replace('<script src="config.js"></script>', '') +index = index.replace('<script src="ka.js"></script>', '') +index = index.replace('<script src="app.js"></script>', f'<script>config={configjson};{files["main.js"]}</script>') + +data = zlib.compress(index.encode('utf-8')) +out = ', '.join(hex(x) for x in data) +print(f""" +#include <avr/pgmspace.h> +#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=(',',':')) |
