Skip to content

Commit

Permalink
Added function to set magma .env when using build flag
Browse files Browse the repository at this point in the history
  • Loading branch information
djlawren committed May 12, 2024
1 parent 97e22ee commit 1302d33
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions server.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
from app.utility.config_generator import ensure_local_config


MAGMA_PATH = "./plugins/magma"


def setup_logger(level=logging.DEBUG):
format = "%(message)s"
datefmt = "%Y-%m-%d %H:%M:%S"
Expand Down Expand Up @@ -139,11 +142,19 @@ async def enable_cors(request, response):

async def start_vue_dev_server():
await asyncio.create_subprocess_shell(
"npm run dev", stdout=sys.stdout, stderr=sys.stderr, cwd="./plugins/magma/"
"npm run dev", stdout=sys.stdout, stderr=sys.stderr, cwd=MAGMA_PATH
)
logging.info("VueJS development server is live.")


def configure_magma_env_file():
logging.info("Setting VueJS environment file.")
host = BaseWorld.get_config("host")
port = BaseWorld.get_config("port")
with open("%s/.env" % MAGMA_PATH, "w") as fp:
fp.write("VITE_CALDERA_URL=http://%s:%s" % (host, port))


def _get_parser():

def list_str(values):
Expand Down Expand Up @@ -251,19 +262,20 @@ def list_str(values):
app_svc.register_subapp("/api/v2", app.api.v2.make_app(app_svc.get_services()))
init_swagger_documentation(app_svc.application)
if args.uiDevHost:
if not os.path.exists("./plugins/magma/dist"):
if not os.path.exists("%s/dist" % MAGMA_PATH):
logging.info("Building VueJS front-end.")
subprocess.run(["npm", "run", "build"], cwd="plugins/magma", check=True)
subprocess.run(["npm", "run", "build"], cwd=MAGMA_PATH, check=True)
logging.info("VueJS front-end build complete.")
app_svc.application.on_response_prepare.append(enable_cors)

if args.build:
configure_magma_env_file()
logging.info("Building VueJS front-end.")
subprocess.run(["npm", "install"], cwd="plugins/magma", check=True)
subprocess.run(["npm", "run", "build"], cwd="plugins/magma", check=True)
subprocess.run(["npm", "install"], cwd=MAGMA_PATH, check=True)
subprocess.run(["npm", "run", "build"], cwd=MAGMA_PATH, check=True)
logging.info("VueJS front-end build complete.")
else:
if not os.path.exists("./plugins/magma/dist"):
if not os.path.exists("%s/dist" % MAGMA_PATH):
logging.warning(
"[bright_yellow]Built Caldera v5 Vue components not detected, and `--build` flag not supplied."
" If attempting to start Caldera v5 for the first time, the `--build` flag must be"
Expand Down

0 comments on commit 1302d33

Please sign in to comment.