Bunli
Packages

create-bunli

Scaffold new Bunli CLI projects with ease

create-bunli

Scaffold new Bunli CLI projects in seconds with built-in templates and full customization support.

Quick Start

bunx create-bunli my-cli
npm create bunli@latest my-cli
yarn create bunli my-cli
pnpm create bunli my-cli

Features

  • ๐Ÿš€ Fast scaffolding - Get started in seconds
  • ๐Ÿ“ฆ Multiple templates - Choose from basic, advanced, or monorepo setups
  • ๐Ÿ”ง TypeScript ready - Full TypeScript support out of the box
  • ๐Ÿงช Testing included - Comes with @bunli/test for CLI testing
  • ๐ŸŽจ Best practices - Follows Bunli conventions and patterns
  • ๐ŸŒ External templates - Use any GitHub repository as a template
  • ๐Ÿ’พ Offline support - Works offline with cached templates

Usage

Interactive Mode

Run without arguments for a guided experience:

bunx create-bunli

You'll be prompted for:

  • Project name
  • Directory location
  • Template selection
  • Package manager preference

Command Line Mode

Specify options directly:

bunx create-bunli my-cli --template advanced --package-manager pnpm

Options

OptionShortDescriptionDefault
--template-tProject templatebasic
--dir-dDirectory to create project in./{name}
--package-manager-pPackage manager (bun, npm, yarn, pnpm)bun
--git-gInitialize git repositorytrue
--install-iInstall dependenciestrue
--offlineUse cached templates when availablefalse

Built-in Templates

Basic Template

Default

Perfect for simple CLI tools with a single command.

View structure
my-cli/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ index.ts         # CLI entry point
โ”‚   โ””โ”€โ”€ commands/
โ”‚       โ””โ”€โ”€ hello.ts     # Example command
โ”œโ”€โ”€ test/
โ”‚   โ””โ”€โ”€ hello.test.ts    # Example test
โ”œโ”€โ”€ bunli.config.ts      # CLI configuration
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ tsconfig.json
โ””โ”€โ”€ README.md

Features:

  • Single command setup
  • TypeScript configuration
  • Test setup with @bunli/test
  • Build script using bunli
  • Essential dependencies only
bunx create-bunli my-cli --template basic

Advanced Template

For complex CLIs with multiple commands and features.

View structure
my-cli/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ index.ts         # CLI entry point
โ”‚   โ”œโ”€โ”€ commands/        # Command implementations
โ”‚   โ”‚   โ”œโ”€โ”€ index.ts     # Command manifest
โ”‚   โ”‚   โ”œโ”€โ”€ init.ts      # Initialize configuration
โ”‚   โ”‚   โ”œโ”€โ”€ validate.ts  # File validation
โ”‚   โ”‚   โ”œโ”€โ”€ serve.ts     # Development server
โ”‚   โ”‚   โ””โ”€โ”€ config.ts    # Configuration management
โ”‚   โ””โ”€โ”€ utils/          # Utility functions
โ”‚       โ”œโ”€โ”€ config.ts
โ”‚       โ”œโ”€โ”€ validator.ts
โ”‚       โ””โ”€โ”€ glob.ts
โ”œโ”€โ”€ test/
โ”œโ”€โ”€ bunli.config.ts
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ tsconfig.json
โ””โ”€โ”€ README.md

Features:

  • Multiple commands with subcommands
  • Configuration management system
  • File validation with rules
  • Built-in development server
  • License selection during setup
  • Rich utility functions
bunx create-bunli my-cli --template advanced

Monorepo Template

For large projects with multiple packages.

View structure
my-cli/
โ”œโ”€โ”€ packages/
โ”‚   โ”œโ”€โ”€ cli/            # Main CLI package
โ”‚   โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ””โ”€โ”€ package.json
โ”‚   โ”œโ”€โ”€ core/           # Core functionality
โ”‚   โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ””โ”€โ”€ package.json
โ”‚   โ””โ”€โ”€ utils/          # Shared utilities
โ”‚       โ”œโ”€โ”€ src/
โ”‚       โ””โ”€โ”€ package.json
โ”œโ”€โ”€ turbo.json          # Turborepo config
โ”œโ”€โ”€ package.json        # Root package.json
โ”œโ”€โ”€ tsconfig.json       # Root TypeScript config
โ”œโ”€โ”€ .changeset/         # Changeset config
โ””โ”€โ”€ README.md

Features:

  • Turborepo configuration
  • Multiple packages with workspace setup
  • Shared dependencies management
  • Changeset support for versioning
  • Parallel builds and testing
  • Optimized for scalability
bunx create-bunli my-cli --template monorepo

External Templates

Use any GitHub repository as a template:

GitHub Templates

# Short format
bunx create-bunli my-cli --template username/repo

# Full GitHub format
bunx create-bunli my-cli --template github:username/repo

# Specific branch or tag
bunx create-bunli my-cli --template username/repo#branch

NPM Templates

bunx create-bunli my-cli --template npm:template-package

Local Templates

bunx create-bunli my-cli --template ./path/to/template
bunx create-bunli my-cli --template file:./path/to/template

Creating Custom Templates

Build your own templates with variable substitution and custom logic.

Template Structure

A template is any directory with files that will be copied and processed. Add a template.json for advanced features:

{
  "name": "my-template",
  "description": "My custom Bunli template",
  "variables": [
    {
      "name": "projectName",
      "message": "Project name",
      "type": "string",
      "default": "my-project"
    },
    {
      "name": "license",
      "message": "License",
      "type": "select",
      "choices": [
        { "label": "MIT", "value": "MIT" },
        { "label": "Apache 2.0", "value": "Apache-2.0" },
        { "label": "GPL 3.0", "value": "GPL-3.0" }
      ]
    }
  ],
  "files": {
    "include": ["**/*.ts", "**/*.json"],
    "exclude": ["node_modules", ".git"]
  },
  "hooks": {
    "postInstall": ["npm run build"]
  }
}

Variable Substitution

Templates support multiple variable formats:

FormatExampleUsage
Handlebars{{projectName}}Most common
EJS<%= projectName %>Alternative
Shell$projectNameScripts
Python__projectName__File names

Available Variables:

  • {{projectName}} - The project name
  • {{description}} - Project description
  • {{author}} - Author name
  • {{license}} - License type
  • {{year}} - Current year
  • {{packageManager}} - Selected package manager

File Name Variables

Use variables in file names:

templates/
โ””โ”€โ”€ my-template/
    โ”œโ”€โ”€ __projectName__.config.js  # Becomes my-app.config.js
    โ””โ”€โ”€ src/
        โ””โ”€โ”€ __projectName__.ts     # Becomes my-app.ts

Variable Types

{
  "name": "apiKey",
  "message": "API Key",
  "type": "string",
  "default": ""
}
{
  "name": "useTypeScript",
  "message": "Use TypeScript?",
  "type": "boolean",
  "default": true
}
{
  "name": "port",
  "message": "Default port",
  "type": "number",
  "default": 3000
}
{
  "name": "framework",
  "message": "Choose framework",
  "type": "select",
  "choices": [
    { "label": "Express", "value": "express" },
    { "label": "Fastify", "value": "fastify" }
  ]
}

Advanced Usage

Programmatic API

Use create-bunli programmatically:

import { createProject } from 'create-bunli'

await createProject({
  name: 'my-cli',
  template: 'advanced',
  dir: './projects/my-cli',
  packageManager: 'bun',
  install: true,
  git: true,
  offline: false
})

Offline Mode

Work offline with cached templates:

# Use cached template if available
bunx create-bunli my-cli --offline

# Force offline mode (fail if not cached)
GIGET_FORCE_OFFLINE=1 bunx create-bunli my-cli

Custom Directory

Create project in a specific location:

# Create in current directory
bunx create-bunli . --template advanced

# Create in custom path
bunx create-bunli my-cli --dir ~/projects/my-cli

Examples

Create a simple CLI

bunx create-bunli todo-cli
cd todo-cli
bunli dev

Create with all options

bunx create-bunli weather-cli \
  --template advanced \
  --package-manager pnpm \
  --dir ~/tools/weather-cli \
  --git \
  --install

Use external template

bunx create-bunli my-app \
  --template pvtnbr/bunli-starter \
  --package-manager npm

Create without prompts

bunx create-bunli api-cli \
  --template monorepo \
  --no-git \
  --no-install

Troubleshooting

Template not found

If you get a "template not found" error:

  • Check the template name spelling
  • For GitHub templates, ensure the repository exists and is public
  • For local templates, verify the path exists
  • Try with --offline if you've used the template before

Installation fails

If dependency installation fails:

  • Check your internet connection
  • Ensure the package manager is installed
  • Try with --no-install and install manually
  • Clear package manager cache

Permission errors

If you get permission errors:

  • Ensure write access to the target directory
  • Try a different directory
  • Check available disk space
  • Run with appropriate permissions

Variable substitution not working

If template variables aren't replaced:

  • Check variable syntax (use {{variable}} format)
  • Ensure variables are defined in template.json
  • Verify file is not in excluded patterns
  • Check file encoding (UTF-8 required)

Pro tip: Create your own organization template and share it with your team using GitHub repositories!

Next Steps

On this page