Created
December 3, 2020 15:52
-
-
Save csalzano/f54d5d32405fc3cdc5f40addef0c7649 to your computer and use it in GitHub Desktop.
Zips a directory while excluding .git, node_modules, and .gitingore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
::plugin-zipper.bat | |
::Zips a directory while excluding .git, node_modules, and .gitingore | |
@echo off | |
set /p slug=Please enter a directory name/plugin slug: | |
If /I "%slug%"=="" goto earlyexit | |
tar -a -c -f "%slug%".zip --exclude ".git" --exclude ".gitignore" --exclude "node_modules" "%slug%" | |
:earlyexit |
plugin-zipper.sh
a Unix-like system equivalent
Puts version numbers in file names
A plugin with slug term-meta-ui
will zip into a folder named term-meta-ui-v0.4.0.zip.
#!/usr/local/bin/bash
#
# plugin-zipper.sh
#
# a script that creates WordPress plugin zip files ready for distribution
# version 1.1.0
#
# perhaps a plugin directory name name was passed as the first argument
if [ -z "$1" ]
then
# ask the user to type in a site name
echo "Please enter a directory name/plugin slug:"
read slug
else
slug=$1
fi
# extract the version number from the plugin header comment by...
# - copying it to a WordPress installation
# - extract version number with wp-cli
# - delete the plugin copy
# remember the current directory.
dir=$(pwd)
# copy the plugin to a WordPress installation.
cp -r "${slug}" ~/sites/empty/wp-content/plugins
# extract the version number.
cd ~/sites/empty/
version_number="$(wp plugin get "${slug}" --field=version)"
wp plugin delete "${slug}" --quiet
# go back to the original directory.
cd "${dir}"
# zip the directory.
# do not include .git directories, node_modules directories, or .DS_Store files.
if [ -n "$version_number" ]; then
# put the version number in the file name.
# plugin-slug-v1.0.0.zip
zip -r "${slug}-v${version_number}".zip "${slug}" -x "/${slug}/*.git*" -x "/${slug}/node_modules/*" -x "/${slug}/*.DS_Store"
else
# no version number.
# plugin-slug.zip
zip -r "${slug}".zip "${slug}" -x "/${slug}/*.git*" -x "/${slug}/node_modules/*" -x "/${slug}/*.DS_Store"
fi
Usage
[~/]$ bash plugin-zipper.sh term-meta-ui
Using git archive could make this platform agnostic https://stackoverflow.com/a/28357990/338432
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage on Windows