Skip to content

Instantly share code, notes, and snippets.

@Jarrodsz
Created July 16, 2023 13:37
Show Gist options
  • Save Jarrodsz/2440a6bff5eec9cbd8aec93720c9bc38 to your computer and use it in GitHub Desktop.
Save Jarrodsz/2440a6bff5eec9cbd8aec93720c9bc38 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Get the name of the application from the command line argument.
app_name=$1
# Check if the application exists.
app_dir=$(find ./apps/* -type d -name "$app_name" -print0 | xargs -0 ls)
if [ -z "$app_dir" ]; then
echo "App '$app_name' does not exist"
exit 1
fi
echo "Deploying $app_name from apps/$app_name to deploy output folder: ./_deploy/$app_name"
# remove existing deployed app
rm -rf ./_deploy/$app_name
# create deployed app
pnpm --filter=./apps/$app_name --prod --production deploy ./_deploy/$app_name
# CLEANUP
cd ./_deploy/$app_name
json_file='./package.json'
if [[ ! -f "$json_file" ]]; then
echo "File $json_file does not exist."
exit 1
fi
sed -i '' '/"devDependencies": {/,/},/d' "$json_file"
## END CLEANUP
## INSTALL CORE PACKAGES
# Use jq to parse package.json and find all dependencies that include "@core"
packages=$(jq -r '.dependencies | to_entries[] | select(.key | contains("@core")) | .key' ./package.json)
# Loop over each package and install it
for package in $packages
do
echo "Installing $package..."
pnpm install $package
done
echo "All @core packages have been installed."
## END INSTALL CORE PACKAGES
# setup new git
git init
git remote add dokku dokku@app:$app_name
git config remote.dokku.fetch +refs/heads/*:refs/remotes/dokku/*
# install the required packages
git add *
git commit -m 'Initial commit'
# Push the changes to the remote server.
git push dokku master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment