-
Notifications
You must be signed in to change notification settings - Fork 800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Synced Newspack Blocks: Update to 4.5.2 #40636
Merged
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
f8fb1e9
Sync newspack-blocks to 4.5.2
tbradsha 73e653f
Update script to auto-add textdomain to block.json
tbradsha 7520915
Update script to detect potential ENT_COMPAT needs
tbradsha 26ed945
Script tweaks
tbradsha f51d4b3
More script tweaks
tbradsha e385469
Add .phpcs.dir.xml via script
tbradsha 58c59a2
Finish up 4.5.2 block sync
tbradsha 428a09d
Update baseline
tbradsha c1caf91
Update Phan baseline in script
tbradsha de03fc9
Commit changes from script
tbradsha 3af28b0
Add ENT_COMPAT again
tbradsha bdee6ad
Add changelog
tbradsha 307bbd4
Add .phpcsignore
tbradsha f334dbe
Commit synced blocks with PHPCS lint disabled
tbradsha 0b0dba3
Allow one to resync current version
tbradsha ba51ed5
Update eslint and phpcbf calls
tbradsha 83b0491
Commit less-linted JS/TS files
tbradsha 3135249
Clean up paths
tbradsha ed996dd
Once again apply ENT_COMPAT changes
tbradsha de0c564
Update README
tbradsha c354232
Update index.php version number via script
tbradsha 877a79d
Don't run Phan on synced files
tbradsha 38dafc1
Remove Phan from README
tbradsha 8465bfc
Simplify PHP textdomain fix
tbradsha 5d3d690
Catch additional textdomain cases
tbradsha 2f56f6b
Adjust docs wording
tbradsha bc7ac12
Remove `ENT_COMPAT` step
tbradsha File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
src/features/newspack-blocks/synced-newspack-blocks |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ fi | |
|
||
# pick up value considering that the argument | ||
# has the --key=value shape. | ||
key_value=$(echo ${1} | cut -d'=' -f 2) | ||
key_value=$(echo "${1}" | cut -d'=' -f 2) | ||
# Set mode depending on first argument | ||
if [[ $1 =~ ^--release= ]] | ||
then | ||
|
@@ -44,15 +44,14 @@ then | |
echo --branch=master | ||
echo "--nodemodules (to use defined in package.json)" | ||
echo "--path=/path/to/newspack-blocks" | ||
echo --release=v2.0.0 | ||
echo --release=v4.0.0 | ||
echo | ||
echo You can find the latest release ID on https://github.com/Automattic/newspack-blocks/releases/latest | ||
echo | ||
exit 1 | ||
fi | ||
|
||
TARGET=./src/features/newspack-blocks/synced-newspack-blocks | ||
ENTRY=./src/features/newspack-blocks/index.php | ||
|
||
if [[ ( "$MODE" != "path" ) && ( "$MODE" != "npm" ) ]]; | ||
then | ||
|
@@ -62,20 +61,23 @@ then | |
|
||
if [[ "$CURRENT_VERSION" == "$NAME" ]]; then | ||
echo "The current version $CURRENT_VERSION of the newspack-blocks is synced." | ||
exit 0 | ||
read -rp "Do you want to proceed anyway? (y/N): " proceed | ||
if [[ ! "$proceed" =~ ^[Yy]$ ]]; then | ||
exit 0 | ||
fi | ||
fi | ||
fi | ||
|
||
# make a temp directory | ||
TEMP_DIR=`mktemp -d` | ||
TEMP_DIR=$(mktemp -d) | ||
CODE=$TEMP_DIR/code | ||
|
||
# download zip file | ||
echo Downloading $MODE $NAME into $TEMP_DIR | ||
(cd $TEMP_DIR && curl -L --fail -s -O $URL) | ||
echo "Downloading $MODE $NAME into $TEMP_DIR" | ||
(cd "$TEMP_DIR" && curl -L --fail -s -O "$URL") | ||
|
||
# handle download error | ||
ZIPS=( $TEMP_DIR/*.zip ) | ||
ZIPS=( "$TEMP_DIR"/*.zip ) | ||
ZIP=${ZIPS[0]} | ||
if [ ! -f "$ZIP" ]; then | ||
echo "Tried to download $URL" | ||
|
@@ -90,13 +92,13 @@ then | |
fi | ||
|
||
# extract zip | ||
echo Extracting into $CODE | ||
mkdir -p $CODE | ||
unzip -q $ZIP -d $CODE | ||
echo "Extracting into $CODE" | ||
mkdir -p "$CODE" | ||
unzip -q "$ZIP" -d "$CODE" | ||
|
||
# find the main file and use its directory as the root of our source dir | ||
MAIN_FILE=`find $CODE -name "newspack-blocks.php"` | ||
CODE=`dirname $MAIN_FILE` | ||
MAIN_FILE=$(find "$CODE" -name "newspack-blocks.php") | ||
CODE=$(dirname "$MAIN_FILE") | ||
|
||
# handle unzip error | ||
if [ ! -f "$CODE/newspack-blocks.php" ]; then | ||
|
@@ -127,31 +129,84 @@ mkdir -p $TARGET/components | |
mkdir -p $TARGET/shared | ||
mkdir -p $TARGET/types | ||
|
||
# copy files and directories | ||
NEW_VERSION=v`jq -r .version $CODE/package.json` | ||
# Update Newspack Blocks version number in the package. | ||
NEW_VERSION=v$(jq -r .version "$CODE"/package.json) | ||
echo "$NEW_VERSION" > $TARGET/version.txt | ||
cp $CODE/includes/class-newspack-blocks-api.php $TARGET/ | ||
cp $CODE/includes/class-newspack-blocks.php $TARGET/ | ||
cp -R $CODE/src/blocks/homepage-articles $TARGET/blocks/ | ||
cp -R $CODE/src/blocks/carousel $TARGET/blocks/ | ||
cp -R $CODE/src/shared $TARGET/ | ||
cp -R $CODE/src/components $TARGET/ | ||
sed -E -i.bak "s|^define\( 'NEWSPACK_BLOCKS__VERSION', '.*' \);$|define( 'NEWSPACK_BLOCKS__VERSION', '$NEW_VERSION' );|" "$TARGET"/../index.php | ||
rm "$TARGET"/../index.php.bak | ||
|
||
# copy files and directories | ||
cp "$CODE"/includes/class-newspack-blocks-api.php $TARGET/ | ||
cp "$CODE"/includes/class-newspack-blocks.php $TARGET/ | ||
cp -R "$CODE"/src/blocks/homepage-articles $TARGET/blocks/ | ||
cp -R "$CODE"/src/blocks/carousel $TARGET/blocks/ | ||
cp -R "$CODE"/src/shared $TARGET/ | ||
cp -R "$CODE"/src/components $TARGET/ | ||
|
||
# Get Typescript working by copying the main type defs over. | ||
cp $CODE/src/types/index.d.ts $TARGET/types/ | ||
cp "$CODE"/src/types/index.d.ts $TARGET/types/ | ||
# Function types need to be capitalized in our system. We only match " function" | ||
# beginning with a space to avoid matching it as a substring. (Not perfect, but | ||
# imperfections will be caught by CI with failing tsc, etc.) | ||
sed "${sedi[@]}" -e "s| function| Function|g" "$TARGET/types/index.d.ts" | ||
|
||
# Note: I would have used eslint-nibble, but it doesn't support autofixing via the CLI. | ||
echo "Changing JS textdomain to match jetpack-mu-wpcom..." | ||
pnpm [email protected] dlx eslint --no-ignore --rule '"@wordpress/i18n-text-domain":["error",{"allowedTextDomain":"jetpack-mu-wpcom"}]' --fix $TARGET > /dev/null | ||
BASE=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../../../.. && pwd) | ||
FULLTARGET="$PWD/$TARGET" | ||
|
||
# Add a temporary single-rule eslint.config.mjs file. | ||
cat > "$TARGET/eslint.config.mjs" <<EOF | ||
import makeBaseConfig from 'jetpack-js-tools/eslintrc/base.mjs'; | ||
|
||
// This directory is copy-pasted from elsewhere, but we still need to run this one rule over it. | ||
export default [ | ||
// Import base config, but no rules. | ||
...makeBaseConfig( import.meta.url ).map( block => ( { ...block, rules: {} } ) ), | ||
// Enable just this one rule. | ||
{ | ||
rules: { | ||
"@wordpress/i18n-text-domain": [ "error", { allowedTextDomain: "jetpack-mu-wpcom" } ], | ||
} | ||
}, | ||
]; | ||
EOF | ||
( cd "$BASE" && pnpm run lint-file --no-inline-config --no-ignore --fix "$FULLTARGET" ) | ||
rm "$TARGET/eslint.config.mjs" | ||
|
||
echo "Changing JS translation function call to avoid bad minification..." | ||
pnpm --package=jscodeshift dlx jscodeshift -t ./bin/sync-newspack-blocks-formatter.js --extensions=js $TARGET | ||
|
||
# Add temporary PHPCS config file. | ||
PHPCSSTANDARDFILE="$TARGET/phpcs.tmp.xml" | ||
cat > "$PHPCSSTANDARDFILE" <<EOF | ||
<?xml version="1.0"?> | ||
<ruleset> | ||
<rule ref="Jetpack.Functions.I18n"> | ||
<properties> | ||
<property name="text_domain" value="jetpack-mu-wpcom" /> | ||
</properties> | ||
</rule> | ||
|
||
<rule ref="WordPress.Utils.I18nTextDomainFixer"> | ||
<properties> | ||
<property name="old_text_domain" type="array"> | ||
<element value="newspack-blocks" /> | ||
</property> | ||
<property name="new_text_domain" value="jetpack-mu-wpcom" /> | ||
</properties> | ||
</rule> | ||
</ruleset> | ||
EOF | ||
echo "Changing PHP textdomain to match jetpack-mu-wpcom..." | ||
../../../vendor/bin/phpcbf --standard=./.phpcs.dir.xml --filter=../../../vendor/automattic/jetpack-phpcs-filter/src/PhpcsFilter.php --runtime-set jetpack-filter-no-ignore -q $TARGET | ||
|
||
"$BASE"/vendor/bin/phpcbf --standard="$PHPCSSTANDARDFILE" "$TARGET" | ||
rm "$PHPCSSTANDARDFILE" | ||
|
||
# Add textdomain to block.json | ||
echo "Adding textdomain to all block.json files..." | ||
for block_json_file in "$TARGET"/blocks/*/block.json; do | ||
TMPFILE=$(mktemp) | ||
jq --tab '. += {"textdomain": "jetpack-mu-wpcom"}' "$block_json_file" > "$TMPFILE" | ||
mv "$TMPFILE" "$block_json_file" | ||
done | ||
echo Sync done. |
4 changes: 4 additions & 0 deletions
4
projects/packages/jetpack-mu-wpcom/changelog/update-synced_newspack_blocks
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: changed | ||
|
||
Newspack Blocks: Updated to version 4.5.2. |
46 changes: 23 additions & 23 deletions
46
projects/packages/jetpack-mu-wpcom/src/features/newspack-blocks/README.md
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
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
8 changes: 0 additions & 8 deletions
8
...kages/jetpack-mu-wpcom/src/features/newspack-blocks/synced-newspack-blocks/.phpcs.dir.xml
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want you could source the file from the monorepo root
tools/includes/proceed_p.sh
to use our fancy function for doing prompts like this.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any advantage of sourcing vs a simple
read
? :^)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
proceed_p
function handles a bunch of edge cases. It doesn't matter a whole lot though. 🤷