Shikensu
🚀
Create a Shikensu Program.
This is basically a wrapper around list and FileSystem.initialize
that creates a Program 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)
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 -> ...)
}
]
Alias for a Node program.
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(..))
Node.defineSimpleProgram
(\_ ->
Init.await
FileSystem.initialize
(\fsPermission ->
CurrentDirectory
|> Shikensu.list fsPermission
|> Task.map (Shikensu.withExtension "md")
|> ...
-- When creating a `SimpleProgram` we need to return a `Init.Task`
-- This requires us to use `Init.awaitTask` which expects a task of the type `Task Never a`
-- This is different from Shikensu's Task type, which is `Task Error a`
-- So ideally you do some error handling here, or just ignore it.
|> Task.andThen (\_ -> Task.succeed Cmd.none)
|> Task.onError (\_ -> Task.succeed Cmd.none)
|> (\task -> Init.awaitTask task Node.endWithCmd)
)
)
⚠️ 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/.
Alias for the main Task type we'll be working with here.
IO
Read the files in the given compendium/bundle,
setting the content property in the definition.
Write each definition to their respective location. The location will depend on the focus and the environment it was run in.