make.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #!/bin/python
  2. from pathlib import Path
  3. from json import loads
  4. from shutil import rmtree
  5. from shutil import copytree
  6. from maketool import sass_compiler
  7. from maketool import esbuild_compiler
  8. from maketool import render
  9. from maketool import script
  10. from maketool import link
  11. root = Path(__file__).absolute().parent
  12. source = root / Path("./")
  13. build = root / Path("build/")
  14. styles = source / Path("styles/")
  15. scripts = source / Path("scripts/")
  16. scripts_loader = scripts / Path("core.js")
  17. theme_loader = styles / Path("core.sass")
  18. full_bundle = scripts / Path("bundle.js")
  19. script_bundle = build / Path("pack.js")
  20. theme_bundle = build / Path("pack.css")
  21. bundle_tmp_output = build / Path("bundle.tmp.js")
  22. bundle_output = build / Path("bundle.js")
  23. if build.exists():
  24. rmtree(build)
  25. build.mkdir()
  26. sass_compiler(theme_loader).build(theme_bundle)
  27. esbuild_compiler(scripts_loader).build(script_bundle)
  28. with theme_bundle.open() as style:
  29. with script_bundle.open() as script:
  30. script = script.read().replace("\"", "\\\"").replace("`", "\\`")
  31. style = style.read().replace("\"", "\\\"").replace("`", "\\`")
  32. rendering = render(full_bundle)
  33. rendering.add("style", style)
  34. rendering.add("script", script)
  35. with bundle_tmp_output.open("w") as output:
  36. output.write(rendering.finalize())
  37. esbuild_compiler(bundle_tmp_output).build(bundle_output)