The script will allow creating a new component in the folder src/components
. If the given path ends with a component name (detection is made if the last part of the path is in PascalCase), then it will detect the new component created is a sub-component and put it in an subComponents
folder. A new export
is automatically added (and sorted alphabetically) into the index.js
file of the parent folder.
validFolders
→ List of folders where a new component can be createdsubComponentFolderName
→ Name of the folder for sub-components
Initial folder structure:
src/
└── components/
├── Parent/
│ └── Parent.js
└── index.js
Initial src/components/index.js
:
export { default as Parent } from "./Parent/Parent";
Creating a new component:
node ".bin/create-component.sh"
Enter folder path: src/components
Enter component name: NewParent
New folder structure:
src/
└── components/
├── NewParent/
│ └── NewParent.js
├── Parent/
│ └── Parent.js
└── index.js
New src/components/index.js
:
export { default as NewParent } from "./NewParent/NewParent";
export { default as Parent } from "./Parent/Parent";
Creating a new sub-component:
node ".bin/create-component.sh"
Enter folder path: src/components/NewParent
Enter component name: NewChild
New folder structure:
src/
└── components/
├── NewParent/
│ ├── subComponents/
│ │ ├── NewChild/
│ │ │ └── NewChild.js
│ │ └── index.js
│ └── NewParent.js
├── Parent/
│ └── Parent.js
└── index.js