Skip to content

Instantly share code, notes, and snippets.

@alexkuc
Created June 22, 2022 07:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexkuc/32574dc72a8f4bbcc18ffa7f20ed5b67 to your computer and use it in GitHub Desktop.
Save alexkuc/32574dc72a8f4bbcc18ffa7f20ed5b67 to your computer and use it in GitHub Desktop.
Create distributable version of WordPress plugin
#!/usr/bin/env bash
# install node dependencies
# --production flag is *not* required since we use bundler
NODE_ENV=production npm install
# install optimized backend dependencies
composer install --no-dev --optimize-autoloader
# ensure clean dist directory
rm -fr frontend/
# ensure clean state by removing plugin/ directory
rm -rf plugin/
# install optimized frontend dependencies
NODE_ENV=production npm run build
# create plugin dir variable
dir="${PWD##*/}"
# determine plugin version from index.php file
version=$(grep -Pio '(?<=version: )([0-9\\.]+)$' index.php)
# create file variable
file="$(pwd)"/plugin/"$dir"-"$version".zip
# create dist directory
mkdir plugin
# create dist archive (ready for upload and use)
(cd .. && zip -r "$file" "$dir" \
-x "$dir/.stfolder/*" \
-x "$dir/.vscode/*" \
-x "$dir/node_modules/*" \
-x "$dir/plugin/*" \
-x "$dir/scripts/*" \
-x "$dir/stubs/*" \
-x "$dir/src/*" \
-x "$dir/.distignore" \
-x "$dir/.env.local" \
-x "$dir/.gitignore" \
-x "$dir/.stignore" \
-x "$dir/composer.json" \
-x "$dir/composer.lock" \
-x "$dir/index.html" \
-x "$dir/LICENSE" \
-x "$dir/package-lock.json" \
-x "$dir/package.json" \
-x "$dir/tsconfig.json" \
-x "$dir/tsconfig.node.json" \
-x "$dir/vite.config.ts"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment