0.3.3 • Published 4 years ago

react-code-creator v0.3.3

Weekly downloads
22
License
MIT
Repository
github
Last release
4 years ago

React Code Creator

Summary

A lightweight tool to create boilerplate code for common React files.

React Code Creator is a simple implementation of plop.js for common React files.

React Code Creator supports creating the following types of React files:

  • Views (jsx or tsx)
  • Services
  • Contexts
  • Models (when using typescript)
  • Includes css and test spec files
  • Redux reducers
  • Actions
  • Storybook stories

Install

npm install react-code-creator --save-dev

Or

yarn add react-code-creator --dev

Using

Config file

React Code Creator uses a react-code-creator.config.yaml file (which you should place at your project's root directory) to determine how to generate certain files. The config file should automatically be added to your root folder after installation with npm.

The config file has the following properties:

useTypescript: # Default: false
generateCss: # Default: true
generateTests: # Default: true
generateInterfaces: # Default: false
generateStories: # Default: false
generatePropTypes: false # true or false. Default is false
generateTypescriptProps: false # true or false. Default is false
cssExtension: # Default: "css"
testExtension: # Default: "spec"
root: # Default: "./src"
viewPath: # Default "views"
modelPath: # Default "models"
servicePath: # Default "services"
contextPath: # Default "contexts"
fileCase: # Default "camel"
pathCase: # Default "camel"
useSemicolons: # Default true
PropertyDescriptionPossible ValuesDefault
useTypescriptWhether to create typescript files (.tsx, .ts)true or falsefalse
generateCssWhether to generate css files when creating componentstrue or falsetrue
generateTestsWhether to generate test spec files when creating components and servicestrue or falsetrue
generateInterfacesWhether to generate interfaces when creating servicestrue or falsefalse
generateStoriesWhether to generate Storybook stories when creating componentstrue or falsefalse
generatePropTypesWhether to generate React.PropTypes when creating componentstrue or falsefalse
generateTypescriptPropsWhether to generate Typescript props when creating componentstrue or falsefalse
cssExtensionDefine the type of css file to generate"css", "scss", "less", "sass""css"
testExtensionThe file extension for test spec files"spec" or "test""spec"
rootThe root directory for your source code (where React Code Creator will place the generated files)any filepath string"./src"
viewPathWhere in the root directory to place autogenerated viewsany filepath string"views"
modelPathWhere in the root directory to place autogenerated modelsany filepath string"models"
servicePathWhere in the root directory to place autogenerated servicesany filepath string"services"
contextPathWhere in the root directory to place autogenerated contextsany filepath string"contexts"
fileCaseCasing type to try and enforce when creating file names"camel", "pascal", "dash", "snake", "dot""camel"
pathCaseCasing type to try and enforce when creating file paths"camel", "pascal", "dash", "snake""camel"
useSemicolonsWhether to use semicolons in generated filestrue or falsetrue

Casing Examples (fileCase and pathCase)

  • camel: camelCaseNames
  • pascal: PascalCaseNames
  • dash: dash-case-names
  • snake: snake_case_names
  • dot: dot.case.names

Running

After installing, React Code Creator should add a new script to your package.json file.

Run npm run new to begin the CLI

Skipping prompts

If you already know the values you would like to provide the CLI, you can add them as args

For example: npm run new componenent myComponent

Commands

You can see the full list of commands by running npm run new

Changing the Run command

You can change the command from new by updating the scripts section of your package.json file.

Naming Conventions

When creating certain files, React Code Creator will use the exact name you specify as the filename. This is the case when creating a Component, Model, or a Service

For example:

  • Creating component / class component: userProfile -> userProfile
  • Creating model: user -> user
  • Creating service: userFetcher -> userFetcher

But when creating a Context or Reducer, React Code Creator will append Context or Reducer to the filename, so don't include them when naming them!

For example:

  • Creating context: user -> userContext
  • Creating a reducer: user -> userReducer

Troubleshooting

Avoid frequently changing the config

React Code Creator relies on regex patterns to track and modify some generated files. Avoid changing the config parameters (such as file casing patterns, directories, or enabling/disabling typescript) to avoid errors related to locating previously generated files.

License

You may use React Code Creator under the MIT license