cleaner watching

This commit is contained in:
Cory LaViska
2023-06-08 14:46:12 -04:00
parent 0de54b163a
commit 45ddaa4d38
2 changed files with 23 additions and 4 deletions

View File

@@ -195,6 +195,13 @@ module.exports = function (eleventyConfig) {
hasBuiltSearchIndex = true;
});
//
// Send a signal to stdout that let's the build know we've reached this point
//
eleventyConfig.on('eleventy.after', () => {
console.log('[eleventy.after]');
});
//
// Dev server options (see https://www.11ty.dev/docs/dev-server/#options)
//

View File

@@ -29,7 +29,8 @@ let buildResult;
// process and an array of strings containing any output are included in the resolved promise.
//
async function buildTheDocs(watch = false) {
return new Promise((resolve, reject) => {
return new Promise(async (resolve, reject) => {
const afterSignal = '[eleventy.after]';
const args = ['@11ty/eleventy', '--quiet'];
const output = [];
@@ -45,12 +46,23 @@ async function buildTheDocs(watch = false) {
});
child.stdout.on('data', data => {
if (data.includes(afterSignal)) return; // don't log the signal
output.push(data.toString());
});
child.on('close', () => {
resolve({ child, output });
});
if (watch) {
// The process doesn't terminate in watch mode so, before resolving, we listen for a known signal in stdout that
// tells us when the first build completes.
child.stdout.on('data', data => {
if (data.includes(afterSignal)) {
resolve({ child, output });
}
});
} else {
child.on('close', () => {
resolve({ child, output });
});
}
});
}