2022-07-08 09:22:35 +01:00
|
|
|
import os
|
2022-08-03 14:10:32 +02:00
|
|
|
import warnings
|
2023-02-01 17:19:56 +01:00
|
|
|
from pathlib import Path
|
2022-07-08 09:22:35 +01:00
|
|
|
|
2023-02-01 17:19:56 +01:00
|
|
|
LNBITS_PATH = Path("lnbits").absolute()
|
2022-07-08 09:22:35 +01:00
|
|
|
|
2023-03-31 12:46:24 +02:00
|
|
|
# from ..lnbits.helpers import vendored_js, vendored_css
|
|
|
|
vendored_js = [
|
|
|
|
"/static/vendor/moment.js",
|
|
|
|
"/static/vendor/underscore.js",
|
|
|
|
"/static/vendor/axios.js",
|
|
|
|
"/static/vendor/vue.js",
|
|
|
|
"/static/vendor/vue-router.js",
|
|
|
|
"/static/vendor/vue-qrcode-reader.browser.js",
|
|
|
|
"/static/vendor/vue-qrcode.js",
|
|
|
|
"/static/vendor/vuex.js",
|
|
|
|
"/static/vendor/quasar.ie.polyfills.umd.min.js",
|
|
|
|
"/static/vendor/quasar.umd.js",
|
|
|
|
"/static/vendor/Chart.bundle.js",
|
|
|
|
]
|
|
|
|
|
|
|
|
vendored_css = [
|
|
|
|
"/static/vendor/quasar.css",
|
|
|
|
"/static/vendor/Chart.css",
|
|
|
|
"/static/vendor/vue-qrcode-reader.css",
|
|
|
|
]
|
2022-07-08 09:22:35 +01:00
|
|
|
|
|
|
|
|
|
|
|
def url_for_vendored(abspath: str) -> str:
|
2023-04-03 15:34:17 +02:00
|
|
|
return f"/{os.path.relpath(abspath, LNBITS_PATH)}"
|
2022-07-08 09:22:35 +01:00
|
|
|
|
2022-08-03 13:16:50 +02:00
|
|
|
|
2022-07-08 09:22:35 +01:00
|
|
|
def transpile_scss():
|
|
|
|
with warnings.catch_warnings():
|
|
|
|
warnings.simplefilter("ignore")
|
|
|
|
from scss.compiler import compile_string # type: ignore
|
|
|
|
|
|
|
|
with open(os.path.join(LNBITS_PATH, "static/scss/base.scss")) as scss:
|
|
|
|
with open(os.path.join(LNBITS_PATH, "static/css/base.css"), "w") as css:
|
|
|
|
css.write(compile_string(scss.read()))
|
|
|
|
|
2022-08-03 13:16:50 +02:00
|
|
|
|
2022-07-08 09:22:35 +01:00
|
|
|
def bundle_vendored():
|
2023-03-31 12:46:24 +02:00
|
|
|
for files, outputpath in [
|
|
|
|
(vendored_js, os.path.join(LNBITS_PATH, "static/bundle.js")),
|
|
|
|
(vendored_css, os.path.join(LNBITS_PATH, "static/bundle.css")),
|
2022-07-08 09:22:35 +01:00
|
|
|
]:
|
|
|
|
output = ""
|
2023-03-31 12:46:24 +02:00
|
|
|
for path in files:
|
|
|
|
with open(f"{LNBITS_PATH}{path}") as f:
|
|
|
|
output += f.read() + ";\n"
|
2022-07-08 09:22:35 +01:00
|
|
|
with open(outputpath, "w") as f:
|
|
|
|
f.write(output)
|
|
|
|
|
|
|
|
|
|
|
|
def build():
|
|
|
|
transpile_scss()
|
|
|
|
bundle_vendored()
|
|
|
|
|
|
|
|
|
2022-08-03 13:16:50 +02:00
|
|
|
if __name__ == "__main__":
|
|
|
|
build()
|