Skip to content

alvis/presetter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

617 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Logo

npm build maintainability coverage dependencies

Transform 40+ dev dependencies into 2 packages โ€” template-driven configuration management for modern TypeScript development

โ€ขโ€ƒ โ€ƒQuick Startโ€ƒ โ€ƒโ€ขโ€ƒ โ€ƒMonorepo Structureโ€ƒ โ€ƒโ€ขโ€ƒ โ€ƒOfficial Presetsโ€ƒ โ€ƒโ€ขโ€ƒ โ€ƒUsageโ€ƒ โ€ƒโ€ข

Presetter is a configuration management tool that eliminates the pain of setting up and maintaining build configurations across TypeScript projects. Instead of copying dozens of config files and managing 40+ dev dependencies, you install 2 packages and get a perfectly configured development environment.

This monorepo contains the Presetter engine and a comprehensive ecosystem of official presets for every TypeScript development scenario.

Before and After


๐Ÿš€ Quick Start

๐ŸŽฏ Choose Your Development Style

# ๐ŸŸข Modern ESM development
npx presetter use presetter-preset-esm

# ๐Ÿ”— Legacy CommonJS compatibility
npx presetter use presetter-preset-cjs

# ๐ŸŒ Dual-module library publishing
npx presetter use presetter-preset-hybrid

# ๐ŸŽจ Modern web development (TailwindCSS + Storybook)
npx presetter use presetter-preset-esm presetter-preset-web

# โš›๏ธ React application with optimized toolchain
npx presetter use presetter-preset-esm presetter-preset-react

# ๐Ÿข Production-grade (security + 100% coverage)
npx presetter use presetter-preset-esm presetter-preset-strict

# โšก Next.js application with full-stack support
npx presetter use presetter-preset-next

๐Ÿ”ง Or Set It Up Manually

  1. Add Presetter and preset to your project:
{
  scripts: {
    bootstrap: 'presetter bootstrap',
  },
  devDependencies: {
    'presetter': 'latest',
    'presetter-preset-esm': 'latest',
  },
}
  1. Create preset configuration:
// presetter.config.ts
export { default } from 'presetter-preset-esm';
  1. Install and start developing:
npm install  # Configurations generated automatically
npm run test # Everything just works! โœจ

Demo


๐Ÿ—๏ธ Monorepo Structure

This repository is organized as a TypeScript monorepo containing the core Presetter engine and all official presets:

presetter/
โ”œโ”€โ”€ packages/
โ”‚   โ”œโ”€โ”€ presetter/              ๐ŸŽ›๏ธ Core configuration management engine
โ”‚   โ”œโ”€โ”€ types/                  ๐Ÿ“‹ TypeScript definitions for preset development
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ preset-essentials/      ๐Ÿ—๏ธ Foundation toolkit (TypeScript, ESLint, Vitest)
โ”‚   โ”œโ”€โ”€ preset-monorepo/        ๐Ÿ“ฆ Monorepo project management
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ preset-esm/             ๐Ÿš€ ESM-first development
โ”‚   โ”œโ”€โ”€ preset-cjs/             ๐Ÿ”— CommonJS compatibility
โ”‚   โ”œโ”€โ”€ preset-hybrid/          ๐ŸŒ Dual CommonJS/ESM packages
โ”‚   โ”‚
โ”‚   โ”œโ”€โ”€ preset-strict/          ๐Ÿข Production-grade quality enforcement
โ”‚   โ”œโ”€โ”€ preset-web/             ๐ŸŽจ Modern web development stack
โ”‚   โ”œโ”€โ”€ preset-react/           โš›๏ธ React development excellence
โ”‚   โ”œโ”€โ”€ preset-next/            โšก Next.js full-stack development
โ”‚   โ””โ”€โ”€ preset-rollup/          ๐Ÿ“ฆ Professional library bundling
โ”‚
โ””โ”€โ”€ assets/                     ๐ŸŽจ Logos, demos, and documentation assets

๐ŸŽฏ Package Categories

Category Packages Purpose
Core Engine presetter, types Configuration management infrastructure
Foundation preset-essentials, preset-monorepo Base TypeScript development toolkit
Module Systems preset-esm, preset-cjs, preset-hybrid JavaScript module format specializations
Extensions preset-strict, preset-web, preset-react, preset-next, preset-rollup Specialized development environments

๐Ÿ“ฆ Official Presets

๐Ÿ—๏ธ Foundation Presets

Preset Purpose Dependencies Best For
presetter-preset-essentials Complete TypeScript development toolkit TypeScript, ESLint, Vitest, Prettier, Husky Foundation for all TypeScript projects
presetter-preset-monorepo Monorepo project management Workspace tools, cross-package scripts Multi-package repositories

๐Ÿš€ Module System Presets

Preset Purpose Extends Best For
presetter-preset-esm ESM-first development essentials Modern Node.js projects, libraries
presetter-preset-cjs CommonJS compatibility essentials Legacy environments, enterprise
presetter-preset-hybrid Dual CommonJS/ESM packages essentials npm libraries needing broad compatibility

๐ŸŽจ Specialized Extension Presets

Preset Purpose Extends Best For
presetter-preset-strict Production-grade quality enforcement Any base preset Enterprise applications, critical systems
presetter-preset-web Modern web development stack Any base preset Web applications, SPAs
presetter-preset-react React development excellence Any base preset React applications, component libraries
presetter-preset-next Next.js full-stack development esm + strict + react Next.js apps with App Router, Server Components
presetter-preset-rollup Professional library bundling Any base preset npm packages, open-source libraries

๐ŸŽฏ Common Preset Combinations

// Modern web application
extends: [esm, web]

// React component library
extends: [react, rollup]

// Legacy Node.js service
extends: [cjs]

// Full-stack TypeScript monorepo
extends: [monorepo]

// Next.js application (includes everything)
export { default } from 'presetter-preset-next';

๐Ÿ” How Presetter Works

Presetter transforms configuration management through intelligent template processing:

๐ŸŽ›๏ธ The Core Engine (packages/presetter)

Presetter handles two main responsibilities:

  1. ๐Ÿ—๏ธ Environment Setup:

    • Installs development dependencies defined by presets
    • Generates configuration files using sophisticated templates
  2. โšก Script Management:

    • Merges preset scripts with local package.json scripts
    • Provides intelligent script composition and execution
    • Enables run, run-s, and run-p commands for enhanced workflows
    • Binary Path Resolution: Automatically discovers executables in each preset's node_modules/.bin and prepends them to PATH, allowing preset tools to take priority without requiring shamefullyHoist or public-hoist-pattern configuration

    Note: Libraries loaded via dynamic import (like @vitest/coverage-v8) may still need to be installed at root or hoisted. See the presetter package docs for details.

๐Ÿ“‹ Preset Architecture

Each preset is a reusable configuration bundle containing:

  • Dependencies: Defined as peerDependencies and installed automatically
  • Configuration Templates: Dynamic files that adapt to your project structure
  • Scripts: Lifecycle commands that integrate with your local workflows
  • Variables: Customizable parameters for flexible configuration

๐Ÿง  Two-Pass Resolution System

Presetter uses a sophisticated resolution process:

  1. ๐Ÿ“‹ Dependency Resolution: Build preset inheritance tree and merge configurations
  2. ๐ŸŽฏ Asset Generation: Process templates with context-aware variable substitution
  3. โšก Override Application: Apply customizations while preserving preset benefits

๐Ÿ› ๏ธ Usage

๐Ÿ“ Basic Configuration

// presetter.config.ts - Use a preset as-is
export { default } from 'presetter-preset-esm';

๐ŸŽจ Advanced Customization

// presetter.config.ts - Customize and extend presets
import { preset } from 'presetter';
import esm from 'presetter-preset-esm';
import strict from 'presetter-preset-strict';

export default preset('my-project', {
  extends: [esm, strict],
  override: {
    variables: {
      target: 'ES2023', // Modern compilation target
      source: 'source', // Custom source directory
    },
    assets: {
      'tsconfig.json': {
        compilerOptions: {
          allowImportingTsExtensions: true,
        },
      },
    },
  },
});

โšก CLI Commands

# Preset management
presetter use <preset>         # Adopt preset(s) to project
presetter bootstrap           # Apply configurations
presetter unset              # Remove all preset artifacts

# Development workflows
run build                    # Build your project
run test                     # Run tests with coverage
run lint                     # Lint and fix code
run watch                    # Development mode

# Advanced execution
run-s clean build test       # Sequential execution
run-p lint test              # Parallel execution

๐Ÿข Monorepo Development

๐Ÿ”ง Development Setup

This monorepo uses Presetter itself for development! Each package has its own preset configuration:

# Install dependencies
npm install

# Bootstrap all packages
npm run bootstrap

# Run tests across all packages
npm run test

# Build all packages
npm run build

๐Ÿ“Š Package Dependencies

graph TD
  T[types]
  P[presetter]
  E[preset-essentials]
  S[preset-strict]
  M[preset-esm]
  C[preset-cjs]
  H[preset-hybrid]
  W[preset-web]
  R[preset-react]
  N[preset-next]
  U[preset-rollup]
  O[preset-monorepo]

  P --> T
  E --> T
  M --> E
  C --> E
  H --> E
  S --> T
  W --> T
  R --> W
  N --> M
  N --> S
  N --> R
  U --> T
  O --> M
  O --> S
Loading

๐ŸŽฏ Workspace Scripts

The monorepo provides convenient workspace-wide commands:

Command Purpose
npm run build Build all packages in dependency order
npm run test Run tests across all packages
npm run lint Lint all packages with auto-fix
npm run clean Clean build artifacts
npm run bootstrap Bootstrap all preset configurations

๐Ÿ“– Documentation

๐Ÿ“š Package Documentation

Each package contains comprehensive documentation:

๐ŸŽ“ Learning Resources

Topic Resource
Getting Started Core Engine Quick Start
Preset Creation Types Package Guide
Advanced Usage Configuration Customization
Monorepo Setup Monorepo Preset Guide

๐Ÿค Contributing

We'd love your ideas and contributions! Submit issues or suggestions via GitHub Issues. See the Contribution Guide for more details.


โ“ FAQ

How do I create a custom preset?

Create a TypeScript file that exports a preset configuration:

import { preset } from 'presetter';

export default preset('my-preset', {
  variables: {
    source: 'src',
    output: 'dist',
  },
  scripts: {
    build: 'tsc',
    test: 'vitest',
  },
  assets: {
    'tsconfig.json': {
      compilerOptions: {
        target: 'ES2022',
        module: 'ESNext',
      },
    },
  },
});

How do I customize an existing preset?

Use the override field to modify preset configurations:

import { preset } from 'presetter';
import esm from 'presetter-preset-esm';

export default preset('custom', {
  extends: [esm],
  override: {
    assets: {
      'tsconfig.json': {
        compilerOptions: {
          strict: false, // Relax TypeScript strictness
        },
      },
    },
  },
});

Can I combine multiple presets?

Yes! Presets are designed to be composable:

import { preset } from 'presetter';
import essentials from 'presetter-preset-essentials';
import web from 'presetter-preset-web';
import react from 'presetter-preset-react';
import strict from 'presetter-preset-strict';

export default preset('ultimate-react', {
  extends: [essentials, web, react, strict],
});

How do I ignore files from a preset?

Override the asset with null:

export default preset('custom', {
  extends: [somePreset],
  override: {
    assets: {
      '.gitignore': null, // Don't generate .gitignore
    },
  },
});

๐ŸŒŸ Philosophy

Presetter was born from the frustration of maintaining identical configurations across multiple TypeScript projects. The core principles:

  • ๐ŸŽฏ Simplicity: One command should set up a complete development environment
  • ๐Ÿ”„ Maintainability: Updates should propagate automatically across all projects
  • ๐Ÿงฉ Composability: Presets should work together seamlessly
  • โšก Flexibility: Local customizations should always be respected
  • ๐Ÿ“ˆ Scalability: Should work for individual projects and large monorepos

๐Ÿ“„ License

Released under the MIT License. ยฉ 2020, Alvis Tang.

License

About

๐Ÿ›น Reuse and manage build scripts, devDependencies and config files from your favourite presets, instead of copy and paste!

Topics

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

โšก