Skip to content

Commit a742202

Browse files
committed
Remove npm run compile and add pyproject compile run
1 parent c90f2a5 commit a742202

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

plain/plain/cli/cli.py

+16-15
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import importlib
2-
import json
32
import os
43
import shutil
54
import subprocess
65
import sys
6+
import tomllib
77
import traceback
88
from importlib.metadata import entry_points
99
from importlib.util import find_spec
@@ -292,22 +292,23 @@ def compile(keep_original, fingerprint, compress):
292292
result = entry_point.load()()
293293
print()
294294

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)
306309
print()
307310
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")
311312
sys.exit(result.returncode)
312313

313314
# Compile our assets

0 commit comments

Comments
 (0)