1.1.0 • Published 3 years ago

@tristanwritescode/react-gen v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

React-Gen

An extensible file scaffolder for any web project but made with React in mind since Angular already has a great code gen tool.

Installation

npm install -g @tristanwritescode/react-gen

Usage

react-gen [command] [templateNameOrShortcut] [...paths]
  • If command is omitted, gen is assumed.
  • Multiple paths can be provided to generate multiple template instances

Create a settings file (optional)

react-gen init

Scaffold the functional-component template

react-gen gen functional-component components/some/path/my-component

or

react-gen gen fc components/some/path/my-component

or

react-gen fc components/some/path/my-component components/some/path/other-component

Configuration

Create a json file named .react-gen at your package.json level, or use the init command.

Settings schema

PropertyDescriptionDefault
basePathAn absolute path from the settings file for which template paths should be relative to."src"
templatesAn array of custom templates to be merged with existing templatesN/A
directoryForTemplateGiven a path "routes/my-component"; true will create a my-component directory and place the template files in there, false will place template files directly in the routes directory.true
directoryCasingCase conversion option for directory names. One of kebabCase, camelCase, pascalCase"kebabCase"
fileCasingCase conversion option for file names. One ofkebabCase, camelCase, pascalCase"pascalCase"

Template schema

PropertyDescription
nameThe name of the template. If this name matches an existing template it will override that template.
shortcutA shortcut value for the template. (Optional)
filesAn array of paths to files for this template. Can be absolute or relative to the settings file.
fileCasingOverrides the file casing setting for just this template.
directoryCasingOverrides the directory casing setting for just this template

Custom templates

File naming

Template files should be named file.[ext].mustache. The file portion will be replaced with the last segment of the provided template path. The .mustache extension will be removed.

Eg. routes/my-component with the file name file.tsx.mustache will result in the file name MyComponent.tsx assuming the default fileCasing of pascalCase

File template

The templates themselves are mustache templates. The model available has the following properties.

PropertyDescription
directoryThe directory path for the template as determined by directoryCasing and directoryForTemplate settings
fileNameThe file portion of the file name as determined by the fileCasing setting.
kebabNameThe name of the template formatted in kebab case
camelNameThe name of the template formatted in camel case
pascalNameThe name of the template formatted in pascal case

Example

See functional-component

1.1.0

3 years ago

1.0.0

3 years ago

0.5.1

4 years ago

0.5.0

4 years ago

0.4.0

5 years ago

0.3.0-alpha

5 years ago

0.2.0

5 years ago

0.1.4

5 years ago

0.1.1-alpha

5 years ago

0.1.3

5 years ago

0.1.0-alpha

5 years ago