diff --git a/.gitignore b/.gitignore index c29e72f47..516579db6 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,5 @@ platformio-device-monitor*.log logs/device-monitor*.log platformio_override.ini +webapp_dist/ .DS_Store diff --git a/pio-scripts/compile_webapp.py b/pio-scripts/compile_webapp.py new file mode 100644 index 000000000..ace042bf6 --- /dev/null +++ b/pio-scripts/compile_webapp.py @@ -0,0 +1,65 @@ +import os +import hashlib +import pickle +import subprocess + +def check_files(directories, filepaths, hash_file): + old_file_hashes = {} + file_hashes = {} + + for directory in directories: + for root, dirs, filenames in os.walk(directory): + for file in filenames: + filepaths.append(os.path.join(root, file)) + + for file_path in filepaths: + with open(file_path, 'rb') as f: + file_data = f.read() + file_hashes[file_path] = hashlib.md5(file_data).hexdigest() + + if os.path.exists(hash_file): + with open(hash_file, 'rb') as f: + old_file_hashes = pickle.load(f) + + update = False + for file_path, file_hash in file_hashes.items(): + if file_path not in old_file_hashes or old_file_hashes[file_path] != file_hash: + update = True + break + + if not update: + print("webapp artifacts should be up-to-date") + return + + print("compiling webapp (hang on, this can take a while and there might be little output)...") + + try: + # if these commands fail, an exception will prevent us from + # persisting the current hashes => commands will be executed again + subprocess.run(["yarn", "--cwd", "webapp", "install", "--frozen-lockfile"], + check=True) + + subprocess.run(["yarn", "--cwd", "webapp", "build"], check=True) + + except FileNotFoundError: + raise Exception("it seems 'yarn' is not installed/available on your system") + + with open(hash_file, 'wb') as f: + pickle.dump(file_hashes, f) + +def main(): + if os.getenv('GITHUB_ACTIONS') == 'true': + print("INFO: not testing for up-to-date webapp artifacts when running as Github action") + return 0 + + print("INFO: testing for up-to-date webapp artifacts") + + directories = ["webapp/src/", "webapp/public/"] + files = ["webapp/index.html", "webapp/tsconfig.config.json", + "webapp/tsconfig.json", "webapp/vite.config.ts", + "webapp/yarn.lock"] + hash_file = "webapp_dist/.hashes.pkl" + + check_files(directories, files, hash_file) + +main() diff --git a/platformio.ini b/platformio.ini index f9435984c..b7917a10e 100644 --- a/platformio.ini +++ b/platformio.ini @@ -50,6 +50,7 @@ lib_deps = plerup/EspSoftwareSerial @ ^8.2.0 extra_scripts = + pre:pio-scripts/compile_webapp.py pre:pio-scripts/auto_firmware_version.py pre:pio-scripts/patch_apply.py post:pio-scripts/create_factory_bin.py diff --git a/webapp_dist/favicon.ico b/webapp_dist/favicon.ico deleted file mode 100644 index 68e73986d..000000000 Binary files a/webapp_dist/favicon.ico and /dev/null differ diff --git a/webapp_dist/favicon.png b/webapp_dist/favicon.png deleted file mode 100644 index 278aac84f..000000000 Binary files a/webapp_dist/favicon.png and /dev/null differ diff --git a/webapp_dist/index.html.gz b/webapp_dist/index.html.gz deleted file mode 100644 index be84fc7db..000000000 Binary files a/webapp_dist/index.html.gz and /dev/null differ diff --git a/webapp_dist/js/app.js.gz b/webapp_dist/js/app.js.gz deleted file mode 100644 index 42d83ecb0..000000000 Binary files a/webapp_dist/js/app.js.gz and /dev/null differ diff --git a/webapp_dist/site.webmanifest b/webapp_dist/site.webmanifest deleted file mode 100644 index 3be246091..000000000 --- a/webapp_dist/site.webmanifest +++ /dev/null @@ -1,13 +0,0 @@ -{ - "name": "OpenDTU", - "short_name": "OpenDTU", - "display": "standalone", - "orientation": "portrait", - "icons": [ - { - "src": "/favicon.png", - "sizes": "144x144", - "type": "image/png" - } - ] -} \ No newline at end of file diff --git a/webapp_dist/zones.json.gz b/webapp_dist/zones.json.gz deleted file mode 100644 index 02f82db68..000000000 Binary files a/webapp_dist/zones.json.gz and /dev/null differ