From aea795769a0cc658ea631e5602875dcf20cb753f Mon Sep 17 00:00:00 2001 From: John Chilton Date: Wed, 25 Oct 2023 11:53:32 -0400 Subject: [PATCH] Publish tool shed frontend to npm. --- lib/tool_shed/webapp/fast_app.py | 27 ++++++++++++++++++---- lib/tool_shed/webapp/frontend/package.json | 7 ++++-- lib/tool_shed/webapp/package.json | 19 +++++++++++++++ 3 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 lib/tool_shed/webapp/package.json diff --git a/lib/tool_shed/webapp/fast_app.py b/lib/tool_shed/webapp/fast_app.py index 18af5dcb7708..d4429255017e 100644 --- a/lib/tool_shed/webapp/fast_app.py +++ b/lib/tool_shed/webapp/fast_app.py @@ -64,9 +64,26 @@ # Start tool shed with: # TOOL_SHED_VITE_PORT=4040 TOOL_SHED_API_VERSION=v2 ./run_tool_shed.sh TOOL_SHED_VITE_PORT: Optional[str] = os.environ.get("TOOL_SHED_VITE_PORT", None) +TOOL_SHED_FRONTEND_TARGET: str = os.environ.get("TOOL_SHED_FRONTEND_TARGET") or "auto" # auto, src, or node TOOL_SHED_USE_HMR: bool = TOOL_SHED_VITE_PORT is not None -FRONTEND = Path(__file__).parent.resolve() / "frontend" +WEBAPP_DIR = Path(__file__).parent.resolve() +FRONTEND = WEBAPP_DIR / "frontend" FRONTEND_DIST = FRONTEND / "dist" +INSTALLED_FRONTEND = WEBAPP_DIR / "node_modules" / "@galaxyproject" / "tool-shed-frontend" / "dist" +INDEX_FILENAME = "index.html" + + +def find_frontend_target() -> Path: + src_target = FRONTEND_DIST + node_target = INSTALLED_FRONTEND + if TOOL_SHED_FRONTEND_TARGET == "src": + return src_target + elif TOOL_SHED_FRONTEND_TARGET == "node": + return node_target + elif src_target.exists(): + return src_target + else: + return node_target def frontend_controller(app): @@ -75,14 +92,16 @@ def frontend_controller(app): def index(trans=Depends(get_trans)): if TOOL_SHED_USE_HMR: - index = FRONTEND / "index.html" + if TOOL_SHED_FRONTEND_TARGET != "auto": + raise Exception("Cannot configure HMR and with this frontend target.") + index = FRONTEND / INDEX_FILENAME index_html = index.read_text() index_html = index_html.replace( f"""""", f"""""", ) else: - index = FRONTEND_DIST / "index.html" + index = find_frontend_target() / INDEX_FILENAME index_html = index.read_text() ensure_valid_session(trans) cookie = trans.session_csrf_token @@ -168,7 +187,7 @@ def mount_static(directory: Path): if TOOL_SHED_USE_HMR: mount_static(FRONTEND / "node_modules") else: - mount_static(FRONTEND_DIST / "assets") + mount_static(find_frontend_target() / "assets") routes_package = "tool_shed.webapp.api" if SHED_API_VERSION == "v1" else "tool_shed.webapp.api2" include_all_package_routers(app, routes_package) diff --git a/lib/tool_shed/webapp/frontend/package.json b/lib/tool_shed/webapp/frontend/package.json index ab8b86cc6b26..0050777dadba 100644 --- a/lib/tool_shed/webapp/frontend/package.json +++ b/lib/tool_shed/webapp/frontend/package.json @@ -1,7 +1,10 @@ { - "name": "galaxy-tool-shed", + "name": "@galaxyproject/tool-shed-frontend", "license": "MIT", - "version": "0.2.0", + "version": "0.2.1", + "files": [ + "dist" + ], "scripts": { "dev": "vite --port 4040 --strict-port", "build": "vue-tsc --noEmit && vite build", diff --git a/lib/tool_shed/webapp/package.json b/lib/tool_shed/webapp/package.json new file mode 100644 index 000000000000..e131b43e9ee7 --- /dev/null +++ b/lib/tool_shed/webapp/package.json @@ -0,0 +1,19 @@ +{ + "name": "@galaxyproject/tool-shed", + "version": "1.0.0", + "description": ".. figure:: https://galaxyproject.org/images/galaxy-logos/galaxy_project_logo.jpg :alt: Galaxy Logo", + "main": "index.js", + "repository": { + "type": "git", + "url": "git+https://github.com/galaxyproject/galaxy.git" + }, + "author": "Galaxy Contributors", + "license": "MIT", + "bugs": { + "url": "https://github.com/galaxyproject/galaxy/issues" + }, + "homepage": "https://github.com/galaxyproject/galaxy#readme", + "dependencies": { + "@galaxyproject/tool-shed-frontend": "^0.2.1" + } +}