It's fairly trivial to create a React project, but there's always a big hurdle between creating it locally and making it shareable so that someone else can run it. This lesson walks you through the process of automating creating a React project locally, creating the repository where it's going to be hosted, and creating shareable links where it can be run so that you can quickly and easily create single one-off demos and shoot them over to your friends and coworkers for sharing your code ideas in a working environment.
share-react-project() {
if [[ -z "$1" ]]; then
echo "Usage: share-react-project <project_name>"
return 1
fi
local project_name="$1"
local github_username=$(gh api /user --jq '.login')
echo "Creating Vite project: $project_name"
pnpm create vite "$project_name" --template react
cd "$project_name"
echo "Initializing Git repository"
git init
echo "Adding all files to Git"
git add .
echo "Creating initial commit"
git commit -m "Initial commit"
local codesandbox_link="https://codesandbox.io/p/github/${github_username}/${project_name}"
echo "Adding CodeSandbox link to README.md"
echo "" >> README.md
echo "## CodeSandbox" >> README.md
echo "[![Open in CodeSandbox](https://assets.codesandbox.io/github/button-edit-blue.svg)](${codesandbox_link})" >> README.md
echo "Adding README.md to Git"
git add README.md
echo "Committing README.md changes"
git commit -m "Add CodeSandbox link"
echo "Creating GitHub repository: $github_username/$project_name"
gh repo create "$github_username/$project_name" --public
echo "Pushing to remote 'origin'"
git push -u origin main
echo "Project '$project_name' created successfully!"
echo "GitHub repository: https://github.com/$github_username/$project_name"
echo "CodeSandbox link: $codesandbox_link"
}
Usage:
share-react-project demo-project
标签:project,GitHub,Creating,md,echo,Project,github,README,name From: https://www.cnblogs.com/Answer1215/p/18624324