Skip to content

dominicchapman/spike-cli-generation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spike CLI Generation

This repo explores a few options for generation of code from templates.

Out-of-the-box Plop CLI

Plop is a popular generation framework that glues together Inquirer for CLI prompts and Handlebars for creating templates.

The ootb-plop-cli workspace shows how Plop can be used to generate a design system primitive. We provide a template like the __templates__/primitive directory, a plopfile.ts configuration and call the gen:primitive command to generate a primitive with the name of our choosing.

Hygen

Hygen is a code generator that stitches together Enquirer for CLI prompts and Embedded JavaScript templates for creating templates.

The hygen workspace shows how Hygen can be used to generate a design system primitive. After initializing Hygen with npx hygen init self we can use the new generator that is generated for us (so meta) to create our own generators. We create a primitive generator with npx hygen generator new primitive, fill the contents of the primitive/new directory with desired output and make use of Hygen helpers and inflections within the EJS to craft the output.

Prior Art

  • Bison templates using Hygen
  • Redwood custom generation from .tsx template
  • Comparison between Hygen and Plop from Bison author

General Thoughts

Using Handlebars and EJS makes for a poor DX, with error prone text editor format-on-save and lack of linting. Reaching for fully custom CLI like the Redwood example linked could improve DX, but we would lose the benefits of the templating engines (conditionals, case modifiers, etc.).

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors