|
1 | 1 | import importlib |
2 | | -import json |
3 | 2 | import os |
4 | 3 | import shutil |
5 | 4 | import subprocess |
6 | 5 | import sys |
| 6 | +import tomllib |
7 | 7 | import traceback |
8 | 8 | from importlib.metadata import entry_points |
9 | 9 | from importlib.util import find_spec |
@@ -292,22 +292,23 @@ def compile(keep_original, fingerprint, compress): |
292 | 292 | result = entry_point.load()() |
293 | 293 | print() |
294 | 294 |
|
295 | | - # TODO also look in [tool.plain.compile.run] |
296 | | - |
297 | | - # Run a "compile" script from package.json automatically |
298 | | - package_json = Path("package.json") |
299 | | - if package_json.exists(): |
300 | | - with package_json.open() as f: |
301 | | - package = json.load(f) |
302 | | - |
303 | | - if package.get("scripts", {}).get("compile"): |
304 | | - click.secho("Running `npm run compile`", bold=True) |
305 | | - result = subprocess.run(["npm", "run", "compile"]) |
| 295 | + pyproject_path = plain.runtime.APP_PATH.parent / "pyproject.toml" |
| 296 | + if pyproject_path.exists(): |
| 297 | + with pyproject_path.open("rb") as f: |
| 298 | + pyproject = tomllib.load(f) |
| 299 | + |
| 300 | + for name, data in ( |
| 301 | + pyproject.get("tool", {}) |
| 302 | + .get("plain", {}) |
| 303 | + .get("compile", {}) |
| 304 | + .get("run", {}) |
| 305 | + .items() |
| 306 | + ): |
| 307 | + click.secho(f"Running {name} from pyproject.toml", bold=True) |
| 308 | + result = subprocess.run(data["cmd"], shell=True) |
306 | 309 | print() |
307 | 310 | if result.returncode: |
308 | | - click.secho( |
309 | | - f"Error in `npm run compile` (exit {result.returncode})", fg="red" |
310 | | - ) |
| 311 | + click.secho(f"Error in {name} (exit {result.returncode})", fg="red") |
311 | 312 | sys.exit(result.returncode) |
312 | 313 |
|
313 | 314 | # Compile our assets |
|
0 commit comments