From 9d70505ad87e3e4d4500dfffb093f0539ad547ec Mon Sep 17 00:00:00 2001
From: flashwave <me@flash.moe>
Date: Thu, 3 Apr 2025 20:01:27 +0000
Subject: [PATCH] Added utility to nuke the templating cache directory.

---
 src/Templating/TemplatingContext.php |  2 +-
 tools/nuke-tpl-cache                 | 17 +++++++++++++++++
 2 files changed, 18 insertions(+), 1 deletion(-)
 create mode 100755 tools/nuke-tpl-cache

diff --git a/src/Templating/TemplatingContext.php b/src/Templating/TemplatingContext.php
index 67630dc5..a96bf551 100644
--- a/src/Templating/TemplatingContext.php
+++ b/src/Templating/TemplatingContext.php
@@ -11,7 +11,7 @@ class TemplatingContext {
 
     public function __construct(
         Dependencies $deps,
-        string $cachePath,
+        public private(set) string $cachePath,
     ) {
         $this->env = new TplEnvironment(
             Misuzu::PATH_TEMPLATES,
diff --git a/tools/nuke-tpl-cache b/tools/nuke-tpl-cache
new file mode 100755
index 00000000..3dbd8847
--- /dev/null
+++ b/tools/nuke-tpl-cache
@@ -0,0 +1,17 @@
+#!/usr/bin/env php
+<?php
+namespace Misuzu;
+
+require_once __DIR__ . '/../misuzu.php';
+
+$path = $msz->tplCtx->cachePath;
+if(empty($path))
+    die(sprintf('No cache path is specified.%s', PHP_EOL));
+
+if(!is_dir($path))
+    die(sprintf('Cache directory does not exist.%s', PHP_EOL));
+
+if(fileowner($path) !== posix_getuid())
+    die(sprintf('Script must be run as the owner of the cache directory.%s', PHP_EOL));
+
+echo `rm -rv {$path}`;