-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into fixtabbing-breaking
- Loading branch information
Showing
12 changed files
with
1,159 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# syntax=docker/dockerfile:1 | ||
ARG VOLTO_VERSION | ||
FROM plone/frontend-builder:${VOLTO_VERSION} as builder | ||
|
||
ARG ADDON_NAME | ||
ARG ADDON_PATH | ||
|
||
ENV THEME='@kitconcept/volto-light-theme' | ||
|
||
# Copy helper.py as /setupAddon | ||
COPY dockerfiles/helper.py /setupAddon | ||
|
||
# Copy addon code | ||
COPY --chown=node:node ./packages/${ADDON_PATH} /app/src/addons/${ADDON_PATH}/ | ||
|
||
# Install | ||
RUN <<EOT | ||
set -e | ||
/setupAddon | ||
yarn install --network-timeout 1000000 | ||
yarn build | ||
rm -rf cache omelette .yarn/cache | ||
EOT | ||
|
||
FROM plone/frontend-prod-config:${VOLTO_VERSION} | ||
|
||
LABEL maintainer="kitconcept GmbH <[email protected]>" \ | ||
org.label-schema.name="ghcr.io/kitconcept/lighttheme" \ | ||
org.label-schema.description="Volto project with @kitconcept/volto-light-theme" \ | ||
org.label-schema.vendor="kitconcept GmbH" | ||
|
||
COPY --from=builder /app/ /app/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
#!/usr/bin/python3 | ||
"""Addon support for Volto.""" | ||
from pathlib import Path | ||
from typing import Tuple | ||
|
||
import json | ||
import logging | ||
import os | ||
|
||
|
||
logger = logging.getLogger("Volto Helper") | ||
|
||
|
||
def get_jsconfig_path(): | ||
primary_path = (APP_FOLDER / "tsconfig.json").resolve() | ||
fallback_path = (APP_FOLDER / "jsconfig.json").resolve() | ||
|
||
if primary_path.exists(): | ||
return primary_path | ||
elif fallback_path.exists(): | ||
return fallback_path | ||
else: | ||
return None | ||
|
||
|
||
APP_FOLDER = Path("/app").resolve() | ||
PACKAGE_JSON_PATH = (APP_FOLDER / "package.json").resolve() | ||
JSCONFIG_PATH = get_jsconfig_path() | ||
VOLTOCONFIGPATH = (APP_FOLDER / "volto.config.js").resolve() | ||
|
||
|
||
ADDON_NAME = os.environ.get("ADDON_NAME", "") | ||
ADDITIONAL_ADDONS = os.environ.get("ADDITIONAL_ADDONS", "") | ||
|
||
|
||
def add_packages_to_package_json(config: dict, packages: dict) -> dict: | ||
"""Add addons to the main `package.json`.""" | ||
addons = config.get("addons", []) | ||
workspaces = config.get("workspaces", []) | ||
for pkg_name, pkg_path in packages.items(): | ||
if not VOLTOCONFIGPATH.exists(): | ||
addons.append(pkg_name) | ||
workspace_path = pkg_path.replace("/src", "") | ||
workspaces.append(f"src/{workspace_path}") | ||
config["addons"] = addons | ||
config["workspaces"] = workspaces | ||
return config | ||
|
||
|
||
def parse_jsonconfig(config: dict) -> dict: | ||
"""Parse existing `jsconfig.json`.""" | ||
packages = {} | ||
config_paths = config.get("compilerOptions", {}).get("paths", {}) | ||
for pkg_name, pkg_path in config_paths.items(): | ||
if isinstance(pkg_path, list): | ||
packages[pkg_name] = pkg_path[0] | ||
return packages | ||
|
||
|
||
def parse_addon_name(addon_name: str) -> Tuple[str, str]: | ||
"""Parse the addon name and return also its probable path.""" | ||
if addon_name.startswith("@"): | ||
_, path = addon_name.split("/") | ||
return addon_name, path | ||
return addon_name, addon_name | ||
|
||
|
||
def addon_to_package_json(config: dict, addon_name: str, addon_path: str) -> dict: | ||
"""Add a single addon to main `package.json`.""" | ||
project_addons = config["addons"] | ||
project_dependencies = config["dependencies"] | ||
# Process package.json for the addon | ||
workspace_path = f"src/addons/{addon_path}" | ||
addon_path = (APP_FOLDER / workspace_path).resolve() | ||
addon_config = json.load(open(addon_path / "package.json")) | ||
# Process peerDependencies | ||
peer_dependencies = addon_config.get("peerDependencies", {}) | ||
for dependency_name, version in peer_dependencies.items(): | ||
if dependency_name in project_dependencies: | ||
continue | ||
project_dependencies[dependency_name] = version | ||
# Process peerAddons | ||
peer_addons = addon_config.get("peerAddons", []) | ||
for name in peer_addons: | ||
if name in project_addons: | ||
continue | ||
project_addons.append(name) | ||
# Add our addon to addons and to workspaces | ||
project_addons.append(addon_name) | ||
workspaces = config.get("workspaces", []) | ||
workspaces.append(workspace_path) | ||
|
||
config["addons"] = project_addons | ||
config["dependencies"] = project_dependencies | ||
config["workspaces"] = workspaces | ||
return config | ||
|
||
|
||
def addon_to_jsconfig_json(config: dict, addon_name: str, addon_path: str) -> dict: | ||
"""Add a single addon to `jsconfig.json`.""" | ||
if "compilerOptions" not in config: | ||
config["compilerOptions"] = {} | ||
if "paths" not in config: | ||
config["compilerOptions"]["paths"] = {} | ||
|
||
config["compilerOptions"]["paths"][addon_name] = [f"addons/{addon_path}/src"] | ||
return config | ||
|
||
|
||
if ADDON_NAME: | ||
logger.info("Processing the ADDON_NAME variable.") | ||
SETTINGS = ( | ||
(addon_to_package_json, PACKAGE_JSON_PATH), | ||
(addon_to_jsconfig_json, JSCONFIG_PATH), | ||
) | ||
addon_name, addon_path = parse_addon_name(ADDON_NAME) | ||
for func, path in SETTINGS: | ||
data = func(json.load(open(path)), addon_name=addon_name, addon_path=addon_path) | ||
json.dump(data, open(path, "w"), indent=2) | ||
else: | ||
packages = {} | ||
if JSCONFIG_PATH.exists(): | ||
packages = parse_jsonconfig(json.load(open(JSCONFIG_PATH))) | ||
|
||
if not packages: | ||
logger.warning("Existing jsconfig.json does not contain packages.") | ||
else: | ||
logger.info("Processing existing jsconfig.json.") | ||
package_json = json.load(open(PACKAGE_JSON_PATH)) | ||
# Process package_json | ||
package_json = add_packages_to_package_json(package_json, packages) | ||
json.dump(package_json, open(PACKAGE_JSON_PATH, "w"), indent=2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.