Skip to content

Commit

Permalink
Publish tool shed frontend to npm.
Browse files Browse the repository at this point in the history
  • Loading branch information
jmchilton committed Oct 25, 2023
1 parent 4fcf3b5 commit 1424047
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
27 changes: 23 additions & 4 deletions lib/tool_shed/webapp/fast_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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", None) 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):
Expand All @@ -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"""<script type="module" src="/src/{shed_entry_point}"></script>""",
f"""<script type="module" src="http://localhost:{TOOL_SHED_VITE_PORT}/{vite_runtime}"></script><script type="module" src="http://localhost:{TOOL_SHED_VITE_PORT}/src/{shed_entry_point}"></script>""",
)
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
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions lib/tool_shed/webapp/frontend/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
19 changes: 19 additions & 0 deletions lib/tool_shed/webapp/package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit 1424047

Please sign in to comment.