summaryrefslogtreecommitdiff
path: root/node_modules/@11ty/eleventy/src/Util/FileSystemManager.js
diff options
context:
space:
mode:
authorShipwreckt <me@shipwreckt.co.uk>2025-10-31 20:02:14 +0000
committerShipwreckt <me@shipwreckt.co.uk>2025-10-31 20:02:14 +0000
commit7a52ddeba2a68388b544f529d2d92104420f77b0 (patch)
tree15ddd47457a2cb4a96060747437d36474e4f6b4e /node_modules/@11ty/eleventy/src/Util/FileSystemManager.js
parent53d6ae2b5568437afa5e4995580a3fb679b7b91b (diff)
Changed from static to 11ty!
Diffstat (limited to 'node_modules/@11ty/eleventy/src/Util/FileSystemManager.js')
-rw-r--r--node_modules/@11ty/eleventy/src/Util/FileSystemManager.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/node_modules/@11ty/eleventy/src/Util/FileSystemManager.js b/node_modules/@11ty/eleventy/src/Util/FileSystemManager.js
new file mode 100644
index 0000000..12881d7
--- /dev/null
+++ b/node_modules/@11ty/eleventy/src/Util/FileSystemManager.js
@@ -0,0 +1,48 @@
+import path from "node:path";
+import fs from "node:fs";
+import { mkdir, writeFile } from "node:fs/promises";
+
+class FileSystemManager {
+ constructor(templateConfig) {
+ if (!templateConfig || templateConfig.constructor.name !== "TemplateConfig") {
+ throw new Error(
+ "Internal error: Missing `templateConfig` or was not an instance of `TemplateConfig`.",
+ );
+ }
+ this.templateConfig = templateConfig;
+ }
+
+ exists(pathname) {
+ return this.templateConfig.existsCache.exists(pathname);
+ }
+
+ async createDirectoryForFile(filePath) {
+ let dir = path.parse(filePath).dir;
+ if (!dir || this.exists(dir)) {
+ return;
+ }
+
+ return mkdir(dir, { recursive: true });
+ }
+
+ createDirectoryForFileSync(filePath) {
+ let dir = path.parse(filePath).dir;
+ if (!dir || this.exists(dir)) {
+ return;
+ }
+
+ fs.mkdirSync(dir, { recursive: true });
+ }
+
+ async writeFile(filePath, content) {
+ return writeFile(filePath, content);
+ }
+
+ writeFileSync(filePath, content) {
+ // Note: This deliberately uses the synchronous version to avoid
+ // unbounded concurrency: https://github.com/11ty/eleventy/issues/3271
+ fs.writeFileSync(filePath, content);
+ }
+}
+
+export { FileSystemManager };