Show error message when all Page Templates are removed.

This commit is contained in:
Dillon Kearns 2021-04-23 10:17:25 -07:00
parent 594888776b
commit 1ea3a81316
3 changed files with 37 additions and 6 deletions

View File

@ -13,6 +13,8 @@ async function generate() {
}
async function writeFiles() {
const cliCode = generateTemplateModuleConnector("cli");
const browserCode = generateTemplateModuleConnector("browser");
ensureDirSync("./elm-stuff");
ensureDirSync("./gen");
ensureDirSync("./elm-stuff/elm-pages");
@ -31,13 +33,11 @@ async function writeFiles() {
// write `Pages.elm` with cli interface
fs.writeFileSync("./elm-stuff/elm-pages/Pages.elm", elmPagesCliFile());
const cliCode = generateTemplateModuleConnector("cli");
fs.writeFileSync(
"./elm-stuff/elm-pages/TemplateModulesBeta.elm",
cliCode.mainModule
);
fs.writeFileSync("./elm-stuff/elm-pages/Route.elm", cliCode.routesModule);
const browserCode = generateTemplateModuleConnector("browser");
fs.writeFileSync("./gen/TemplateModulesBeta.elm", browserCode.mainModule);
fs.writeFileSync("./gen/Route.elm", browserCode.routesModule);

View File

@ -113,12 +113,26 @@ async function start(options) {
} else if (pathThatChanged.endsWith(".elm")) {
if (elmMakeRunning) {
} else {
let codegenError = null;
if (needToRerunCodegen(eventName, pathThatChanged)) {
await codegen.generate();
try {
await codegen.generate();
} catch (error) {
codegenError = error;
}
}
elmMakeRunning = true;
clientElmMakeProcess = compileElmForBrowser();
pendingCliCompile = compileCliApp();
if (codegenError) {
const errorJson = JSON.stringify({
type: "compile-errors",
errors: [codegenError],
});
clientElmMakeProcess = Promise.reject(errorJson);
pendingCliCompile = Promise.reject(errorJson);
} else {
clientElmMakeProcess = compileElmForBrowser();
pendingCliCompile = compileCliApp();
}
let timestamp = Date.now();
Promise.all([clientElmMakeProcess, pendingCliCompile])

View File

@ -16,7 +16,24 @@ function generateTemplateModuleConnector(phase) {
}
});
if (templates.length <= 0) {
throw `I couldn't find any Page Templates. Try using elm-pages add Index to get started with your first page!`;
throw {
path: "",
name: "TemplateModulesBeta",
problems: [
{
title: "Could not generate entrypoint",
message: [
`I couldn't find any Page Templates. Try creating your first page by running: \n\n`,
{
bold: false,
underline: false,
color: "yellow",
string: "elm-pages add Index",
},
],
},
],
};
}
return {