dillonkearns/elm-pages/10.0.0

NOTE: the latest version is 12.3.0

Pages.Script

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.com/docs/elm-pages-scripts.

type alias Script =
Script

The type for your run function that can be executed by elm-pages run.

Defining Scripts

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.com/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
        )

File System Utilities

{ 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
        )

Utilities

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
        )

Errors

type Error
= FileWriteError

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.