Skip to content

dep-ts/yaml-layer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@dep/yaml-layer 🗂️

A lightweight, type-safe YAML-to-JSON compiler and watcher for Deno.

JSR version

Features ✨

  • Incremental Builds: Uses file system modification times to cache unchanged files.
  • 🛡️ Type Safety: Enforce structure via custom schemas (e.g., Zod) per directory.
  • 🔄 Transforms: Modify or extend your data programmatically before it's saved.
  • 🏗️ Auto-Imports: Generates a main.ts file with standard JSON imports for easy use.
  • 📡 Hot Reloading: Built-in watcher that debounces file system events for rapid development.

Installation 📦

  • Deno:

    deno add jsr:@dep/yaml-layer
    deno install -A -n yaml-layer jsr:@dep/yaml-layer/cli
  • Node.js (18+) or Bun:

    npx jsr add @dep/yaml-layer

    Then import as an ES module:

    import { builder, watcher, defineConfig } from '@dep/yaml-layer';

Usage 🎯

CLI 💻

Build your project manually or start the watcher for real-time development:

# Basic build (defaults to ./content)
yaml-layer build

# Watch mode with custom output
yaml-layer build --watch --outDir ./dist/data

# Custom config path
yaml-layer build -c ./custom.config.ts

API 🧩

Use defineConfig for full type safety when configuring your data layers:

// yaml-layer.config.ts
import { defineConfig } from '@dep/yaml-layer/config';
import { s } from '@dep/schema'; // example schema library

export default defineConfig({
  contentDir: './docs',
  outDir: './.gen',
  docType: 'Wiki', // Groups will be named WikiRoot, WikiGuides, etc.
  schemas: {
    WikiRoot: s.object({
      title: s.string(),
      priority: s.number(),
    }),
  },
  transforms: {
    WikiGuides: (data) => ({
      ...data,
      readingTime: Math.ceil(data._raw.length / 200),
    }),
  },
});

To run it via code:

import { builder, watcher } from '@dep/yaml-layer';

// One-time build
await builder();

// Or watch for changes
await watcher();

Consuming Data 📦

Once the artifacts are generated, simply import the grouped constants directly into your application

// Import the generated constants from your outDir (e.g., ./.gen/main.ts)
import { WikiGuides, WikiRoot } from './.gen/main.ts';

// Single entry access (e.g., a landing page config)
const siteConfig = WikiRoot[0];
console.log(`Welcome to ${siteConfig.title}`);

// Collection iteration (e.g., a blog or documentation list)
WikiGuides.forEach((page) => {
  console.log(`- ${page.title} (ID: ${page._slug})`);
});

License 📄

MIT License – see LICENSE for details.

Author: Estarlin R (estarlincito.com)

About

A lightweight Deno-based tool that transforms YAML content into typed JSON artifacts and generates a central TypeScript entry point for easy data access.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors