-
Notifications
You must be signed in to change notification settings - Fork 0
Steps
javarome edited this page May 21, 2024
·
9 revisions
The Ssg execute a number of Steps, sequentially (to allows steps to rely on replacements from a previous step).
Example of predefined steps are:
- ContentStep perform Replacements in files contents.
- DirectoryStep completes a template based on sub-directories,
- CopyStep copies files; sequentially (to produce a listing of them, typically).
Such steps can be added to a Ssg instance, before asking it to start performing them. For instance:
import { ContentStep, CopyStep, Ssg, SsgConfig, SsgContextImpl } from "ssg-api"
const config: SsgConfig = {
getOutputPath(context: SsgContext): string {
return path.join("out", context.file.name)
}
}
const context = new SsgContextImpl("fr")
new Ssg(config)
.add(new ContentStep(contentConfigs, outputFunc))
.add(dir1SubdirectoriesStep)
.add(dir2SubdirectoriesStep)
.add(...anArrayOfSteps)
.add(new CopyStep(copiesToDo))
.start(context)You can create your own steps by implementing the SsgStep interface.
A Step can do anything and return its own results (here a boolean):
class MyStep implements SsgStep {
async execute(context: SsgContext): Promise<boolean> {
context.log("Performing my step")
return true
}
}but it will typically use context.file to perform a transformation.