1.1.4 • Published 7 months ago

@dannywrayuk/cookie-cutter v1.1.4

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

With Cookie Cutter you can generate code, files, and folders using a directory as your template. It uses handlebars and prompts under the hood to ask the user for information and then populate the template. This library should speed up your workflow anytime you find yourself writing boilerplate. It works great for anything from react components to entire projects.

Install

Installation is not required for one time use, you can simply execute this package as a script eg npx @dannywrayuk/cookie-cutter. However, if you intend on using this script multiple times, it would decrease execution time by installing the dependency.

Use your favourite package manager

Using npm:

$ npm install @dannywrayuk/cookie-cutter

Using yarn:

$ yarn add @dannywrayuk/cookie-cutter

Using pnpm:

$ pnpm add @dannywrayuk/cookie-cutter

Usage

All uses of Cookie Cutter are going to look something like this:

$ @dannywrayuk/cookie-cutter <template-directory> <output-directory>

Where template-directory is the path of a template containing a valid template.config.json, and output-directory is a path to the desired output destination of the generated content.

The Template

The template must be contained inside a directory and contain all the files and folders that should be created at the output. The file names, directories, and file content may all contain handlebar expressions that will be resolved using data collected from user prompts. Helpers are available to help with the generation of data from the user input, eg changing the casing of the input. Currently string and date are used from handlebar-helpers

Template Config

All valid templates must contain a template.config.json at their root, this is to guide Cookie Cutter when generating your content. This primary purpose of this config is to list the user questions - these are needed to prompt the user and gather required template variables. An example config:

{
  "questions": [
    {
      "type": "text",
      "name": "name",
      "message": "What is your name?",
      "initial": "Danny"
    }
  ]
}

where each question in the array is a prompt type defined by prompts.

Options

$ @dannywrayuk/cookie-cutter <template-directory> <output-directory> <...extra>

template-directory

The path to a template, or a directory containing multiple templates. If the folder contains multiple templates the user will be prompted to select a template. Defaults to the current directory when not supplied.

output-directory

The desired output path, or a new folder name. This is the location the content will be created in. However, if a folder name is provided that does not already exist, a directory of that name will first be created. This folder name is also passed into the generator and will override the name parameter in the template config.

Optionally the output directory can also contain handlebar expressions such as output/{{service-type}}/ and the expression will be resolved before generation begins.

...extra

The answers to any user prompts can be manually passed as arguments to Cookie Cutter and these prompts will be skipped when generating. An override for name would be:

$ @dannywrayuk/cookie-cutter <template-directory> <output-directory> --name Danny

Contribution

If there is an option or feature you would like to see, please feel free to raise an issue or open a pull request. Contributions are welcome :)

License

MIT © Danny Wray

1.1.4

7 months ago

1.1.3

10 months ago

1.1.2

10 months ago

1.1.1

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

1.0.2

11 months ago

1.0.1

11 months ago