@dddstack/droplet v2.1.7
@dddstack/droplet
A simple code generation tool for complex codebases.
Overview
Droplet makes code generation consistent, reusable, and simple. At its core, Droplet is a link between Handlebars templates and CLI prompts.
Installation
npm install @dddstack/droplet -D
Initialization
Run the following command to initialize Droplet:
npx droplet init
Droplet will create a basic droplet
directory with an example file and template.
Droplet Directory
Droplet automatically reads all Droplet files and templates in the droplet
directory. To create files and templates, follow the Droplet naming convention:
- droplet_directory_*: Directory
- droplet_file_*.hbs: Droplet file
- droplet_template_*: Droplet template
For example, a droplet
directory structure could look like:
├── droplet
│ ├── droplet_directory_docs
│ │ ├── droplet_file_README.md.hbs
│ │ └── droplet_file_README.md.fr.hbs
│ ├── droplet_file_index.ts.hbs
│ ├── droplet_template_package
│ │ ├── droplet_file_index.ts.hbs
└─└─└── droplet_file_package.json.hbs
Commands
File
Drop a Droplet file to a location:
npx droplet file
Template
Drop a Droplet template to a location:
npx droplet template
Droplet Value
To take advantage of Handlebars, use {{droplet}}
in Handlebars templates:
├── droplet
│ ├── droplet*template*{{droplet}}
└─└──└─ droplet_file_index.ts.hbs
// droplet_file_index.ts
export const droplet = {{droplet}};
Droplet prompts for an optional value that will be inserted into all mentions of {{droplet}}
.
Wrapping Droplet
Under the hood, Droplet is simply a Commander instance and can be easily extended.
npm install @dddstack/droplet-core
import { droplet } from "@dddstack/droplet-core";
export const program = droplet({
// looks for droplet directory in fromDirectory
// defaults to cwd()
fromDirectory: "./files",
// location prompt appends starts paths with toDirectory
// defaults to cwd()
toDirectory: "./src"
});
program.command("command").action(() => console.log("command"));
For a comprehensive example of wrapping Droplet, see @ddddurk/cli.
Acknowledgements
Droplet acknowledges the hard work put into these great projects: