Programmatic API
Use jstatico programmatically in your scripts.
Simple API
import { generate } from 'jstatico';
await generate('src', 'dist');Builder API
For more control, use the builder pattern:
import { jstatico } from 'jstatico/builder';
await jstatico('src', 'dist')
.addPreprocessor(myProcessor)
.generate();Types
Preprocessor
interface Preprocessor {
name?: string;
match: RegExp;
process: (this: FileResult) => ProcessResult;
}Postprocessor
interface Postprocessor {
name?: string;
match: RegExp;
process: (this: FileResult, tree: TreeMap, context: TreeContext) => ProcessResult;
}Writer
interface Writer {
name?: string;
match: RegExp;
write: (file: FileResult, destPath: string) => Promise<void> | void;
}ProcessResult
type ProcessResult = void | {
extension?: string;
content?: string;
meta?: Record<string, unknown>;
};FileResult
interface FileResult {
path: string;
extension: string;
meta: FileMeta;
getContent(): string;
setContent(content: string): void;
}TreeMap
type TreeMap = {
[key: string]: FileResult | TreeMap;
};Importing Types
import type {
Preprocessor,
Postprocessor,
Writer,
ProcessResult,
FileResult,
TreeMap,
TreeContext
} from 'jstatico';