|
27 | 27 | ("PARAGON_ENABLED_THEMES", []), |
28 | 28 | # Whether Tutor should expose the compiled themes to be served (e.g. via nginx, cady or static server) |
29 | 29 | ("PARAGON_SERVE_COMPILED_THEMES", True), |
| 30 | + # Paragon Builder Docker image |
| 31 | + # This image is used to compile themes and should be built with `tutor images build paragon-builder` |
| 32 | + ("PARAGON_BUILDER_IMAGE", "paragon-builder:latest"), |
30 | 33 | ] |
31 | 34 | ) |
32 | 35 |
|
@@ -55,6 +58,22 @@ def create_paragon_folders(project_root: str) -> None: |
55 | 58 | print(f"[paragon] Created {label} folder at: {path}") |
56 | 59 |
|
57 | 60 |
|
| 61 | +######################################## |
| 62 | +# DOCKER IMAGE MANAGEMENT |
| 63 | +######################################## |
| 64 | + |
| 65 | +hooks.Filters.IMAGES_BUILD.add_items( |
| 66 | + [ |
| 67 | + ( |
| 68 | + "paragon-builder", # Image name used with 'tutor images build myservice' |
| 69 | + ("plugins", "paragon", "build", "paragon-builder"), # Path to Dockerfile |
| 70 | + "{{ PARAGON_BUILDER_IMAGE }}", # Docker image tag |
| 71 | + (), # Build arguments |
| 72 | + ), |
| 73 | + ] |
| 74 | +) |
| 75 | + |
| 76 | + |
58 | 77 | ######################################## |
59 | 78 | # TEMPLATE RENDERING |
60 | 79 | # (It is safe & recommended to leave |
@@ -92,3 +111,60 @@ def create_paragon_folders(project_root: str) -> None: |
92 | 111 | for path in glob(str(importlib_resources.files("tutorparagon") / "patches" / "*")): |
93 | 112 | with open(path, encoding="utf-8") as patch_file: |
94 | 113 | hooks.Filters.ENV_PATCHES.add_item((os.path.basename(path), patch_file.read())) |
| 114 | + |
| 115 | + |
| 116 | +######################################## |
| 117 | +# CUSTOM JOBS (a.k.a. "do-commands") |
| 118 | +######################################## |
| 119 | + |
| 120 | + |
| 121 | +@click.command() |
| 122 | +@click.option( |
| 123 | + "--source-tokens-only", |
| 124 | + is_flag=True, |
| 125 | + default=False, |
| 126 | + help="Include only source design tokens in the build.", |
| 127 | +) |
| 128 | +@click.option( |
| 129 | + "--output-token-references", |
| 130 | + is_flag=True, |
| 131 | + default=False, |
| 132 | + help="Include references for tokens with aliases to other tokens in the build output.", |
| 133 | +) |
| 134 | +@click.option("--themes", help="Comma-separated list of themes to build.") |
| 135 | +@click.option( |
| 136 | + "-v", "--verbose", is_flag=True, default=False, help="Enable verbose logging." |
| 137 | +) |
| 138 | +def build_tokens( |
| 139 | + themes: str, |
| 140 | + source_tokens_only: bool, |
| 141 | + output_token_references: bool, |
| 142 | + verbose: bool, |
| 143 | +) -> list[tuple[str, str]]: |
| 144 | + """ |
| 145 | + Build theme token files using Paragon. |
| 146 | +
|
| 147 | + Args: |
| 148 | + source_tokens_only (bool): Only source design tokens. |
| 149 | + output_token_references (bool): Output token references. |
| 150 | + themes (str): Comma-separated list of themes. |
| 151 | + verbose (bool): Verbose logging. |
| 152 | +
|
| 153 | + Returns: |
| 154 | + list[tuple[str, str]]: List of commands to run. |
| 155 | + """ |
| 156 | + args = [] |
| 157 | + if source_tokens_only: |
| 158 | + args.append("--source-tokens-only") |
| 159 | + if output_token_references: |
| 160 | + args.append("--output-token-references") |
| 161 | + if themes: |
| 162 | + args.append("--themes") |
| 163 | + args.append(themes) |
| 164 | + if verbose: |
| 165 | + args.append("--verbose") |
| 166 | + |
| 167 | + return [("paragon-builder", " ".join(args))] |
| 168 | + |
| 169 | + |
| 170 | +hooks.Filters.CLI_DO_COMMANDS.add_item(build_tokens) |
0 commit comments