Created
January 9, 2020 09:06
-
-
Save daviddarnes/ff765e7174aad73da2623c2e63099ed8 to your computer and use it in GitHub Desktop.
Mini Node server for triggering 11ty builds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const http = require('http'); | |
const process = require('process'); | |
const { exec } = require('child_process'); | |
const hostname = '127.0.0.1'; | |
const port = 3000; | |
const server = http.createServer((req, res) => { | |
console.log('Ghost content updated!'); | |
process.chdir('../eleventy/'); | |
console.log(`Navigated to: ${process.cwd()}`); | |
exec('eleventy build', (error, output, ouputerror) => { | |
console.log('Attempting 11ty build…') | |
if (error !== null) { | |
console.log('Build failed…') | |
console.log(`exec error: \n${error}`); | |
} | |
console.log(`exec output: \n${output}`); | |
console.log(`exec output errors: \n${ouputerror ? ouputerror : 'there were no errors'}`); | |
}) | |
res.end('okay'); | |
}); | |
server.listen(port, hostname, () => { | |
console.log(`Server running at http://${hostname}:${port}/`); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment