2.1.7 • Published 11 months ago

@dddstack/droplet v2.1.7

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

@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 init

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

droplet file

Template

Drop a Droplet template to a location:

npx droplet template

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:

2.1.7

11 months ago

1.0.1

1 year ago

1.0.0

1 year ago

2.1.2

1 year ago

2.1.1

1 year ago

2.1.4

1 year ago

2.1.3

1 year ago

2.1.6

1 year ago

2.1.5

1 year ago

2.1.0

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago