A node script to easily create both Functional and Class React components.
While building up my React projects I found myself creating the same directory structure for all the new components I would create. Each component consisted of a folder named the same as the component with two files, the index.js and the actual component with the name of the component as the name of the file. So this node script when run, will use inquirer to prompt and create said files for you.
project
│ README.md
│ ...
│
└───src
│ │ App.js
│ │ ...
│ │
│ └───components
│ │____Button
| | |__ Button.js
| | |__ index.js
│ │____NavBar
| | |____NavBar.js
| | |____index.js
│ │
│ └───pages
│ │ Landing.js
| | |____Landing.js
| | |____index.js
│ │ Search.js
| | |____Search.js
| | |____index.js
│ │ ...
- Clone this project and cd into it
git clone [email protected]:jtung23/create-react-components-script.git
cd create-react-components-script
-
With Ubuntu 16.04+ to set up executable (this works for my computer)
- Move
react-component
(not the .js file) to /usr/bin/- (example)
sudo mv react-component /usr/bin/
- Mac:
/usr/local/bin
- (example)
- Restart terminal and test with command,
react-component
- Will prompt for class/function component and name
- Move
-
To set up executable for other systems
- pkg
npm install -g pkg
- This package allows you to create the exectuable file for linux, macos, and windows