Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
let configured = false;
let finished = false;
const methodsToCall = [];
function setup() {
const Eleventy = require("@11ty/eleventy");
const originalWrite = Eleventy.prototype.write;
Eleventy.prototype.write = async function(...args) {
const out = await originalWrite.apply(this, args);
finished = true;
while (methodsToCall.length) {
const method = methodsToCall.shift();
await method();
}
return out;
};
}
/**
* @param {function(): void} method to call once Eleventy is done
*/
module.exports = function postEleventyBuild(method) {
if (!configured) {
configured = true;
setImmediate(setup);
}
if (finished) {
throw new Error(`Eleventy has already finished`);
}
methodsToCall.push(method);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment