About
The Wordscript Runtime is responsible for:
- Initializing a runtime instance from configuration
- Loading plugins
- Parsing one or more Wordscript files
- Ensuring Wordscript is well-formed and valid
- Coordinating plugins
- Invoking actions
- Running a script
- Generating media
- Publishing media
- Deploying media
Lifecycle
flowchart TD
a[Create Runtime] --> lp[Load Plugins]
lp --> b[Load Wordscript]
b --> v[Validate]
v --> rs[Run Script]
v --> c[Generate Media]
c --> d[slideshow]
c --> e[interactive speech]
c --> f[website]
d --> p[Package]
e --> p
f --> p
p--> preview[Preview]
p --> dep[Deploy]
Parsing
A parsed wordscript returns a Script Fragment
. This is simply a list of elements. Unlike other languages, text and attributes are standalone elements.
const fragment = parse("[[ hello ]] [[ world [[@ color:red; ]] ]]");
This fragment will contain the following elements
text ["hello"]
whitespace [" "]
text ["world", @[{color:"red"}] ]
Creating A Runtime
This method creates a runtime with a default configuration and includes standard plugins.
const runtime = await createWordscriptRuntime()
Adding Plugins
Most basic Wordscript runtime features rely on plugins. Several core plugins are included in the standardPlugins
module.
createWordscriptRuntime({
plugins: standardPlugins()
})
You can install your own plugins along with the standard plugins.
createWordscriptRuntime({
plugins: [
...standardPlugins(),
yourPlugin(),
})
Loading Wordscript
Once you create the runtime, you will want to load some Wordscript.
const runtime = await createWordscriptRuntime()
~~~~await runtime.load(myScript)
Loading a script will also validate it.
Playing Scripts
[coming soon]
Generating Media
After loading your script, you can generate media.
There are four primary media types: audio
, video
, print
, and code
.
Each media target can support multiple formats.
For example, the transcript plugin can generate HTML and Markdown transcripts.
Plugins define supported media targets in their manifest.
const targets = await runtime.getMediaTargets()
Media is created by specifying the desired media target and format.
await runtime.load(myWordscript)
const media = await runtime.generate('transcript','html')
Publishing And Deploying Media
Exporting, such as saving to a file, is considered publishing. Serving media over the internet is also publishing.
await runtime
.load(myWordscript)
.generate('speech')
.publish('localStorage')
flowchart TD
a[Generate Media] --> b[Publish Media]
b --> c[Local Storage]
b --> d[File System]
b --> e[Cloud Storage]
b --> f[Social Media]