#!/bin/python from pathlib import Path from json import loads from shutil import rmtree from shutil import copytree from maketool import sass_compiler from maketool import esbuild_compiler from maketool import render from maketool import script from maketool import link root = Path(__file__).absolute().parent source = root / Path("./") build = root / Path("build/") styles = source / Path("styles/") scripts = source / Path("scripts/") scripts_loader = scripts / Path("core.js") theme_loader = styles / Path("core.sass") full_bundle = scripts / Path("bundle.js") script_bundle = build / Path("pack.js") theme_bundle = build / Path("pack.css") bundle_tmp_output = build / Path("bundle.tmp.js") bundle_output = build / Path("bundle.js") if build.exists(): rmtree(build) build.mkdir() sass_compiler(theme_loader).build(theme_bundle) esbuild_compiler(scripts_loader).build(script_bundle) with theme_bundle.open() as style: with script_bundle.open() as script: script = script.read().replace("\"", "\\\"").replace("`", "\\`") style = style.read().replace("\"", "\\\"").replace("`", "\\`") rendering = render(full_bundle) rendering.add("style", style) rendering.add("script", script) with bundle_tmp_output.open("w") as output: output.write(rendering.finalize()) esbuild_compiler(bundle_tmp_output).build(bundle_output)