How sebastian-fitzner/mangony works
Project Type & Purpose
• Mangony is a static site generator. Its purpose is to take source files (data, pages, layouts, partials), watch them for changes (using chokidar), process them with templating engines (e.g., Handlebars, JSX, Freemarker), and compile the output to a destination directory.
• Additionally, Mangony can run a development server (powered by Express and BrowserSync) to enable live reloads and efficient rebuilds.
File Structure for Key Components
• examples – showing usage examples for different templating engines.
• lib – contains the core library files:
• mangony.js (the core class).
• modules (subdirectories for components like data management, templater logic, and file watching).
• plugins (plugins for different templating engines and server functionality).
• utils (helper functions, events, and loaders).
• test – contains test cases and fixtures covering different template types.
• This structure indicates that the architecture is modular and plugin-based, with clear separations between core functionality, plugins, and supporting utilities.
Key Components
a. Core Engine:
• Mangony Core (from index.js and lib/mangony.js) which serves as the central orchestrator.
b. Modules:
• Data Module (lib/modules/data.js): Responsible for managing and caching input data.
• Templater Module (lib/modules/templater.js): Handles the templating logic.
• Watcher Module (lib/modules/watcher.js): Watches file system changes for fast re-rendering.
c. Plugins:
• Templater Plugins:
• ftl-templater (for Freemarker templates)
• hbs-templater (for Handlebars templates)
• jsx-templater (for JSX or React-like rendering)
• Server Plugin (lib/plugins/server.js): Provides the development server for live reloads.
d. Utilities:
• Utility components under lib/utils that support event handling, helper functions, and dynamic loading.
e. Configuration & File Types:
• The configuration allows setting up different types (data, pages, layouts, partials), which determine input directories and file glob patterns used by the system.
Relationships and Data Flow
• The Core loads configuration for each type (data, pages, partials, layouts) and instantiates watchers on these directories.
• When a file changes, the Watcher Module notifies the Core, which then uses the Templater Module to process the file(s).
• Templating is performed via one or more of the Plugin components (e.g., JSX templater, Handlebars templater), which interface with external libraries (like Express when the server plugin is active, or BrowserSync for live reloading).
• The final output is compiled files stored in the destination directory.
• Additionally, if the development server is enabled, requests are routed through the Express server component, with BrowserSync handling injection and reloads.
Architectural Patterns & Design Principles
• Plugin-based Architecture: Core behavior is extended through plugins; each templater is a plugin.
• Modular Design: Responsibilities are divided between data, templater, watcher, and utility modules.
• Event-driven: The project uses watchers that trigger events (via the events module in utils) on file changes.
• Configuration-driven: Flexibility in directory structures and file patterns via user-defined options.
Final Checklist
• Components are clearly labeled.
• Core modules (Mangony core, modules, utilities)
• Plugins (templater and server)
• External dependencies (Express, BrowserSync, templating libraries)
• Annotations where necessary to describe interactions between components.