Skip to content

Instantly share code, notes, and snippets.

@sixman9
Last active April 14, 2024 14:19
Show Gist options
  • Save sixman9/a7c551ad330b266fef786a7888f5a53f to your computer and use it in GitHub Desktop.
Save sixman9/a7c551ad330b266fef786a7888f5a53f to your computer and use it in GitHub Desktop.
PNPM and Turbo-based Monorepo Bash script, with starter Cloudflare application
#!/bin/bash
# Check if jq is installed, if not, install it
if ! command -v jq &> /dev/null
then
echo "jq could not be found, installing..."
sudo apt-get install jq -y || sudo yum install jq -y || brew install jq
fi
# Check if pnpm is installed, if not, install it
if ! command -v pnpm &> /dev/null
then
echo "pnpm could not be found, installing..."
curl -fsSL https://get.pnpm.io/install.sh | sh -
fi
# Check if Git is installed, if not, install it
if ! command -v git &> /dev/null
then
echo "git could not be found, installing..."
sudo apt-get install git -y || sudo yum install git -y || brew install git
fi
# Create the root directory for the monorepo
mkdir my-monorepo
cd my-monorepo
# Initialize a new package.json
pnpm init
# Initialise Git
git init
curl -L https://www.toptal.com/developers/gitignore/api/remix+cloudflarepages,node,macos,linux,git,react,turbo -o ./.gitignore && echo 'curl done.'
# Create directories for libraries and applications with the correct names
mkdir packages apps
touch ./packages/.gitkeep
# Create pnpm-workspace.yaml with the correct folder structure
echo "packages:" > pnpm-workspace.yaml
echo " - 'packages/*'" >> pnpm-workspace.yaml
echo " - 'apps/*'" >> pnpm-workspace.yaml
# Add Turborepo configuration to package.json
jq '. + {turbo: {pipeline: {dev: {cache: false}, build: {dependsOn: ["^build"], outputs: ["build/**", "dist/**"]}}}}' package.json > package.json.tmp && mv package.json.tmp package.json
# Add scripts for Turborepo and preinstall script to package.json
jq '.scripts += {"dev": "turbo run dev", "build": "turbo run build", "preinstall": "npx only-allow pnpm"}' package.json > package.json.tmp && mv package.json.tmp package.json
#!/bin/bash
# Check if Git global email is set
git_email=$(git config --global user.email)
if [ -z "$git_email" ]; then
echo "Enter your Git global email:" >&2 # Output to standard error to ensure it shows on the terminal
read user_email < /dev/tty # Read input from the terminal
git config --global user.email "$user_email"
else
echo "Global email already set as: $git_email" >&2
fi
# Check if Git global name is set
git_name=$(git config --global user.name)
if [ -z "$git_name" ]; then
echo "Enter your Git global name:" >&2 # Output to standard error to ensure it shows on the terminal
read user_name < /dev/tty # Read input from the terminal
git config --global user.name "$user_name"
else
echo "Global name already set as: $git_name" >&2
fi
# Install Turborepo
pnpm add -Dw turbo
npx @turbo/codemod create-turbo-config --force .
remixDir=remix-app
# Navigate to the apps directory, initialize Remix on Cloudflare, and return
pushd apps
pnpm dlx create-remix@latest $remixDir --no-git-init --no-install --package-manager pnpm --template remix-run/remix/templates/cloudflare && popd && git add . && git commit -m "Initial commit" && pnpm install -r
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment