From 8e2f59393339398590a05efcbd4d624779c54f87 Mon Sep 17 00:00:00 2001 From: Joe Fusco Date: Fri, 23 Oct 2026 22:16:57 -0400 Subject: [PATCH] chore: share one version sync script across plugins The five bin/sync-package-version.sh copies differed only in the plugin file name and version constant, which both follow from the plugin folder name. Each plugin's `npm run version` now runs scripts/sync-plugin-version.sh, which works them out. --- .../hwp-documents/bin/sync-package-version.sh | 59 ------------------- plugins/hwp-documents/package.json | 2 +- .../hwp-previews/bin/sync-package-version.sh | 59 ------------------- plugins/hwp-previews/package.json | 2 +- .../wpgraphql-debug-extensions/package.json | 2 +- .../bin/sync-package-version.sh | 59 ------------------- plugins/wpgraphql-logging/package.json | 2 +- .../bin/sync-package-version.sh | 59 ------------------- plugins/wpgraphql-webhooks/package.json | 2 +- .../sync-plugin-version.sh | 24 +++++--- 10 files changed, 22 insertions(+), 248 deletions(-) delete mode 100755 plugins/hwp-documents/bin/sync-package-version.sh delete mode 100755 plugins/hwp-previews/bin/sync-package-version.sh delete mode 100755 plugins/wpgraphql-logging/bin/sync-package-version.sh delete mode 100755 plugins/wpgraphql-webhooks/bin/sync-package-version.sh rename plugins/wpgraphql-debug-extensions/bin/sync-package-version.sh => scripts/sync-plugin-version.sh (65%) diff --git a/plugins/hwp-documents/bin/sync-package-version.sh b/plugins/hwp-documents/bin/sync-package-version.sh deleted file mode 100755 index 36b39f829..000000000 --- a/plugins/hwp-documents/bin/sync-package-version.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash - -# Exit on any error -set -e - -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -NC='\033[0m' # No Color - -# Get the version from package.json -VERSION=$(node -p "require('./package.json').version") - -if [ -z "$VERSION" ]; then - echo -e "${RED}Error: Could not read version from package.json${NC}" - exit 1 -fi - -echo -e "${YELLOW}Syncing version ${VERSION} across all files...${NC}" - -# Update composer.json -if [ -f "composer.json" ]; then - echo "Updating composer.json..." - # Use sed to preserve original formatting (tabs/spaces) - sed -i.bak -E "s/(\"version\":[[:space:]]*\")[^\"]*(\",?)/\1$VERSION\2/" composer.json && rm composer.json.bak - echo -e "${GREEN}✓ Updated composer.json${NC}" -else - echo -e "${YELLOW}⚠ composer.json not found${NC}" -fi - -# Update readme.txt (WordPress style) -if [ -f "readme.txt" ]; then - echo "Updating readme.txt..." - sed -i.bak -E "s/(Stable tag:|Version:)[[:space:]]*[0-9]+\.[0-9]+\.[0-9]+/\1 $VERSION/g" readme.txt && rm readme.txt.bak - echo -e "${GREEN}✓ Updated readme.txt${NC}" -else - echo -e "${YELLOW}⚠ readme.txt not found${NC}" -fi - -# Update hwp-documents.php -PLUGIN_FILE="hwp-documents.php" - -if [ -f "$PLUGIN_FILE" ]; then - echo "Updating main plugin file: $PLUGIN_FILE..." - - # Update WordPress plugin header version (handles beta versions) - sed -i.bak -E "s/(\* Version:[[:space:]]*)[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?/\1$VERSION/g" "$PLUGIN_FILE" && rm "${PLUGIN_FILE}.bak" - - # Update HWP_DOCUMENTS_VERSION define statement - sed -i.bak -E "s/(define\([[:space:]]*['\"]HWP_DOCUMENTS_VERSION['\"][[:space:]]*,[[:space:]]*['\"])[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?(['\"][[:space:]]*\))/\1$VERSION\3/g" "$PLUGIN_FILE" && rm "${PLUGIN_FILE}.bak" - - echo -e "${GREEN}✓ Updated $PLUGIN_FILE${NC}" -else - echo -e "${YELLOW}⚠ $PLUGIN_FILE not found${NC}" -fi - -echo -e "${GREEN}✅ Version sync complete! All files updated to version ${VERSION}${NC}" -echo -e "${YELLOW}Files will be staged by the workflow's 'git add .' command${NC}"`` diff --git a/plugins/hwp-documents/package.json b/plugins/hwp-documents/package.json index 35d6720be..66b06f233 100644 --- a/plugins/hwp-documents/package.json +++ b/plugins/hwp-documents/package.json @@ -8,7 +8,7 @@ "test:e2e": "wp-scripts test-playwright --config tests/e2e/playwright.config.js", "test:e2e:debug": "npm run test:e2e -- --debug", "wp-env": "wp-env", - "version": "./bin/sync-package-version.sh" + "version": "../../scripts/sync-plugin-version.sh" }, "keywords": [ "wordpress", diff --git a/plugins/hwp-previews/bin/sync-package-version.sh b/plugins/hwp-previews/bin/sync-package-version.sh deleted file mode 100755 index 22581777d..000000000 --- a/plugins/hwp-previews/bin/sync-package-version.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash - -# Exit on any error -set -e - -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -NC='\033[0m' # No Color - -# Get the version from package.json -VERSION=$(node -p "require('./package.json').version") - -if [ -z "$VERSION" ]; then - echo -e "${RED}Error: Could not read version from package.json${NC}" - exit 1 -fi - -echo -e "${YELLOW}Syncing version ${VERSION} across all files...${NC}" - -# Update composer.json -if [ -f "composer.json" ]; then - echo "Updating composer.json..." - # Use sed to preserve original formatting (tabs/spaces) - sed -i.bak -E "s/(\"version\":[[:space:]]*\")[^\"]*(\",?)/\1$VERSION\2/" composer.json && rm composer.json.bak - echo -e "${GREEN}✓ Updated composer.json${NC}" -else - echo -e "${YELLOW}⚠ composer.json not found${NC}" -fi - -# Update readme.txt (WordPress style) -if [ -f "readme.txt" ]; then - echo "Updating readme.txt..." - sed -i.bak -E "s/(Stable tag:|Version:)[[:space:]]*[0-9]+\.[0-9]+\.[0-9]+/\1 $VERSION/g" readme.txt && rm readme.txt.bak - echo -e "${GREEN}✓ Updated readme.txt${NC}" -else - echo -e "${YELLOW}⚠ readme.txt not found${NC}" -fi - -# Update hwp-previews.php -PLUGIN_FILE="hwp-previews.php" - -if [ -f "$PLUGIN_FILE" ]; then - echo "Updating main plugin file: $PLUGIN_FILE..." - - # Update WordPress plugin header version (handles beta versions) - sed -i.bak -E "s/(\* Version:[[:space:]]*)[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?/\1$VERSION/g" "$PLUGIN_FILE" && rm "${PLUGIN_FILE}.bak" - - # Update HWP_PREVIEWS_VERSION define statement - sed -i.bak -E "s/(define\([[:space:]]*['\"]HWP_PREVIEWS_VERSION['\"][[:space:]]*,[[:space:]]*['\"])[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?(['\"][[:space:]]*\))/\1$VERSION\3/g" "$PLUGIN_FILE" && rm "${PLUGIN_FILE}.bak" - - echo -e "${GREEN}✓ Updated $PLUGIN_FILE${NC}" -else - echo -e "${YELLOW}⚠ $PLUGIN_FILE not found${NC}" -fi - -echo -e "${GREEN}✅ Version sync complete! All files updated to version ${VERSION}${NC}" -echo -e "${YELLOW}Files will be staged by the workflow's 'git add .' command${NC}"`` diff --git a/plugins/hwp-previews/package.json b/plugins/hwp-previews/package.json index 707ce24f8..5fc40e98f 100644 --- a/plugins/hwp-previews/package.json +++ b/plugins/hwp-previews/package.json @@ -8,7 +8,7 @@ "test:e2e": "wp-scripts test-playwright --config tests/e2e/playwright.config.js", "test:e2e:debug": "npm run test:e2e -- --debug", "wp-env": "wp-env", - "version": "./bin/sync-package-version.sh" + "version": "../../scripts/sync-plugin-version.sh" }, "keywords": [ "wordpress", diff --git a/plugins/wpgraphql-debug-extensions/package.json b/plugins/wpgraphql-debug-extensions/package.json index 3e587f35d..fe62c2677 100644 --- a/plugins/wpgraphql-debug-extensions/package.json +++ b/plugins/wpgraphql-debug-extensions/package.json @@ -5,7 +5,7 @@ "description": "Debug Extensions for WordPress", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "version": "./bin/sync-package-version.sh" + "version": "../../scripts/sync-plugin-version.sh" }, "keywords": [], "author": "wpengine", diff --git a/plugins/wpgraphql-logging/bin/sync-package-version.sh b/plugins/wpgraphql-logging/bin/sync-package-version.sh deleted file mode 100755 index e5bbed5ba..000000000 --- a/plugins/wpgraphql-logging/bin/sync-package-version.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash - -# Exit on any error -set -e - -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -NC='\033[0m' # No Color - -# Get the version from package.json -VERSION=$(node -p "require('./package.json').version") - -if [ -z "$VERSION" ]; then - echo -e "${RED}Error: Could not read version from package.json${NC}" - exit 1 -fi - -echo -e "${YELLOW}Syncing version ${VERSION} across all files...${NC}" - -# Update composer.json -if [ -f "composer.json" ]; then - echo "Updating composer.json..." - # Use sed to preserve original formatting (tabs/spaces) - sed -i.bak -E "s/(\"version\":[[:space:]]*\")[^\"]*(\",?)/\1$VERSION\2/" composer.json && rm composer.json.bak - echo -e "${GREEN}✓ Updated composer.json${NC}" -else - echo -e "${YELLOW}⚠ composer.json not found${NC}" -fi - -# Update readme.txt (WordPress style) -if [ -f "readme.txt" ]; then - echo "Updating readme.txt..." - sed -i.bak -E "s/(Stable tag:|Version:)[[:space:]]*[0-9]+\.[0-9]+\.[0-9]+/\1 $VERSION/g" readme.txt && rm readme.txt.bak - echo -e "${GREEN}✓ Updated readme.txt${NC}" -else - echo -e "${YELLOW}⚠ readme.txt not found${NC}" -fi - -# Update wpgraphql-logging.php -PLUGIN_FILE="wpgraphql-logging.php" - -if [ -f "$PLUGIN_FILE" ]; then - echo "Updating main plugin file: $PLUGIN_FILE..." - - # Update WordPress plugin header version (handles beta versions) - sed -i.bak -E "s/(\* Version:[[:space:]]*)[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?/\1$VERSION/g" "$PLUGIN_FILE" && rm "${PLUGIN_FILE}.bak" - - # Update WPGRAPHQL_LOGGING_VERSION define statement - sed -i.bak -E "s/(define\([[:space:]]*['\"]WPGRAPHQL_LOGGING_VERSION['\"][[:space:]]*,[[:space:]]*['\"])[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?(['\"][[:space:]]*\))/\1$VERSION\3/g" "$PLUGIN_FILE" && rm "${PLUGIN_FILE}.bak" - - echo -e "${GREEN}✓ Updated $PLUGIN_FILE${NC}" -else - echo -e "${YELLOW}⚠ $PLUGIN_FILE not found${NC}" -fi - -echo -e "${GREEN}✅ Version sync complete! All files updated to version ${VERSION}${NC}" -echo -e "${YELLOW}Files will be staged by the workflow's 'git add .' command${NC}"`` diff --git a/plugins/wpgraphql-logging/package.json b/plugins/wpgraphql-logging/package.json index cbc8f63da..3139462b4 100644 --- a/plugins/wpgraphql-logging/package.json +++ b/plugins/wpgraphql-logging/package.json @@ -8,7 +8,7 @@ "test:e2e": "wp-scripts test-playwright --config tests/e2e/playwright.config.js", "test:e2e:debug": "npm run test:e2e -- --debug", "wp-env": "wp-env", - "version": "./bin/sync-package-version.sh" + "version": "../../scripts/sync-plugin-version.sh" }, "keywords": [], "author": "wpengine", diff --git a/plugins/wpgraphql-webhooks/bin/sync-package-version.sh b/plugins/wpgraphql-webhooks/bin/sync-package-version.sh deleted file mode 100755 index 6b8bf8ebd..000000000 --- a/plugins/wpgraphql-webhooks/bin/sync-package-version.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash - -# Exit on any error -set -e - -# Colors for output -RED='\033[0;31m' -GREEN='\033[0;32m' -YELLOW='\033[1;33m' -NC='\033[0m' # No Color - -# Get the version from package.json -VERSION=$(node -p "require('./package.json').version") - -if [ -z "$VERSION" ]; then - echo -e "${RED}Error: Could not read version from package.json${NC}" - exit 1 -fi - -echo -e "${YELLOW}Syncing version ${VERSION} across all files...${NC}" - -# Update composer.json -if [ -f "composer.json" ]; then - echo "Updating composer.json..." - # Use sed to preserve original formatting (tabs/spaces) - sed -i.bak -E "s/(\"version\":[[:space:]]*\")[^\"]*(\",?)/\1$VERSION\2/" composer.json && rm composer.json.bak - echo -e "${GREEN}✓ Updated composer.json${NC}" -else - echo -e "${YELLOW}⚠ composer.json not found${NC}" -fi - -# Update readme.txt (WordPress style) -if [ -f "readme.txt" ]; then - echo "Updating readme.txt..." - sed -i.bak -E "s/(Stable tag:|Version:)[[:space:]]*[0-9]+\.[0-9]+\.[0-9]+/\1 $VERSION/g" readme.txt && rm readme.txt.bak - echo -e "${GREEN}✓ Updated readme.txt${NC}" -else - echo -e "${YELLOW}⚠ readme.txt not found${NC}" -fi - -# Update wpgraphql-webhooks.php -PLUGIN_FILE="wpgraphql-webhooks.php" - -if [ -f "$PLUGIN_FILE" ]; then - echo "Updating main plugin file: $PLUGIN_FILE..." - - # Update WordPress plugin header version (handles beta versions) - sed -i.bak -E "s/(\* Version:[[:space:]]*)[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?/\1$VERSION/g" "$PLUGIN_FILE" && rm "${PLUGIN_FILE}.bak" - - # Update WPGRAPHQL_WEBHOOKS_VERSION define statement - sed -i.bak -E "s/(define\([[:space:]]*['\"]WPGRAPHQL_WEBHOOKS_VERSION['\"][[:space:]]*,[[:space:]]*['\"])[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?(['\"][[:space:]]*\))/\1$VERSION\3/g" "$PLUGIN_FILE" && rm "${PLUGIN_FILE}.bak" - - echo -e "${GREEN}✓ Updated $PLUGIN_FILE${NC}" -else - echo -e "${YELLOW}⚠ $PLUGIN_FILE not found${NC}" -fi - -echo -e "${GREEN}✅ Version sync complete! All files updated to version ${VERSION}${NC}" -echo -e "${YELLOW}Files will be staged by the workflow's 'git add .' command${NC}"`` diff --git a/plugins/wpgraphql-webhooks/package.json b/plugins/wpgraphql-webhooks/package.json index 1e6a1b6f2..0fe636ba3 100644 --- a/plugins/wpgraphql-webhooks/package.json +++ b/plugins/wpgraphql-webhooks/package.json @@ -5,7 +5,7 @@ "description": "Webhooks solution for WordPress", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", - "version": "./bin/sync-package-version.sh" + "version": "../../scripts/sync-plugin-version.sh" }, "keywords": [], "author": "wpengine", diff --git a/plugins/wpgraphql-debug-extensions/bin/sync-package-version.sh b/scripts/sync-plugin-version.sh similarity index 65% rename from plugins/wpgraphql-debug-extensions/bin/sync-package-version.sh rename to scripts/sync-plugin-version.sh index b464caa95..0d4b783b0 100755 --- a/plugins/wpgraphql-debug-extensions/bin/sync-package-version.sh +++ b/scripts/sync-plugin-version.sh @@ -1,5 +1,11 @@ #!/bin/bash +# Syncs a plugin's package.json version into composer.json, readme.txt, the plugin header, +# and the _VERSION constant. +# +# Run it from the plugin folder (it's each plugin's `npm run version` script), or pass the +# plugin folder as the first argument. + # Exit on any error set -e @@ -9,6 +15,13 @@ GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color +cd "${1:-.}" + +SLUG=$(basename "$PWD") +PLUGIN_FILE="$SLUG.php" +# e.g. hwp-previews -> HWP_PREVIEWS_VERSION +VERSION_CONSTANT="$(echo "$SLUG" | tr '[:lower:]-' '[:upper:]_')_VERSION" + # Get the version from package.json VERSION=$(node -p "require('./package.json').version") @@ -17,7 +30,7 @@ if [ -z "$VERSION" ]; then exit 1 fi -echo -e "${YELLOW}Syncing version ${VERSION} across all files...${NC}" +echo -e "${YELLOW}Syncing $SLUG version ${VERSION} across all files...${NC}" # Update composer.json if [ -f "composer.json" ]; then @@ -38,17 +51,15 @@ else echo -e "${YELLOW}⚠ readme.txt not found${NC}" fi -# Update wpgraphql-debug-extensions.php -PLUGIN_FILE="wpgraphql-debug-extensions.php" - +# Update the main plugin file if [ -f "$PLUGIN_FILE" ]; then echo "Updating main plugin file: $PLUGIN_FILE..." # Update WordPress plugin header version (handles beta versions) sed -i.bak -E "s/(\* Version:[[:space:]]*)[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?/\1$VERSION/g" "$PLUGIN_FILE" && rm "${PLUGIN_FILE}.bak" - # Update WPGRAPHQL_DEBUG_EXTENSIONS_VERSION define statement - sed -i.bak -E "s/(define\([[:space:]]*['\"]WPGRAPHQL_DEBUG_EXTENSIONS_VERSION['\"][[:space:]]*,[[:space:]]*['\"])[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?(['\"][[:space:]]*\))/\1$VERSION\3/g" "$PLUGIN_FILE" && rm "${PLUGIN_FILE}.bak" + # Update the version constant's define statement + sed -i.bak -E "s/(define\([[:space:]]*['\"]${VERSION_CONSTANT}['\"][[:space:]]*,[[:space:]]*['\"])[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?(['\"][[:space:]]*\))/\1$VERSION\3/g" "$PLUGIN_FILE" && rm "${PLUGIN_FILE}.bak" echo -e "${GREEN}✓ Updated $PLUGIN_FILE${NC}" else @@ -56,4 +67,3 @@ else fi echo -e "${GREEN}✅ Version sync complete! All files updated to version ${VERSION}${NC}" -echo -e "${YELLOW}Files will be staged by the workflow's 'git add .' command${NC}"``