Skip to content

Instantly share code, notes, and snippets.

@cicorias
Created January 2, 2025 19:46
Show Gist options
  • Save cicorias/ed94089f3acadc7795febd3ff4bb9e21 to your computer and use it in GitHub Desktop.
Save cicorias/ed94089f3acadc7795febd3ff4bb9e21 to your computer and use it in GitHub Desktop.
script to create a react project in one command courtesy Egghead.io
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"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment