Skip to content

CLI tool to generate React components from templates

License

Notifications You must be signed in to change notification settings

aleksandryackovlev/crc

Repository files navigation

CRC - Create React Component

Build Status GitHub release GitHub
An easy to use cli-tool that simplifies the process of creation of React components.

Installation

$ git clone https://github.com/aleksandryackovlev/crc.git
$ cd crc
$ make install

crc create

Create React component

Synopsis

crc create [-f] [-s] [-t <TEMPLATE>] [-d <DIRECTORY>] [ -l <LIFECYCLE_METHODS>]
    [-h <HANDLERS>] [-m <METHODS>] <COMPONENT_NAME> [<PROPS>]

Description

If the placeholder for an option is not defined in a template, this option will not appear in the resulting file even if it is set in the command.

Options

-f
     Create a file component.

-s
     Add styles to a new component. This option is ignored if -f options is set.

-t <TEMPLATE>
     Create a component from the template with the name <TEMPLATE>. By default it is set to the "default" template.

-d <DIRECTORY>
     Create a component in the <DIRECTORY>. By default it is set to the current working directory.

-l <LIFECYCLE_METHODS>
     Add a given list of lifecycle methods. Methods should be given as a string that consits of method names separated by colons.

-h <HANDLERS>
     Add a given list of arrow functions. Handlers should be given as a string that consits of their names separated by colons.

-m <METHODS>
     Add a given list of methods. Methods should be given as a string that consits of their names separated by colons.

<COMPONENT_NAME>
     The name of a component that should be created written in camelcase.

<PROPS>
     A list of props that should be added to a component. Every prop should be written as a separate parameter and should consist of the name, propType and defaultProp separated by colons. If a defaultProp is not given the prop is considered as a required one.

Examples

Create a directory with the SomeComponent component from the default template:

$ crc create SomeComponent

Create a directory with the SomeComponent component from the "some-template" template:

$ crc create -t some-template SomeComponent

Create a file component from the "some-template" template:

$ crc create -t some-template -f SomeComponent

Create a directory with the SomeComponent component from the "some-template" template adding styles:

$ crc create -t some-template -s SomeComponent

Create a directory with the SomeComponent component from the "default" template adding a given list of props:

$ crc create SomeComponent "somePropName:PropType:defalutValue"

Create a directory with the SomeComponent component from the "default" template adding a given list of lifecycle methods:

$ crc create -l "componentDidMount:componentWillUnmount" SomeComponent

Create a directory with the SomeComponent component from the "default" template adding a given list of handlers:

$ crc create -h "handleChange:handleClick" SomeComponent

Create the SomeComponent component with a given list of handlers:

$ crc create -m "handleChange:handleClick" SomeComponent

crc config

Create, edit or delete local crc config files for different directories

Synopsis

crc config <COMMAND> [<DIRECTORY>]

Description

The command handles local config files. If there is no config file in PWD, it is going to be looked for in ancestor directories. The first file, that is found in a list of ancestor directories, is considered as the active local config. Config files are going to be edited in the default EDITOR.

Commands

create [<DIRECTORY>]
     Create a local config file component. By default <DIRECTORY> is set to PWD

edit
     Edit the active local config file component if it exits.

delete
     Delete the active local config file component if it exits.

Examples

Create a config file in a current directory:

$ crc config create 

Edit the active config file if it exists:

$ crc config edit 

Delete the active config file if it exists:

$ crc config delete 

crc template

Create, read, update or delete templates

Synopsis

crc template <COMMAND> [-n] [-j <JS_FILE_EXTENTION>] [-s <CSS_FILE_EXTENTION>] <TEMPLATE>

Description

The command handles template files. Template files are going to be edited in the default EDITOR.

Commands

create <TEMPLATE>
     Create a new template with the name <TEMPLATE>.
    Options:
    -n
         Create a template without opening its files in the EDITOR.

    -j <JS_FILE_EXTENTION>
         Set the extention of a component template. By default it is set to "js".

    -s <CSS_FILE_EXTENTION>
         Set the extention of a styles template. By default it is set to "css".

copy <OLD_TEMPLATE> <NEW_TEMPLATE>
     Copy files from the <OLD_TEMPLATE> to <NEW_TEMPLATE>.

edit <TEMPLATE>
     Edit files for the <TEMPLATE> if this template exits.

delete <TEMPLATE>
     Delete the <TEMPLATE> if this template exits.

Examples

Create a new template:

$ crc template -j jsx -s sass create some_template

Edit the "some_template":

$ crc template edit some_template

Delete the "some_template":

$ crc config template delete some_template 

crc help

Show help info

Synopsis

crc help [<COMMAND>]

Examples

Show version:

$ crc help version

Show usage info:

$ crc help usage

Show help info on the crc-create command:

$ crc help create