Architecture

Understanding jstatico's internal architecture.

Core Flow

CLI (cli.ts)
    ↓
generate() (index.ts)
    ↓
┌─────────────────────────────────────┐
│ 1. dirTree() - Build file tree      │
│ 2. processTree() - Apply processors │
│ 3. writeTree() - Write output       │
└─────────────────────────────────────┘

Key Files

FilePurpose
src/cli.tsEntry point, argument parsing
src/index.tsOrchestrates the pipeline
src/builder.tsBuilder API for configuration
src/discovery.tsAuto-discovers processors
src/models/FileResult.tsCore file representation
src/types.tsTypeScript interfaces

FileResult

The core data model representing each file:

class FileResult {
  path: string;          // Original file path
  extension: string;     // Current extension
  meta: FileMeta;        // Frontmatter + computed data

  getContent(): string;  // Lazy content loading
  setContent(s: string); // Update content
}

Processor Execution

Processors run in this order:

  1. Programmatic - Added via Builder API
  2. Auto-discovered - From _processors/
  3. Built-in - Default processors

Within each category, processors run in registration order.

Tree Structure

The directory becomes a nested object:

type TreeMap = {
  [key: string]: FileResult | TreeMap;
};

Templates receive the full tree, enabling cross-file access.

Template Context

Templates get:

{
  body: string;           // Rendered content
  meta: FileMeta;         // Page frontmatter
  _site: TreeMap;         // Data from _site/
  [key: string]: TreeMap; // Full tree access
}

Extension Points

PointInterfacePurpose
Preprocessor{ match, process }Transform input
Postprocessor{ match, process }Transform output
Writer{ match, write }Custom output