Containator
Generate customizable React Components following the Container/Presenter Pattern.
Installation
For better experience shake before use and install globally 🌏
yarn
yarn global add containator
npm
npm install -g containator
Usage
🚧 Warning: 🚧
Containator will create a folder with your component's name, if the folder is already created it won't create anything since it would be dangerous to overwrite.
Command:
containator <NameOfComponent>
Before you can use it create a containerOptions.json
file on the root folder of your project so you can customize the files that are gonna be generated, these are the options:
Name | Description | Type | Default |
---|---|---|---|
styles | Choose if you want to get a .css file created and imported to the presenter component or if you want an import to styled-components |
enum('styled','css') | css |
typescript | If you are using Typescript this option will create interfaces for both the class component on the container and the stateless component on the presenter, also .ts extensions. | boolean | false |
Example of containerOptions.json
file:
Example of usage
-
Go to the folder where you want to create the component:
nico@coder:~$ cd Components -
Run containator where 'Awesome' is the name of your component:
nico@coder:/Components$ containator Awesome -
Go inside to see the magic ✨
nico@coder:/Components$ cd Awesome && ls -
This will give you this folder structure with the default options:
Awesome├── AwesomeContainer.js├── AwesomePresenter.js├-- AwesomeStyles.css├── index.js
How do the files look like?
With the default options:
index.js:
;;
AwesomeContainer.js:
;;; static propTypes = {}; state = {}; { return <AwesomePresenter ...thisstate />; };
AwesomePresenter.js with CSS:
;;; const AwesomePresenter = "Make something awesome!"; AwesomePresenterpropTypes = {}; ;
AwesomePresenter.js with Styled Components:
;;; const AwesomePresenter = "Make something awesome!"; AwesomePresenterpropTypes = {}; ;
AwesomePresenter.js with Styled Components:
;;; const AwesomePresenter = "Make something awesome!"; AwesomePresenterpropTypes = {}; ;
With Typescript:
AwesomeContainer.tsx
;;; ;
AwesomeContainer.tsx with CSS
;;; ; SomethingPresenter.propTypes =; ;
Credits
This CLI was made with ❤️ by Nico from Nomad Coders , if you have any problems using it please open a pull request or contact me via slack.
Stay cool 😎, be happy 😬 and make beautiful stuff 💅🏻
~ Nico & Lynn