mirror of
https://github.com/dillonkearns/elm-pages-v3-beta.git
synced 2024-11-27 11:05:46 +03:00
File read build errors.
This commit is contained in:
parent
4bcfcbd358
commit
4c9c365887
@ -67,18 +67,24 @@ function runElmApp() {
|
||||
outputString(fromElm);
|
||||
} else if (fromElm.tag === "ReadFile") {
|
||||
const filePath = fromElm.args[0];
|
||||
|
||||
const fileContents = fs.readFileSync(filePath).toString();
|
||||
const parsedFile = matter(fileContents);
|
||||
app.ports.fromJsPort.send({
|
||||
tag: "GotFile",
|
||||
data: {
|
||||
filePath,
|
||||
parsedFrontmatter: parsedFile.data,
|
||||
withoutFrontmatter: parsedFile.content,
|
||||
rawFile: fileContents,
|
||||
},
|
||||
});
|
||||
try {
|
||||
const fileContents = fs.readFileSync(filePath).toString();
|
||||
const parsedFile = matter(fileContents);
|
||||
app.ports.fromJsPort.send({
|
||||
tag: "GotFile",
|
||||
data: {
|
||||
filePath,
|
||||
parsedFrontmatter: parsedFile.data,
|
||||
withoutFrontmatter: parsedFile.content,
|
||||
rawFile: fileContents,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
app.ports.fromJsPort.send({
|
||||
tag: "BuildError",
|
||||
data: { filePath },
|
||||
});
|
||||
}
|
||||
} else if (fromElm.tag === "Glob") {
|
||||
const globPattern = fromElm.args[0];
|
||||
const globResult = globby.sync(globPattern);
|
||||
|
@ -88,22 +88,28 @@ function runElmApp(compiledElmPath, pagePath, request, addDataSourceWatcher) {
|
||||
}
|
||||
} else if (fromElm.tag === "ReadFile") {
|
||||
const filePath = fromElm.args[0];
|
||||
try {
|
||||
addDataSourceWatcher(filePath);
|
||||
|
||||
addDataSourceWatcher(filePath);
|
||||
|
||||
const fileContents = (
|
||||
await fsPromises.readFile(path.join(process.cwd(), filePath))
|
||||
).toString();
|
||||
const parsedFile = matter(fileContents);
|
||||
app.ports.fromJsPort.send({
|
||||
tag: "GotFile",
|
||||
data: {
|
||||
filePath,
|
||||
parsedFrontmatter: parsedFile.data,
|
||||
withoutFrontmatter: parsedFile.content,
|
||||
rawFile: fileContents,
|
||||
},
|
||||
});
|
||||
const fileContents = (
|
||||
await fsPromises.readFile(path.join(process.cwd(), filePath))
|
||||
).toString();
|
||||
const parsedFile = matter(fileContents);
|
||||
app.ports.fromJsPort.send({
|
||||
tag: "GotFile",
|
||||
data: {
|
||||
filePath,
|
||||
parsedFrontmatter: parsedFile.data,
|
||||
withoutFrontmatter: parsedFile.content,
|
||||
rawFile: fileContents,
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
app.ports.fromJsPort.send({
|
||||
tag: "BuildError",
|
||||
data: { filePath },
|
||||
});
|
||||
}
|
||||
} else if (fromElm.tag === "Glob") {
|
||||
const globPattern = fromElm.args[0];
|
||||
addDataSourceWatcher(globPattern);
|
||||
|
@ -59,6 +59,7 @@ type alias Model route =
|
||||
type Msg
|
||||
= GotStaticHttpResponse { request : { masked : RequestDetails, unmasked : RequestDetails }, response : Result Pages.Http.Error String }
|
||||
| GotStaticFile ( String, Decode.Value )
|
||||
| GotBuildError BuildError
|
||||
| GotGlob ( String, Decode.Value )
|
||||
| Continue
|
||||
|
||||
@ -102,6 +103,23 @@ cliApplication config =
|
||||
-- tag: "GotGlob"
|
||||
-- tag: "GotFile"
|
||||
case tag of
|
||||
"BuildError" ->
|
||||
Decode.field "data"
|
||||
(Decode.field "filePath" Decode.string
|
||||
|> Decode.map
|
||||
(\filePath ->
|
||||
{ title = "File not found"
|
||||
, message =
|
||||
[ Terminal.text "A DataSource.File read failed because I couldn't find this file: "
|
||||
, Terminal.yellow <| Terminal.text filePath
|
||||
]
|
||||
, fatal = True
|
||||
, path = "" -- TODO wire in current path here
|
||||
}
|
||||
)
|
||||
)
|
||||
|> Decode.map GotBuildError
|
||||
|
||||
"GotFile" ->
|
||||
gotStaticFileDecoder
|
||||
|> Decode.map GotStaticFile
|
||||
@ -608,6 +626,23 @@ update contentCache config msg model =
|
||||
Nothing
|
||||
|> nextStepToEffect contentCache config updatedModel
|
||||
|
||||
GotBuildError buildError ->
|
||||
let
|
||||
updatedModel =
|
||||
{ model
|
||||
| errors =
|
||||
buildError :: model.errors
|
||||
}
|
||||
in
|
||||
StaticResponses.nextStep config
|
||||
updatedModel.mode
|
||||
updatedModel.secrets
|
||||
updatedModel.allRawResponses
|
||||
updatedModel.errors
|
||||
updatedModel.staticResponses
|
||||
Nothing
|
||||
|> nextStepToEffect contentCache config updatedModel
|
||||
|
||||
|
||||
nextStepToEffect :
|
||||
ContentCache
|
||||
|
Loading…
Reference in New Issue
Block a user