fix: resolve ShellCheck violations in shell scripts (#91)
- SC2155 (bin/localwp-setup.sh): declare local variables separately from command substitution assignments to avoid masking return values (13 fixes) - SC2034 (bin/localwp-setup.sh): remove unused PLUGIN_TEXT_DOMAIN variable - SC2162 (bin/localwp-setup.sh): add -r flag to read to avoid backslash mangling - SC2154 (bin/setup-test-env.sh): add shellcheck disable for PHP variables in heredoc that ShellCheck incorrectly identifies as unassigned shell variables - bin/setup-test-env.sh: remove self-modifying chmod +x $0 (unnecessary and bad practice; file permissions should be set once in version control) - bin/setup-test-env.sh: change == to = in POSIX [ ] test expressions - build.sh: add ./ prefix to directory glob copies for clarity - build.sh: use subshell (cd build || exit 1; zip ...) instead of bare cd/cd.. to avoid SC2103 and ensure working directory is always restored Fixes part of #20 (shell script quality issues)
This commit is contained in:
@@ -28,7 +28,6 @@ set -e
|
|||||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
|
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
|
||||||
PLUGIN_SLUG="wp-plugin-starter-template"
|
PLUGIN_SLUG="wp-plugin-starter-template"
|
||||||
PLUGIN_TEXT_DOMAIN="wp-plugin-starter-template"
|
|
||||||
|
|
||||||
# LocalWP paths (macOS)
|
# LocalWP paths (macOS)
|
||||||
LOCAL_SITES_DIR="$HOME/Local Sites"
|
LOCAL_SITES_DIR="$HOME/Local Sites"
|
||||||
@@ -83,7 +82,8 @@ check_localwp() {
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local version=$("$LOCAL_WP_CLI" --version 2>/dev/null || echo "unknown")
|
local version
|
||||||
|
version=$("$LOCAL_WP_CLI" --version 2>/dev/null || echo "unknown")
|
||||||
log_info "LocalWP WP-CLI version: $version"
|
log_info "LocalWP WP-CLI version: $version"
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +96,8 @@ get_site_path() {
|
|||||||
# Get WordPress path within site
|
# Get WordPress path within site
|
||||||
get_wp_path() {
|
get_wp_path() {
|
||||||
local site_name="$1"
|
local site_name="$1"
|
||||||
local site_path=$(get_site_path "$site_name")
|
local site_path
|
||||||
|
site_path=$(get_site_path "$site_name")
|
||||||
|
|
||||||
# LocalWP uses app/public for WordPress files
|
# LocalWP uses app/public for WordPress files
|
||||||
echo "$site_path/app/public"
|
echo "$site_path/app/public"
|
||||||
@@ -105,21 +106,24 @@ get_wp_path() {
|
|||||||
# Check if site exists
|
# Check if site exists
|
||||||
site_exists() {
|
site_exists() {
|
||||||
local site_name="$1"
|
local site_name="$1"
|
||||||
local site_path=$(get_site_path "$site_name")
|
local site_path
|
||||||
|
site_path=$(get_site_path "$site_name")
|
||||||
[ -d "$site_path" ]
|
[ -d "$site_path" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get plugin destination path
|
# Get plugin destination path
|
||||||
get_plugin_path() {
|
get_plugin_path() {
|
||||||
local site_name="$1"
|
local site_name="$1"
|
||||||
local wp_path=$(get_wp_path "$site_name")
|
local wp_path
|
||||||
|
wp_path=$(get_wp_path "$site_name")
|
||||||
echo "$wp_path/wp-content/plugins/$PLUGIN_SLUG"
|
echo "$wp_path/wp-content/plugins/$PLUGIN_SLUG"
|
||||||
}
|
}
|
||||||
|
|
||||||
# Sync plugin files to LocalWP site
|
# Sync plugin files to LocalWP site
|
||||||
sync_plugin() {
|
sync_plugin() {
|
||||||
local site_name="$1"
|
local site_name="$1"
|
||||||
local plugin_dest=$(get_plugin_path "$site_name")
|
local plugin_dest
|
||||||
|
plugin_dest=$(get_plugin_path "$site_name")
|
||||||
|
|
||||||
if ! site_exists "$site_name"; then
|
if ! site_exists "$site_name"; then
|
||||||
log_error "Site '$site_name' does not exist"
|
log_error "Site '$site_name' does not exist"
|
||||||
@@ -181,7 +185,8 @@ create_site() {
|
|||||||
|
|
||||||
check_localwp
|
check_localwp
|
||||||
|
|
||||||
local site_path=$(get_site_path "$site_name")
|
local site_path
|
||||||
|
site_path=$(get_site_path "$site_name")
|
||||||
|
|
||||||
if site_exists "$site_name"; then
|
if site_exists "$site_name"; then
|
||||||
log_warning "Site '$site_name' already exists at: $site_path"
|
log_warning "Site '$site_name' already exists at: $site_path"
|
||||||
@@ -230,7 +235,7 @@ create_site() {
|
|||||||
echo ""
|
echo ""
|
||||||
|
|
||||||
# Wait for user to create site
|
# Wait for user to create site
|
||||||
read -p "Press Enter after you've created the site in LocalWP..."
|
read -r -p "Press Enter after you've created the site in LocalWP..."
|
||||||
|
|
||||||
if site_exists "$site_name"; then
|
if site_exists "$site_name"; then
|
||||||
log_success "Site detected at: $site_path"
|
log_success "Site detected at: $site_path"
|
||||||
@@ -250,7 +255,8 @@ create_site() {
|
|||||||
# Install recommended plugins (matching Playground blueprint)
|
# Install recommended plugins (matching Playground blueprint)
|
||||||
install_recommended_plugins() {
|
install_recommended_plugins() {
|
||||||
local site_name="$1"
|
local site_name="$1"
|
||||||
local wp_path=$(get_wp_path "$site_name")
|
local wp_path
|
||||||
|
wp_path=$(get_wp_path "$site_name")
|
||||||
|
|
||||||
log_info "Note: Install these plugins to match Playground environment:"
|
log_info "Note: Install these plugins to match Playground environment:"
|
||||||
echo " - Plugin Toggle (plugin-toggle)"
|
echo " - Plugin Toggle (plugin-toggle)"
|
||||||
@@ -265,8 +271,10 @@ show_site_info() {
|
|||||||
local domain="$2"
|
local domain="$2"
|
||||||
local multisite="$3"
|
local multisite="$3"
|
||||||
|
|
||||||
local site_path=$(get_site_path "$site_name")
|
local site_path
|
||||||
local plugin_path=$(get_plugin_path "$site_name")
|
site_path=$(get_site_path "$site_name")
|
||||||
|
local plugin_path
|
||||||
|
plugin_path=$(get_plugin_path "$site_name")
|
||||||
|
|
||||||
echo ""
|
echo ""
|
||||||
echo "============================================"
|
echo "============================================"
|
||||||
@@ -305,7 +313,8 @@ reset_site() {
|
|||||||
echo
|
echo
|
||||||
|
|
||||||
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
if [[ $REPLY =~ ^[Yy]$ ]]; then
|
||||||
local plugin_path=$(get_plugin_path "$site_name")
|
local plugin_path
|
||||||
|
plugin_path=$(get_plugin_path "$site_name")
|
||||||
|
|
||||||
log_info "Removing plugin files..."
|
log_info "Removing plugin files..."
|
||||||
rm -rf "$plugin_path"
|
rm -rf "$plugin_path"
|
||||||
@@ -345,14 +354,16 @@ show_info() {
|
|||||||
echo "==============================="
|
echo "==============================="
|
||||||
|
|
||||||
for site_name in "$SINGLE_SITE_NAME" "$MULTISITE_NAME"; do
|
for site_name in "$SINGLE_SITE_NAME" "$MULTISITE_NAME"; do
|
||||||
local site_path=$(get_site_path "$site_name")
|
local site_path
|
||||||
|
site_path=$(get_site_path "$site_name")
|
||||||
|
|
||||||
if site_exists "$site_name"; then
|
if site_exists "$site_name"; then
|
||||||
echo ""
|
echo ""
|
||||||
echo " ${GREEN}✓${NC} $site_name"
|
echo " ${GREEN}✓${NC} $site_name"
|
||||||
echo " Path: $site_path"
|
echo " Path: $site_path"
|
||||||
|
|
||||||
local plugin_path=$(get_plugin_path "$site_name")
|
local plugin_path
|
||||||
|
plugin_path=$(get_plugin_path "$site_name")
|
||||||
if [ -d "$plugin_path" ]; then
|
if [ -d "$plugin_path" ]; then
|
||||||
echo " Plugin: ${GREEN}Installed${NC}"
|
echo " Plugin: ${GREEN}Installed${NC}"
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -1,8 +1,5 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Make this script executable
|
|
||||||
chmod +x "$0"
|
|
||||||
|
|
||||||
# Check if environment type is provided
|
# Check if environment type is provided
|
||||||
if [ -z "$1" ]; then
|
if [ -z "$1" ]; then
|
||||||
echo "Usage: $0 [single|multisite|playground-single|playground-multisite]"
|
echo "Usage: $0 [single|multisite|playground-single|playground-multisite]"
|
||||||
@@ -49,7 +46,7 @@ install_wp_playground() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "$ENV_TYPE" == "single" ]; then
|
if [ "$ENV_TYPE" = "single" ]; then
|
||||||
echo "Setting up single site environment..."
|
echo "Setting up single site environment..."
|
||||||
|
|
||||||
# Install wp-env if needed
|
# Install wp-env if needed
|
||||||
@@ -83,7 +80,7 @@ if [ "$ENV_TYPE" == "single" ]; then
|
|||||||
echo "Site: http://localhost:8888"
|
echo "Site: http://localhost:8888"
|
||||||
echo "Admin login: admin / password"
|
echo "Admin login: admin / password"
|
||||||
|
|
||||||
elif [ "$ENV_TYPE" == "multisite" ]; then
|
elif [ "$ENV_TYPE" = "multisite" ]; then
|
||||||
echo "Setting up multisite environment..."
|
echo "Setting up multisite environment..."
|
||||||
|
|
||||||
# Install wp-env if needed
|
# Install wp-env if needed
|
||||||
@@ -124,7 +121,7 @@ elif [ "$ENV_TYPE" == "multisite" ]; then
|
|||||||
echo "Test site: http://localhost:8888/testsite"
|
echo "Test site: http://localhost:8888/testsite"
|
||||||
echo "Admin login: admin / password"
|
echo "Admin login: admin / password"
|
||||||
|
|
||||||
elif [ "$ENV_TYPE" == "playground-single" ]; then
|
elif [ "$ENV_TYPE" = "playground-single" ]; then
|
||||||
echo "Setting up WordPress Playground single site environment..."
|
echo "Setting up WordPress Playground single site environment..."
|
||||||
|
|
||||||
# Install wp-playground if needed
|
# Install wp-playground if needed
|
||||||
@@ -193,7 +190,7 @@ EOF
|
|||||||
echo "Admin login: admin / password"
|
echo "Admin login: admin / password"
|
||||||
echo "Press Ctrl+C to stop the server when done."
|
echo "Press Ctrl+C to stop the server when done."
|
||||||
|
|
||||||
elif [ "$ENV_TYPE" == "playground-multisite" ]; then
|
elif [ "$ENV_TYPE" = "playground-multisite" ]; then
|
||||||
echo "Setting up WordPress Playground multisite environment..."
|
echo "Setting up WordPress Playground multisite environment..."
|
||||||
|
|
||||||
# Install wp-playground if needed
|
# Install wp-playground if needed
|
||||||
@@ -205,6 +202,7 @@ elif [ "$ENV_TYPE" == "playground-multisite" ]; then
|
|||||||
zip -r dist/plugin.zip . -x "node_modules/*" "dist/*" ".git/*"
|
zip -r dist/plugin.zip . -x "node_modules/*" "dist/*" ".git/*"
|
||||||
|
|
||||||
# Update blueprint to use local plugin
|
# Update blueprint to use local plugin
|
||||||
|
# shellcheck disable=SC2154
|
||||||
cat >playground/multisite-blueprint.json <<EOF
|
cat >playground/multisite-blueprint.json <<EOF
|
||||||
{
|
{
|
||||||
"landingPage": "/wp-admin/network/",
|
"landingPage": "/wp-admin/network/",
|
||||||
|
|||||||
9
build.sh
9
build.sh
@@ -46,9 +46,9 @@ cp -R README.md LICENSE CHANGELOG.md readme.txt composer.json "$BUILD_DIR/"
|
|||||||
# Copy directories
|
# Copy directories
|
||||||
echo "Copying directories..."
|
echo "Copying directories..."
|
||||||
mkdir -p "$BUILD_DIR/admin" "$BUILD_DIR/includes" "$BUILD_DIR/languages" "$BUILD_DIR/assets"
|
mkdir -p "$BUILD_DIR/admin" "$BUILD_DIR/includes" "$BUILD_DIR/languages" "$BUILD_DIR/assets"
|
||||||
cp -R admin/* "$BUILD_DIR/admin/"
|
cp -R ./admin/* "$BUILD_DIR/admin/"
|
||||||
cp -R includes/* "$BUILD_DIR/includes/"
|
cp -R ./includes/* "$BUILD_DIR/includes/"
|
||||||
cp -R languages/* "$BUILD_DIR/languages/"
|
cp -R ./languages/* "$BUILD_DIR/languages/"
|
||||||
|
|
||||||
# Create assets directory structure
|
# Create assets directory structure
|
||||||
mkdir -p "$BUILD_DIR/assets/banner" "$BUILD_DIR/assets/icon" "$BUILD_DIR/assets/screenshots"
|
mkdir -p "$BUILD_DIR/assets/banner" "$BUILD_DIR/assets/icon" "$BUILD_DIR/assets/screenshots"
|
||||||
@@ -73,9 +73,10 @@ fi
|
|||||||
|
|
||||||
# Create ZIP file.
|
# Create ZIP file.
|
||||||
echo "Creating ZIP file..."
|
echo "Creating ZIP file..."
|
||||||
|
(
|
||||||
cd build || exit 1
|
cd build || exit 1
|
||||||
zip -r "../$ZIP_FILE" "$PLUGIN_SLUG" -x "*.DS_Store" -x "*.git*" -x "*.github*"
|
zip -r "../$ZIP_FILE" "$PLUGIN_SLUG" -x "*.DS_Store" -x "*.git*" -x "*.github*"
|
||||||
cd ..
|
)
|
||||||
|
|
||||||
# Check if ZIP file was created successfully
|
# Check if ZIP file was created successfully
|
||||||
if [ -f "$ZIP_FILE" ]; then
|
if [ -f "$ZIP_FILE" ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user