This script automates the creation and registration of a new React component within a categorized directory structure. It also updates the router.jsx
file to import and route the new component.
Prompts the user to enter:
A category name (e.g., admin
, tools
)
A component name (e.g., Home
, Dashboard
)
Converts the component name to lowercase and removes spaces.
Capitalizes the first letter for use as a React component name.
Converts the category name to lowercase and removes spaces.
Displays the normalized category
, component
, and componentCap
(capitalized component name).
Checks if the category directory exists under:
src/components/guests/pages/tools/<category>
If not, it creates the directory.
Checks if the component file (<componentCap>.jsx
) exists inside the category directory.
If not, it creates the file.
Adds basic JSX boilerplate to the new component file:
function ComponentName () {
return (<div><h1>ComponentName Component</h1></div>)
}
export default ComponentName
src/router.jsx
)Uses sed
to insert an import line after the comment //IMPORTSAUTOGENERATED
:
import ComponentName from "./components/guests/pages/tools/category/ComponentName";
Uses sed
to insert a new route object after the marker AUTOGENERATEDROUTES
:
{ path: '/category/component', element: <ComponentName /> },
Opens the newly created component file in Visual Studio Code for immediate editing.
Each critical operation (import, route, boilerplate) checks for success and exits with an error message if it fails.
you must add the following comments for the location where you want the import and route to go. example:
Import:
Children Routes
Source: /f/apachefriends/xampp/htdocs/REACT/APPS/my-react-tools-mdb/appv3/my-react-tools-mdb