npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@s.a.g.a/ejs-compiler

v1.0.0

Published

Simple EJS compiler written in TypeScript, usable as both CLI and library

Readme

ejs-compiler

Simple EJS compiler written in TypeScript, usable as both CLI and library.

Features

  • CLI Tool: Batch compile EJS templates from the command line
  • Library API: Programmatic compilation for build scripts and automation
  • Glob Patterns: Compile multiple files with powerful pattern matching
  • TypeScript Support: Full TypeScript type definitions included
  • ESM Only: Modern ES module design for Node.js 24+

Installation

npm install @s.a.g.a/ejs-compiler

Windows PowerShell:

npm install "@s.a.g.a/ejs-compiler"

Usage

As a CLI Tool

Compile EJS templates from the command line:

ejs-compiler -f "**/*.ejs" -b ./templates -o ./dist -O data.json

CLI Options

  • -f, --file : Template file path (supports glob patterns) [required]
  • -b, --base-dir : Base directory for relative paths (default: "./")
  • -o, --out : Output directory (if omitted, outputs to stdout)
  • -O, --options : Options data (JSON file path or JSON string)
  • -e, --exclude : File patterns to exclude (comma-separated)
  • -w, --watch : Watch for file changes and recompile

Examples

# Compile all EJS files in templates/ to dist/
ejs-compiler -f "**/*.ejs" -b ./templates -o ./dist

# Compile with data from JSON file
ejs-compiler -f "**/*.ejs" -b ./templates -o ./dist -O ./data.json

# Exclude files starting with underscore (partials) at any depth
ejs-compiler -f "**/*.ejs" -b ./templates -o ./dist -e "_*"

# Compile specific files only
ejs-compiler -f "pages/**/*.ejs" -b ./templates -o ./dist

# Watch for changes and recompile automatically
ejs-compiler -f "**/[!_]*.ejs" -b ./templates -o ./dist -w

As a Library

Use ejs-compiler programmatically in your Node.js projects:

import { compile, loadOptionsData } from 'ejs-compiler';

// Compile templates with options
const results = await compile('**/*.ejs', {
  baseDir: './templates',
  outDir: './dist',
  data: {
    title: 'My Website',
    description: 'Welcome to my site',
  },
  exclude: ['_*.ejs'],
});

// Load data from JSON file
const data = await loadOptionsData('./data.json');

// Compile to memory (without writing files)
const results = await compile('index.ejs', {
  baseDir: './templates',
  data: { title: 'Hello' },
  // no outDir = memory only
});

console.log(results[0].content); // Access compiled HTML

API

compile(filePattern, options)

Compiles EJS template files.

Parameters:

  • filePattern (string | string[]): File pattern(s) supporting glob syntax
  • options (CompilerOptions):
    • baseDir (string): Base directory for resolving paths
    • outDir (string): Output directory (optional - omit for memory-only compilation)
    • data (Record<string, unknown>): Data to pass to templates
    • exclude (string[]): File patterns to exclude

Returns: Promise<CompileResult[]>

  • source (string): Source file path
  • output (string | undefined): Output file path (undefined if no outDir)
  • content (string): Compiled HTML content
loadOptionsData(input)

Loads data from JSON file or JSON string.

Parameters:

  • input (string): File path or JSON string

Returns: Promise<Record<string, unknown>>

Examples

See the examples/ directory for complete working examples:

  • npm run example:cli - CLI usage example
  • npm run example:file - Compile to file (static site generation)
  • npm run example:memory - Compile to memory (server-side rendering)

Development

# Build
npm run build

# Development mode (stub mode)
npm run dev

# Format code
npm run format

# Run tests
npm test

Requirements

  • Node.js 24 or higher
  • ESM-compatible environment

License

MIT

Related

  • AGENTS.md - Guidelines for AI agents working on this project