mirror of
https://github.com/dillonkearns/elm-pages.git
synced 2024-10-26 10:27:36 +03:00
Handle creating folders for file write streams, and handle errors.
This commit is contained in:
parent
e5e1798459
commit
d2bdf92e95
@ -190,6 +190,11 @@ b =
|
||||
|> Stream.run
|
||||
|> expectError "file not found error"
|
||||
"Error: ENOENT: no such file or directory, open '/Users/dillonkearns/src/github.com/dillonkearns/elm-pages/examples/end-to-end/does-not-exist'"
|
||||
, Stream.fromString "This is input..."
|
||||
|> Stream.pipe (Stream.fileWrite "/this/is/invalid.txt")
|
||||
|> Stream.run
|
||||
|> expectError "invalid file write destination"
|
||||
"Error: ENOENT: no such file or directory, mkdir '/this'"
|
||||
]
|
||||
|
||||
|
||||
|
@ -724,11 +724,22 @@ function runStream(req, portsFile) {
|
||||
stream: lastStream.pipe(zlib.createUnzip()),
|
||||
};
|
||||
} else if (part.name === "fileWrite") {
|
||||
const destinationPath = path.resolve(part.path);
|
||||
try {
|
||||
await fsPromises.mkdir(path.dirname(destinationPath), {
|
||||
recursive: true,
|
||||
});
|
||||
} catch (error) {
|
||||
resolve({ error: error.toString() });
|
||||
}
|
||||
const newLocal = fs.createWriteStream(destinationPath);
|
||||
newLocal.once("error", (error) => {
|
||||
newLocal.close();
|
||||
resolve({ error: error.toString() });
|
||||
});
|
||||
return {
|
||||
metadata: null,
|
||||
stream: lastStream.pipe(
|
||||
fs.createWriteStream(path.resolve(part.path))
|
||||
),
|
||||
stream: lastStream.pipe(newLocal),
|
||||
};
|
||||
} else if (part.name === "httpWrite") {
|
||||
const makeFetchHappen = makeFetchHappenOriginal.defaults({
|
||||
|
Loading…
Reference in New Issue
Block a user