This pages explains how the various dev scripts work in the repo.
Shell Scripts
Pocketbase Deployment Script
deploy.sh
#!/bin/bash # Set up systemd # https://pocketbase.io/docs/going-to-production/ # nano /lib/systemd/system/pocketbase.service # Load environment variables set -a # automatically export all variables source .env set +a # stop automatically exporting ssh ${SERVER_USER}@${SERVER_HOST} << ENDSSH cd ${APP_PATH} sudo systemctl stop pocketbase echo "rm package-lock.json" git pull echo "npm install" echo "npm run generate" echo "rm -rf pocketbase/pb_public" echo "mkdir pocketbase/pb_public" echo "cp -r .output/public/* pocketbase/pb_public" sudo systemctl start pocketbase sudo systemctl daemon-reload ENDSSH
This script is musch simpler now than it used to be, due to setting pocketbase up as a system service on the server, and moving the static app hosting to firebase.
Now all it does is:
- Stop pocketbase service
- pull changes from the git repo
- Restart the pocketbase service
- Reload daemons
Nuxt Build
It used to also:
- install nuxt app dependencies
- build the nuxt app
- copy it into the pocketbase public folder
It no longer does this.
This script is run when any changes are made to pocketbase that need to be deployed to production via npm run deploy
Pocketbase install script
installpb.sh
#!/bin/bash # Pull pocketbase using version in .env from here: # https://github.com/pocketbase/pocketbase/releases # Load environment variables set -a # automatically export all variables source .env set +a # stop automatically exporting # Check for required environment variables if [ -z "$PB_VERSION" ] || [ -z "$PB_SYSTEM" ] || [ -z "$PB_ARCH" ]; then echo "Error: Missing required environment variables." echo "Please ensure your .env file contains:" echo " PB_VERSION (e.g., 0.25.9)" echo " PB_SYSTEM (e.g., darwin, linux)" echo " PB_ARCH (e.g., amd64, arm64)" exit 1 fi # Construct download URL using PB_VERSION from .env DOWNLOAD_URL="https://github.com/pocketbase/pocketbase/releases/download/v${PB_VERSION}/pocketbase_${PB_VERSION}_${PB_SYSTEM}_${PB_ARCH}.zip" # Function to install unzip based on system install_unzip() { if ! command -v unzip &> /dev/null; then echo "unzip is not installed. Installing..." if [ -f /etc/debian_version ]; then # Debian/Ubuntu sudo apt-get update && sudo apt-get install -y unzip elif [ -f /etc/redhat-release ]; then # RHEL/CentOS/Fedora sudo yum install -y unzip elif [ -f /etc/arch-release ]; then # Arch Linux sudo pacman -Sy --noconfirm unzip elif command -v brew &> /dev/null; then # macOS with Homebrew brew install unzip else echo "Could not install unzip automatically. Please install it manually." exit 1 fi fi } # Check for unzip before proceeding install_unzip # Download the zip file echo "Downloading PocketBase v${PB_VERSION}..." curl -L $DOWNLOAD_URL -o pocketbase/pocketbase_${PB_VERSION}_${PB_SYSTEM}_${PB_ARCH}.zip # Unzip the archive echo "Extracting files..." cd pocketbase && unzip -o pocketbase_${PB_VERSION}_${PB_SYSTEM}_${PB_ARCH}.zip && rm pocketbase_${PB_VERSION}_${PB_SYSTEM}_${PB_ARCH}.zip echo "PocketBase installation complete!"
This script uses Environment variables to download and unzip the specified pocketbase version archive from github releases.
It also checks for and installs unzip to extract the executable.
NPM Scripts
npm scripts are located in package.json
and contain useful commands that are used often.
use with:
npm run {script}
start
concurrently \"npm run dev\" \"npm run pb\"
Uses concurrently to start both the nuxt app and the pocketbase backend for working on in development.
Can be used without ‘run’ with:npm start
version
echo $npm_package_name v$npm_package_version
Prints the current app version
help
npm run
Lists these commands
build
nuxt generate
Builds the static site, output located in dist/
pb
cd ./pocketbase && ./pocketbase serve --dev
Serves the local pocketbase instance for development
installpb
./pocketbase/installpb.sh
Runs the above pocketbase install script locally. This will update your local pocketbase.
installpb:r
npm run env && source .env && ssh ${SERVER_USER}@${SERVER_HOST} \"cd ${APP_PATH} && ./pocketbase/installpb.sh\" && npm run deploy
Syncs remote environment and installs a new version pocketbase on the remote production server.
ios
npm run setenv:prod && nuxt generate && npx cap sync && npm run setenv:dev
Builds the iOS app
setenv:prod & setenv:dev
cp ./.env.production ./.env
& cp ./.env.development ./.env
Writes local .env
to either .env.production
or .env.development
assets
npx @capacitor/assets generate
Generates iOS assets, app icon and splashscreen.
It uses the following assets:
assets/icon.png
assets/splash.png
assets/splash-dark.png
tag
git tag $npm_package_version && git push origin $npm_package_version
Creates and pushes a new tag on the current commit with the current app version
ssh
source .env && ssh ${SERVER_USER}@${SERVER_HOST}
ssh into the remote pocketbase server using config in .env
env
echo 'syncing env to remote' &&
source .env &&
scp ./.env.production ${SERVER_USER}@${SERVER_HOST}:${APP_PATH}/.env &&
scp ./pocketbase/pb_hooks/env.json
Syncs .env.production
& env.json
to the remote production server.
Details in Environment.
deploy
./deploy.sh
Runs the above deploy script to update pocketbase on the remote server.
fb
npm run setenv:prod && npm run generate && firebase deploy --only hosting:tansyapp && npm run setenv:dev
Short for ‘firebase’, this command builds and deploys the app to firebase.