Lesson 09 of 10

CLI & Dev Server

Master every command, flag, and workflow tool OrbLayout provides — from scaffolding to live-reload development to production builds.

CLI Overview

OrbLayout ships with a single CLI binary: orb. Every command starts with it.

All Commands terminal
orb init           # Scaffold a new project
orb build          # Compile .orb → HTML
orb build --minify # Compile + minify HTML/CSS/JS
orb dev            # Dev server with live reload
orb dev --port 8080# Custom port
orb clean          # Remove dist/ folder
orb help           # Show help
orb version        # Show version (v1.2.0)
CommandWhat It DoesFlags
initCreates project folders + starter files
buildCompiles all pages to dist/--minify
devStarts dev server + watches files--port <num>
cleanEmpties the dist/ directory
helpDisplays all commands & options
versionPrints the installed version

orb init — Scaffold a Project

Run orb init in an empty directory to generate the full project structure.

Terminal bash
mkdir my-site && cd my-site
npx orblayout init

What gets created

Output
  ╔═══════════════════════════════════════╗
  ║     ◉  O r b L a y o u t  v1.2.0    ║
  ║     Static Site Builder               ║
  ╚═══════════════════════════════════════╝

  Scaffolding new OrbLayout project...

  ✓ Created pages/
  ✓ Created components/
  ✓ Created layouts/
  ✓ Created assets/
  ✓ Created orb.config.json
  ✓ Created layouts/main.layout
  ✓ Created components/header.orb
  ✓ Created components/footer.orb
  ✓ Created pages/index.orb

  ──────────────────────────────────
  Project scaffolded! Run:

    orb build    — Build static HTML
    orb dev      — Start dev server
💡

Safe to run again. orb init only creates files that don't already exist — it will never overwrite your work.

orb build — Compile Your Site

Compiles every .orb file in pages/ into static HTML in dist/.

Terminal bash
orb build
Output
  Building pages...

  ✓ index.orb → index.html
  ✓ about.orb → about.html
  ✓ blog/post-1.orb → blog/post-1.html
  ✓ Assets copied

  ──────────────────────────────────
  Done! 3 page(s) compiled in 24ms
  Output: dist/

The build pipeline

📋

Here's exactly what happens during a build:

  1. Empty dist/ folder (clean start)
  2. Discover all .orb files in pages/
  3. For each page: parse data → resolve imports → process components → process loops → process conditionals → process with blocks → apply filters → resolve variables → inject layout → collect styles
  4. Minify HTML (if --minify flag)
  5. Write output to dist/
  6. Copy assets/dist/assets/

--minify flag

Produces smaller HTML for production:

Minified build bash
orb build --minify

# What minification does:
# - Removes whitespace
# - Removes HTML comments
# - Removes redundant attributes
# - Minifies inline CSS & JS

Subdirectories

Nested folders in pages/ create matching directories in output:

Source pages/
pages/
├── index.orb
├── about.orb
└── blog/
    ├── post-1.orb
    └── post-2.orb
Output dist/
dist/
├── index.html
├── about.html
└── blog/
    ├── post-1.html
    └── post-2.html

orb dev — Development Server

Start a local server that watches your files and auto-refreshes the browser when you save.

Terminal bash
orb dev

# Or with custom port:
orb dev --port 8080
Output
  Building...

  ✓ index.orb → index.html
  ✓ Assets copied

  🌐 OrbLayout dev server running at http://localhost:3000
  Watching for changes...

How live reload works

OrbLayout uses SSE (Server-Sent Events) — no WebSocket dependency needed.

  1. Watch: Chokidar monitors pages/, components/, layouts/, and assets/
  2. Rebuild: On file change, the entire site is rebuilt (~20ms)
  3. Notify: SSE sends "reload" to all connected browsers
  4. Refresh: JavaScript in the page calls window.location.reload()

What gets served

FeatureDetails
Static filesServed from dist/
Clean URLs/aboutabout.html
Directory indexes/blog/blog/index.html
MIME typesHTML, CSS, JS, JSON, PNG, JPG, SVG, fonts
SSE endpoint/__orb_reload
404 pageBuilt-in styled dark-theme 404

Press Ctrl+C to stop the server gracefully.

orb clean — Clear Output

Removes everything inside dist/. Useful before a fresh production build.

Terminal bash
orb clean

# Then rebuild from scratch:
orb build --minify

Configuration — orb.config.json

Every OrbLayout project reads its settings from orb.config.json in the project root.

orb.config.json json
{
  "pagesDir":      "pages",
  "componentsDir": "components",
  "layoutsDir":    "layouts",
  "outputDir":     "dist",
  "assetsDir":     "assets",
  "minify":        false,
  "pretty":        true
}
KeyDefaultDescription
pagesDir"pages"Directory containing your .orb source files
componentsDir"components"Directory for reusable component files
layoutsDir"layouts"Directory for .layout templates
outputDir"dist"Where compiled HTML is written
assetsDir"assets"Static files copied to output as-is
minifyfalseEnable HTML minification (also via --minify flag)
prettytruePretty-print output HTML

Custom directory names

You can rename any directory:

Custom config json
{
  "pagesDir":      "src/views",
  "componentsDir": "src/ui",
  "layoutsDir":    "src/templates",
  "outputDir":     "build",
  "assetsDir":     "public",
  "minify":        true
}
📋

If orb.config.json doesn't exist, OrbLayout uses the defaults. You only need to include keys you want to change.

npm Scripts

Add OrbLayout commands to your package.json for convenience:

package.json json
{
  "name": "my-site",
  "scripts": {
    "dev":   "orb dev",
    "build": "orb build",
    "prod":  "orb clean && orb build --minify",
    "clean": "orb clean"
  }
}
Usage bash
npm run dev    # Start dev server
npm run build  # Build site
npm run prod   # Clean + minified production build

Programmatic API

Use OrbLayout from your own Node.js scripts — perfect for custom build pipelines, CI/CD, and automation.

build-script.js javascript
const { loadConfig, OrbCompiler, OrbBuilder, OrbDevServer } = require("orblayout");

// Load config from current directory
const config = loadConfig(__dirname);

// ── Option 1: Full build ──
const builder = new OrbBuilder(config);
const result = await builder.build();
console.log(`Built ${result.pages} pages in ${result.time}ms`);

// ── Option 2: Compile a single page ──
const compiler = new OrbCompiler(config);
const html = compiler.compilePage("pages/index.orb");

// ── Option 3: Start dev server ──
const server = new OrbDevServer(config);
await server.start(3000);

Custom filters via API

Register a custom filter javascript
const { loadConfig, OrbCompiler } = require("orblayout");

const config = loadConfig(__dirname);
const compiler = new OrbCompiler(config);

// Register your own filter
compiler.registerFilter("shout", (value) => {
  return value.toUpperCase() + "!!!";
});

compiler.registerFilter("dollars", (value) => {
  return "$" + Number(value).toFixed(2);
});

// Now {{ greeting | shout }} → "HELLO!!!"
// And {{ price | dollars }} → "$9.99"

Exported modules

ExportTypeDescription
loadConfig(rootDir)FunctionReads orb.config.json and returns resolved config object
OrbCompilerClassCore compiler — .compilePage(path), .registerFilter(name, fn)
OrbBuilderClassBuild orchestrator — .build() discovers & compiles all pages
OrbDevServerClassDev server — .start(port), .stop()

✅ Lesson 9 Checkpoint

You should now be able to:

  1. Use every CLI command: init, build, dev, clean, help, version
  2. Build minified production HTML with --minify
  3. Run a live-reloading dev server with custom ports
  4. Configure orb.config.json with custom directories
  5. Set up npm scripts for a professional workflow
  6. Use the programmatic API to build custom tooling
  7. Register custom filters via compiler.registerFilter()