summaryrefslogtreecommitdiff
path: root/node_modules/@11ty/eleventy/src/EleventyWatch.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/EleventyWatch.js
parent53d6ae2b5568437afa5e4995580a3fb679b7b91b (diff)
Changed from static to 11ty!
Diffstat (limited to 'node_modules/@11ty/eleventy/src/EleventyWatch.js')
-rwxr-xr-xnode_modules/@11ty/eleventy/src/EleventyWatch.js131
1 files changed, 131 insertions, 0 deletions
diff --git a/node_modules/@11ty/eleventy/src/EleventyWatch.js b/node_modules/@11ty/eleventy/src/EleventyWatch.js
new file mode 100755
index 0000000..22dffbe
--- /dev/null
+++ b/node_modules/@11ty/eleventy/src/EleventyWatch.js
@@ -0,0 +1,131 @@
+import { TemplatePath } from "@11ty/eleventy-utils";
+
+import PathNormalizer from "./Util/PathNormalizer.js";
+
+/* Decides when to watch and in what mode to watch
+ * Incremental builds don’t batch changes, they queue.
+ * Nonincremental builds batch.
+ */
+
+class EleventyWatch {
+ constructor() {
+ this.incremental = false;
+ this.isActive = false;
+ this.activeQueue = [];
+ }
+
+ isBuildRunning() {
+ return this.isActive;
+ }
+
+ setBuildRunning() {
+ this.isActive = true;
+
+ // pop waiting queue into the active queue
+ this.activeQueue = this.popNextActiveQueue();
+ }
+
+ setBuildFinished() {
+ this.isActive = false;
+ this.activeQueue = [];
+ }
+
+ getIncrementalFile() {
+ if (this.incremental) {
+ return this.activeQueue.length ? this.activeQueue[0] : false;
+ }
+
+ return false;
+ }
+
+ /* Returns the changed files currently being operated on in the current `watch` build
+ * Works with or without incremental (though in incremental only one file per time will be processed)
+ */
+ getActiveQueue() {
+ if (!this.isActive) {
+ return [];
+ } else if (this.incremental && this.activeQueue.length === 0) {
+ return [];
+ } else if (this.incremental) {
+ return [this.activeQueue[0]];
+ }
+
+ return this.activeQueue;
+ }
+
+ _queueMatches(file) {
+ let filterCallback;
+ if (typeof file === "function") {
+ filterCallback = file;
+ } else {
+ filterCallback = (path) => path === file;
+ }
+
+ return this.activeQueue.filter(filterCallback);
+ }
+
+ hasAllQueueFiles(file) {
+ return (
+ this.activeQueue.length > 0 && this.activeQueue.length === this._queueMatches(file).length
+ );
+ }
+
+ hasQueuedFile(file) {
+ if (file) {
+ return this._queueMatches(file).length > 0;
+ }
+ return false;
+ }
+
+ hasQueuedFiles(files) {
+ for (const file of files) {
+ if (this.hasQueuedFile(file)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ get pendingQueue() {
+ if (!this._queue) {
+ this._queue = [];
+ }
+ return this._queue;
+ }
+
+ set pendingQueue(value) {
+ this._queue = value;
+ }
+
+ addToPendingQueue(path) {
+ if (path) {
+ path = PathNormalizer.normalizeSeperator(TemplatePath.addLeadingDotSlash(path));
+ this.pendingQueue.push(path);
+ }
+ }
+
+ getPendingQueueSize() {
+ return this.pendingQueue.length;
+ }
+
+ getPendingQueue() {
+ return this.pendingQueue;
+ }
+
+ getActiveQueueSize() {
+ return this.activeQueue.length;
+ }
+
+ // returns array
+ popNextActiveQueue() {
+ if (this.incremental) {
+ return this.pendingQueue.length ? [this.pendingQueue.shift()] : [];
+ }
+
+ let ret = this.pendingQueue.slice();
+ this.pendingQueue = [];
+ return ret;
+ }
+}
+
+export default EleventyWatch;