mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-27 11:05:46 +03:00
Add watchers when file reads and globs are encountered in the renderer.
This commit is contained in:
parent
fcada0839e
commit
e8f0ffe7b6
@ -167,7 +167,15 @@ async function handleNavigationRequest(req, res) {
|
||||
} else {
|
||||
try {
|
||||
await pendingCliCompile;
|
||||
const renderResult = await renderer(compiledElmPath, req.url, req);
|
||||
const renderResult = await renderer(
|
||||
compiledElmPath,
|
||||
req.url,
|
||||
req,
|
||||
function (pattern) {
|
||||
console.log(`Watching data source ${pattern}`);
|
||||
watcher.add(pattern);
|
||||
}
|
||||
);
|
||||
if (renderResult.kind === "json") {
|
||||
res.writeHead(200, {
|
||||
"Content-Type": "application/json",
|
||||
|
@ -19,11 +19,17 @@ module.exports =
|
||||
* @param {string} compiledElmPath
|
||||
* @param {string} path
|
||||
* @param {import('aws-lambda').APIGatewayProxyEvent} request
|
||||
* @param {(pattern: string) => void} addDataSourceWatcher
|
||||
* @returns
|
||||
*/
|
||||
async function run(compiledElmPath, path, request) {
|
||||
async function run(compiledElmPath, path, request, addDataSourceWatcher) {
|
||||
XMLHttpRequest = require("xhr2");
|
||||
const result = await runElmApp(compiledElmPath, path, request);
|
||||
const result = await runElmApp(
|
||||
compiledElmPath,
|
||||
path,
|
||||
request,
|
||||
addDataSourceWatcher
|
||||
);
|
||||
return result;
|
||||
};
|
||||
|
||||
@ -31,9 +37,10 @@ module.exports =
|
||||
* @param {string} compiledElmPath
|
||||
* @param {string} pagePath
|
||||
* @param {import('aws-lambda').APIGatewayProxyEvent} request
|
||||
* @param {(pattern: string) => void} addDataSourceWatcher
|
||||
* @returns {Promise<({ kind: 'json'; contentJson: string} | { kind: 'html'; htmlString: string })>}
|
||||
*/
|
||||
function runElmApp(compiledElmPath, pagePath, request) {
|
||||
function runElmApp(compiledElmPath, pagePath, request, addDataSourceWatcher) {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.time(`renderer-${pagePath}`);
|
||||
const isJson = pagePath.match(/content\.json\/?$/);
|
||||
@ -82,6 +89,8 @@ function runElmApp(compiledElmPath, pagePath, request) {
|
||||
} else if (fromElm.tag === "ReadFile") {
|
||||
const filePath = fromElm.args[0];
|
||||
|
||||
addDataSourceWatcher(filePath);
|
||||
|
||||
const fileContents = (
|
||||
await fsPromises.readFile(path.join(process.cwd(), filePath))
|
||||
).toString();
|
||||
@ -97,6 +106,7 @@ function runElmApp(compiledElmPath, pagePath, request) {
|
||||
});
|
||||
} else if (fromElm.tag === "Glob") {
|
||||
const globPattern = fromElm.args[0];
|
||||
addDataSourceWatcher(globPattern);
|
||||
const globResult = await globby(globPattern);
|
||||
const captures = globResult.map((result) => {
|
||||
return {
|
||||
|
Loading…
Reference in New Issue
Block a user