11 from minify
import (html_minifier
, rcssmin
, rjsmin
)
14 return '%s (%s) %s' % (env
.get('GIT_VERSION'), env
.get('GIT_SHA'), env
.get('REG_DOMAIN'))
16 def build_version(out
, env
):
17 out
.write('const char *VERSION = "%s";\n\n' % get_version(env
))
20 """Compress data in one shot and return the compressed string.
21 Optional argument is the compression level, in range of 0-9.
24 with gzip
.GzipFile(fileobj
=buf
, mode
='wb', compresslevel
=9, mtime
=0.0) as f
:
28 def build_html(mainfile
, var
, out
, env
):
29 with
open('html/%s' % mainfile
, 'r') as file:
31 if mainfile
.endswith('.html'):
32 data
= html_minifier
.html_minify(data
).replace('@VERSION@', get_version(env
)).replace('@PLATFORM@', re
.sub("_via_.*", "", env
['PIOENV']))
33 if mainfile
.endswith('.css'):
34 data
= rcssmin
.cssmin(data
)
35 if mainfile
.endswith('.js'):
36 data
= rjsmin
.jsmin(data
)
37 out
.write('static const char PROGMEM %s[] = {\n' % var
)
38 out
.write(','.join("0x{:02x}".format(c
) for c
in compress(data
.encode('utf-8'))))
41 def build_common(env
, mainfile
):
42 fd
, path
= tempfile
.mkstemp()
44 with os
.fdopen(fd
, 'w') as out
:
45 build_version(out
, env
)
46 build_html(mainfile
, "INDEX_HTML", out
, env
)
47 build_html("scan.js", "SCAN_JS", out
, env
)
48 build_html("main.css", "CSS", out
, env
)
49 build_html("logo.svg", "FLAG", out
, env
)
51 if not os
.path
.exists("include/WebContent.h") or not filecmp
.cmp(path
, "include/WebContent.h"):
52 shutil
.copyfile(path
, "include/WebContent.h")
55 platform
= env
.get('PIOPLATFORM', '')
57 if platform
in ['espressif8266']:
58 build_common(env
, "rx_index.html")
59 elif platform
in ['espressif32']:
60 build_common(env
, "tx_index.html")