2023-11-07 20:25:54 +00:00
|
|
|
Import("env")
|
2023-11-17 18:28:40 +00:00
|
|
|
import os
|
|
|
|
import gzip
|
|
|
|
from shutil import copyfileobj, rmtree
|
|
|
|
from pathlib import Path
|
2024-05-18 23:32:45 +00:00
|
|
|
import subprocess
|
|
|
|
|
|
|
|
revision = (
|
|
|
|
subprocess.check_output(["git", "rev-parse", "HEAD"])
|
|
|
|
.strip()
|
|
|
|
.decode("utf-8")
|
|
|
|
)
|
2023-11-17 18:28:40 +00:00
|
|
|
|
|
|
|
def gzip_file(input_file, output_file):
|
|
|
|
with open(input_file, 'rb') as f_in:
|
|
|
|
with gzip.open(output_file, 'wb') as f_out:
|
|
|
|
copyfileobj(f_in, f_out)
|
|
|
|
|
|
|
|
def process_directory(input_dir, output_dir):
|
2023-11-17 19:14:28 +00:00
|
|
|
if os.path.exists(output_dir):
|
|
|
|
rmtree(output_dir)
|
2023-11-17 18:28:40 +00:00
|
|
|
for root, dirs, files in os.walk(input_dir):
|
|
|
|
relative_path = os.path.relpath(root, input_dir)
|
|
|
|
output_root = os.path.join(output_dir, relative_path)
|
|
|
|
|
|
|
|
Path(output_root).mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
|
|
for file in files:
|
|
|
|
# if file.endswith(('.html', '.css', '.js')):
|
|
|
|
input_file_path = os.path.join(root, file)
|
|
|
|
output_file_path = os.path.join(output_root, file + '.gz')
|
|
|
|
gzip_file(input_file_path, output_file_path)
|
|
|
|
print(f'Compressed: {input_file_path} -> {output_file_path}')
|
2024-05-18 23:32:45 +00:00
|
|
|
file_path = os.path.join(output_dir, "fs_hash.txt")
|
|
|
|
with open(file_path, "w") as file:
|
|
|
|
file.write(revision)
|
2023-11-17 18:28:40 +00:00
|
|
|
|
2023-11-07 20:25:54 +00:00
|
|
|
|
|
|
|
# Build web interface before building FS
|
|
|
|
def before_buildfs(source, target, env):
|
2023-11-30 19:58:37 +00:00
|
|
|
env.Execute("cd data && yarn && yarn postinstall && yarn build")
|
2023-11-17 18:28:40 +00:00
|
|
|
input_directory = 'data/dist'
|
|
|
|
output_directory = 'data/build_gz'
|
|
|
|
process_directory(input_directory, output_directory)
|
2023-11-07 20:25:54 +00:00
|
|
|
|
2023-11-30 19:58:37 +00:00
|
|
|
os.environ["PUBLIC_BASE_URL"] = ""
|
2023-11-08 11:18:59 +00:00
|
|
|
env.AddPreAction("$BUILD_DIR/littlefs.bin", before_buildfs)
|