Skip to content

Commit

Permalink
Merge pull request #455 from miniBill/absolute-file-write
Browse files Browse the repository at this point in the history
Allow usage of absolute paths in `Script.writeFile`
  • Loading branch information
dillonkearns authored Mar 11, 2024
2 parents aea5a7d + ae92b71 commit a2356d3
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 2 additions & 3 deletions generator/src/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,9 +551,8 @@ function runSleep(req) {
async function runWriteFileJob(req) {
const data = req.body.args[0];
try {
const fullPathToWrite = path.join(process.cwd(), data.path);
await fsPromises.mkdir(path.dirname(fullPathToWrite), { recursive: true });
await fsPromises.writeFile(fullPathToWrite, data.body);
await fsPromises.mkdir(path.dirname(data.path), { recursive: true });
await fsPromises.writeFile(data.path, data.body);
return jsonResponse(req, null);
} catch (error) {
console.trace(error);
Expand Down
6 changes: 4 additions & 2 deletions src/Pages/Script.elm
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ type Error

{-| Write a file to the file system.
File paths are relative to the root of your `elm-pages` project (next to the `elm.json` file and `src/` directory), or you can pass in absolute paths beginning with a `/`.
module MyScript exposing (run)
import BackendTask
Expand Down Expand Up @@ -166,6 +168,8 @@ withCliOptions config execute =
config
|> Program.mapConfig execute
)


sleep : Int -> BackendTask error ()
sleep int =
BackendTask.Internal.Request.request
Expand All @@ -181,8 +185,6 @@ sleep int =
}




doThen : BackendTask error value -> BackendTask error () -> BackendTask error value
doThen task1 task2 =
task2
Expand Down

0 comments on commit a2356d3

Please sign in to comment.