Shikensu

🚀

program : (Task -> Task) -> Focus -> Program

Create a Shikensu Program.

This is basically a wrapper around list and perform that creates a SimpleProgram for you and initialises the needed permissions.

It also prints errors to stderr or a success message to stdout.

import Shikensu
import Shikensu.Contrib as Shikensu
import Shikensu.Focus exposing (Focus(..))
import Task

Shikensu.program sequence CurrentDirectory

sequence task =
    task
        |> Task.map (Shikensu.withExtension "md")
        |> Task.andThen Shikensu.read
        |> Task.map (Shikensu.renderContent markdownRenderer) -- See `example` folder
        |> Task.andThen (Shikensu.write destinationFocus)
programs : Array { focus : Focus, sequence : Task -> Task } -> Program

Provides a way to make and operate on multiple lists.

Technically not multiple programs, but same idea as the program function, just with multiple lists.

import Shikensu
import Shikensu.Focus exposing (Focus(..))

Shikensu.programs
    [ { focus = Relative (Path.directory [ "posts" ])
      , sequence = Task.andThen Shikensu.read
      }
    , { focus = Relative (Path.directory [ "images" ])
      , sequence = Task.map (\bundle -> ...)
      }
    ]
type alias Program = Program {} {}

Alias for a Node program.

list : Permission -> Focus -> Task

The list function itself, unwrapped.

Recursively lists a directory and then gives you a Task containing a Bundle which in turns has an array of Definitions stored under the property named compendium.

This collection of Definitions is the main thing you'll be working with. The goal of this library is to scan a file tree, manipulate it and then optionally write it back to disk. This is done through these definitions.

import Shikensu
import Shikensu.Focus exposing (Focus(..))

Shikensu.perform
    -- To ignore, return `Cmd.none`
    { onSuccess = \env _ -> Stream.sendLine env.stdout "🧪 Sequence completed"
    , onError = \env err -> Stream.sendLine env.stderr ("🚨 " ++ Error.toString err)
    }
    (\fsPermission ->
        CurrentDirectory
            |> Shikensu.list fsPermission
            |> Task.map (Shikensu.withExtension "md")
    )

⚠️ The given Focus will always be in the context of the environment of the resulting Gren binary that is being executed. So for example, say your pwd command returns ~/code/shikensu/, and your focus is Relative (Path.Directory [ "..", "example" ]). If you run ./binary/app the resulting path will be ~/code/example/.

perform :
{ onSuccess : Environment -> a -> Cmd {}
, onError : Environment -> Error -> Cmd {}
}
-> (Permission -> Task Error a)
-> Program

A utility function that helps you create programs.

This uses Node.defineSimpleProgram and FileSystem.initialize underneath and then manages the Shikensu.Task value created by list or some other function.

See the list function above for an example.

type alias Task = Task Error Bundle

Alias for the main Task type we'll be working with here.

IO

read : Bundle -> Task

Read the files in the given compendium/bundle, setting the content property in the definition.

write : Focus -> Bundle -> Task

Write each definition to their respective location. The location will depend on the focus and the environment it was run in.

writeDefinition : Permission -> Path Directory -> Definition -> Task Error {}

⚠️ You most likely want to use write instead. This function is used internally by write but is exposed for special use cases.

Write a definition to its respective location. The location will depend on the given directory path and the environment it was run in. The given directory path must be an absolute path!