duck-template 0.1.5

A cli tool for generating files from a template just with a json file
duck-template-0.1.5 is not a library.

πŸ¦† duck-template

Generate and manage project templates with ease β€” fast, customizable, and powered by Rust.

duck-template helps you scaffold and manage projects using structured JSON configurations and flexible CLI commands. With variant support, remote configs, and dynamic flag injection, it gives you full control over how projects and their files are created.


✨ Features

  • 🧱 Template-based project scaffolding with JSON
  • πŸ—οΈ Variants to support different project layouts (e.g., api, web, cli)
  • 🌍 Remote or local config support (pass a URL or file path)
  • 🧠 Unified flag parsing with dynamic injection into templates
  • πŸͺΆ Blazing fast β€” written in Rust
  • πŸ“¦ Modular commands: init, create, and create-variant

πŸ“¦ Installation

cargo install duck-template

πŸš€ Quick Start

πŸ”§ Initialize a New Project

duck-template init --name my-app

This will:

  • Create a directory my-app/
  • Inject the name into templated files
  • Use your local duck-template.json file

πŸ—οΈ Create From a Variant

duck-template create --variant api --config ./duck-template.json

Or use a remote config:

duck-template create --variant api --config https://example.com/template.json

Optional extras:

duck-template create \
  --variant cli \
  --config ./template.json \
  --outdir ./output \
  --args author=Ahmed,year=2025

✨ Create a New Variant

duck-template create-variant \
  --source ./template-source \
  --name cli \
  --description "Command-line app setup" \
  --config ./duck-template.json

This will:

  • Package the folder into a new variant
  • Append it to the config (if valid and writable)

🧩 Configuration Format

You define templates in a duck-template.json file like this:

{
  "$schema": "https://zpgqhogoevbgpxustvmo.supabase.co/storage/v1/object/public/json/duck-template-schema.json",
  "name": "my-template",
  "version": "1.0.0",
  "description": "Reusable project setup",
  "outdir": "./output",
  "args": {
    "author": "Anonymous",
    "license": "MIT"
  },
  "variants": [
    {
      "name": "api",
      "description": "Express API starter",
      "files": [
        { "path": "src/index.ts", "content": "console.log('API ready');" },
        { "path": "tsconfig.json", "template": "tsconfig-template.json" }
      ]
    }
  ]
}

πŸ› οΈ Command Reference

πŸ”§ init

Create a new project directory.

duck-template init --name my-app
Flag Description
-n, --name Name of the project. Used for the folder name and inside templates.

πŸ—οΈ create

Generate files from a predefined variant.

duck-template create --variant api --config ./config.json
Flag Description
-v, --variant Name of the variant to generate
-d, --outdir Directory to write output (defaults to ./)
-c, --config Local or remote JSON config file
-a, --args Key=value overrides for template injection (e.g., author=Ahmed)

πŸ§ͺ create-variant

Package a folder into a new variant.

duck-template create-variant \
  --source ./starter \
  --name basic \
  --description "Basic setup" \
  --config ./duck-template.json
Flag Description
-s, --source Source directory or file
-n, --name Unique name for the variant
-d, --description Short explanation of what this variant is for
-c, --config Optional path to update an existing config file

πŸ“‚ Output Example

Given:

duck-template init --name wiseman

And this config:

{
  "name": "wiseman",
  "outdir": "./output",
  "variants": [
    {
      "name": "wiseman",
      "files": [
        { "path": "src/main.ts", "content": "console.log('{{name}} is wise');" }
      ]
    }
  ]
}

The result will be:

output/
└── src/
    └── main.ts   // console.log("wiseman is wise");

πŸ’¬ Help & Version

duck-template --help
duck-template --version

Also works with subcommands like:

duck-template init --help
duck-template create-variant --help

πŸ™Œ Contributions

Pull requests, issues, and suggestions are welcome! Feel free to fork, tweak, and share your own templates too.


πŸ¦† duck-template β€” because smart devs don’t start from scratch.