summaryrefslogtreecommitdiffstats
path: root/workers/npm_worker.py
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-05-05 10:35:31 +0200
committerDanilo M. <danix@danix.xyz>2026-05-05 10:35:31 +0200
commit48b84da95d0736124f8be6849aa32df31bdb29aa (patch)
treea7c90bf6e744cdc4b0f0d5416776dfb0d147b644 /workers/npm_worker.py
parent7bc1e99f0720598ff7af74361eb1d9029694ede3 (diff)
downloadpublisher-48b84da95d0736124f8be6849aa32df31bdb29aa.tar.gz
publisher-48b84da95d0736124f8be6849aa32df31bdb29aa.zip
feat: run npm build before hugo server and add manual Build CSS buttonv1.5
NpmWorker (QObject+QProcess) runs `npm run build` in the blog repo. HugoPanel sequences: build CSS → start hugo on Avvia. A separate "Build CSS" button allows rebuilding Tailwind while the server runs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Diffstat (limited to 'workers/npm_worker.py')
-rw-r--r--workers/npm_worker.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/workers/npm_worker.py b/workers/npm_worker.py
new file mode 100644
index 0000000..b8c04af
--- /dev/null
+++ b/workers/npm_worker.py
@@ -0,0 +1,38 @@
+from __future__ import annotations
+from PyQt6.QtCore import QObject, QProcess, pyqtSignal
+from pathlib import Path
+
+class NpmWorker(QObject):
+ log_line = pyqtSignal(str)
+ finished = pyqtSignal(bool) # True = success
+
+ def __init__(self, repo_path: Path, parent=None):
+ super().__init__(parent)
+ self._repo_path = repo_path
+ self._process = QProcess(self)
+ self._process.readyReadStandardOutput.connect(self._on_stdout)
+ self._process.readyReadStandardError.connect(self._on_stderr)
+ self._process.finished.connect(self._on_finished)
+
+ @property
+ def is_running(self) -> bool:
+ return self._process.state() == QProcess.ProcessState.Running
+
+ def run(self):
+ if self.is_running:
+ return
+ self._process.setWorkingDirectory(str(self._repo_path))
+ self._process.start("npm", ["run", "build"])
+
+ def _on_stdout(self):
+ data = self._process.readAllStandardOutput().data().decode("utf-8", errors="replace")
+ for line in data.splitlines():
+ self.log_line.emit(line)
+
+ def _on_stderr(self):
+ data = self._process.readAllStandardError().data().decode("utf-8", errors="replace")
+ for line in data.splitlines():
+ self.log_line.emit(line)
+
+ def _on_finished(self, exit_code: int, _):
+ self.finished.emit(exit_code == 0)