vite-react-cli-tool
v1.0.2
Published
Create a react project with a folder structure that respects the hexagonal architecture
Downloads
21
Readme
vite-react-cli-tool
vite-react-cli-tool
is a command-line tool designed to scaffold React projects with a predefined hexagonal architecture. It sets up essential folders and integrates optional dependencies like Tailwind CSS, Redux Toolkit, and React Router, allowing for a faster and more structured development process.
Features
- Scaffold React projects with a Vite + React template.
- Hexagonal architecture setup with standard folders for modular organization:
assets
,components
,modules
,routes
,store
. - Optional dependency setup for Tailwind CSS, Redux Toolkit, and React Router with simple flags.
Installation
To install vite-react-cli-tool
globally run:
npm install -g vite-react-cli-tool
Usage
To create a new React project with the hexagonal architecture:
vbc create <project-name> [options]
Replace <project-name>
with the desired name of your project. You can add optional flags to include Tailwind CSS, Redux Toolkit, and React Router.
Available Flags
--tw
: Adds Tailwind CSS setup, with the main CSS file configured asindex.css
.--rtk
: Sets up Redux Toolkit with a basic store and example slice.--rr
: Configures React Router with basic routing and sample pages.
Example Command
vbc create my-new-app --tw --rtk --rr
This command will create a new Vite React project named my-new-app
with Tailwind CSS, Redux Toolkit, and React Router preconfigured.
Explanation of the Flags
Tailwind CSS (--tw
flag)
When using the --tw
flag, the tool will:
- Install Tailwind CSS and required dependencies (
postcss
andautoprefixer
). - Generate a
tailwind.config.js
file and configure it with the content paths for Tailwind to scan. - Add an
index.css
file insrc/assets/
with the necessary Tailwind directives (@tailwind base
,@tailwind components
, and@tailwind utilities
).
NB: the index.css
file in src/assets/
is the file you should import in App.tsx
Redux Toolkit (--rtk
flag)
When using the --rtk
flag, the tool will:
- Install Redux Toolkit (
@reduxjs/toolkit
) and React-Redux (react-redux
). - Create a Redux store configuration in
src/store/create-store.ts
. - Add an example slice (
exampleSlice.ts
) insrc/modules/slice/
with basic actions, demonstrating Redux setup.
React Router (--rr
flag)
When using the --rr
flag, the tool will:
- Install
react-router-dom
for routing. - Set up routing in
src/routes/ROUTER.tsx
with sample paths. - Create route definitions in
src/routes/routes.ts
. - Add two sample pages (
Home.tsx
andAbout.tsx
) insrc/pages/
to demonstrate routing.
Project Structure
The generated project will have the following structure:
my-new-app/
├── src/
│ ├── __e2e__/ # End-to-end testing files
│ ├── assets/ # Static files (images, fonts, etc.)
│ ├── components/ # Reusable UI components
│ ├── modules/ # Core application logic, organized by domain
│ │ ├── __tests__/ # Unit and integration tests for modules
│ │ ├── infra/ # Infrastructure layer (APIs, data sources)
│ │ ├── models/ # Data models and types
│ │ ├── slice/ # Redux slices and state
│ │ │ └── exampleSlice.ts # Example Redux slice with actions
│ │ ├── use-case/ # Business logic and use cases
│ └── reducer.ts # Root reducer that combines the module reducers
│ ├── routes/ # Routing configuration
│ │ ├── ROUTER.tsx # Main router component
│ │ └── routes.ts # Route definitions and path configurations
│ └── pages/ # Application pages (e.g., Home, About)
│ ├── Home.tsx # Sample Home page
│ └── About.tsx # Sample About page
│ └── store/ # Redux store setup
│ └── create-store.ts # Store configuration
Commands
create <project-name>
Scaffolds a new React project with a hexagonal architecture and optional configurations.
Example:
vbc create my-new-app --tw --rtk --rr
This initializes a Vite React project named my-new-app
with Tailwind CSS, Redux Toolkit, and React Router configurations.
Contributing
To contribute to vite-react-cli-tool
, follow these steps:
- Fork the repository.
- Clone your forked repository.
- Make your changes and commit them.
- Create a pull request.
Development Setup
To work on the tool locally:
Clone the repository:
git clone <your-fork-url>
Install dependencies:
npm install
Build the TypeScript files:
npm run build
Link the package locally to test it:
npm link
Test the tool by running
vbc
commands from anywhere on your system.
License
This project is licensed under the ISC License.