As developers, we often find ourselves spending too much time repeatedly setting up new projects. While the steps to initialize a project may be simple, automating them can significantly speed up the process, allowing us to focus on what we loveβcoding! In this post, Iβll share a shell script I wrote to automate the setup of a React project with Vite, TypeScript, SWC, and Panda CSS.
Why Automate? βοΈ
Manually setting up new projects each time can be tedious, especially when youβre working with multiple technologies like React, TypeScript, and Panda CSS. To streamline this process, I wrote a script called friday.sh, which automates the entire setup for a new React app. π The script allows you to quickly initialize a new React project, install dependencies like Axios and React Router DOM, and configure Panda CSSβall with a single command.
What Does the Script Do? π
Hereβs what friday.sh takes care of:
β’ π₯οΈ Initializes a React project using Vite with TypeScript and SWC.
β’ πΌ Installs Panda CSS, Axios, and React Router DOM.
β’ β¨ Updates the CSS file with layers for Panda CSS.
β’ π§ Configures package.json and panda.config.ts files.
β’ π Provides options to use your preferred package manager (pnpm, npm, or yarn).
Features π
β’ Automatic Setup: π The script handles the full setup of your React project, from creating the project to installing all necessary dependencies.
β’ Package Manager Choice: You can choose between pnpm, npm, and yarn. By default, it uses pnpm, but you can specify a different one if needed.
β’ Panda CSS Integration: πΌ Panda CSS is installed and integrated into the project. It even updates your index.css file to include Pandaβs base CSS layers.
How to Use π
Run the script with the following syntax:
./friday.sh -d <directory> [-p <package-manager>] [-h]
- -d : π The directory where the React project will be created.
- -p : (Optional) The package manager to use (pnpm, npm, or yarn). Defaults to pnpm.
- -h: (Optional) Prints the help message and exits.
Example Usage π‘
- To initialize a React project in a specified directory using the default package manager (pnpm):
./friday.sh -d /path/to/project-directory
- To initialize a React project using a specific package manager (e.g., npm):
./friday.sh -d /path/to/project-directory -p npm
- To display the help message:
./friday.sh -h
Script Breakdown π οΈ
Hereβs a step-by-step breakdown of what the script does:
- Directory Check: β Ensures that the target directory is specified and created if it doesnβt exist.
- Package Manager Verification: π Checks whether the specified package manager is installed on your system.
- Project Initialization: π₯οΈ Creates a new React project using Vite with TypeScript and SWC.
- Dependency Installation: π¦ Installs Panda CSS, Axios, and React Router DOM.
- CSS Configuration: π¨ Updates the index.css file to import Panda CSS layers.
- Package JSON Update: π Adds a script to package.json for Panda CSS code generation.
- Panda CSS Configuration: πΌ Updates panda.config.ts to include jsxFramework: "react".
- Final Setup: π Prints instructions to run the project.
Link to Github π
Github : friday.sh
Conclusion π
This script has saved me a significant amount of time when setting up new React projects, especially when integrating multiple technologies like Panda CSS. I encourage you to try it out and customise it for your own needs!
Feel free to share the feedback or leave a start on Github.
Top comments (0)