An elm-pages Script is a way to execute an elm-pages
BackendTask
.
Read more about using the elm-pages
CLI to run (or bundle) scripts, plus a brief tutorial, at https://elm-pages-v3.netlify.app/docs/elm-pages-scripts.
Pages.Internal.Script.Script
The type for your run
function that can be executed by elm-pages run
.
withCliOptions : Cli.Program.Config cliOptions -> (cliOptions -> BackendTask FatalError ()) -> Script
Same as withoutCliOptions
, but allows you to define a CLI Options Parser so the user can
pass in additional options for the script.
Uses https://package.elm-lang.org/packages/dillonkearns/elm-cli-options-parser/latest/.
Read more at https://elm-pages-v3.netlify.app/docs/elm-pages-scripts/#adding-command-line-options.
withoutCliOptions : BackendTask FatalError () -> Script
Define a simple Script (no CLI Options).
module MyScript exposing (run)
import BackendTask
import Pages.Script as Script
run =
Script.withoutCliOptions
(Script.log "Hello!"
|> BackendTask.allowFatal
)
writeFile : { path : String, body : String } -> BackendTask { fatal : FatalError, recoverable : Error } ()
Write a file to the file system.
module MyScript exposing (run)
import BackendTask
import Pages.Script as Script
run =
Script.withoutCliOptions
(Script.writeFile
{ path = "hello.json"
, body = """{ "message": "Hello, World!" }"""
}
|> BackendTask.allowFatal
)
log : String -> BackendTask error ()
Log to stdout.
module MyScript exposing (run)
import BackendTask
import Pages.Script as Script
run =
Script.withoutCliOptions
(Script.log "Hello!"
|> BackendTask.allowFatal
)
The recoverable error type for file writes. You can use BackendTask.allowFatal
if you want to allow the program to crash
with an error message if a file write is unsuccessful.