Skip to content
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

Try canonical block plugins using the Time to Read block #61504

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
30673e9
add time to read block
Apr 24, 2024
d95e917
Update settings to register and render block
creativecoder Apr 24, 2024
6721a9f
Updates time to read block plugin
creativecoder May 7, 2024
11462ad
Remove example-static plugin
creativecoder May 8, 2024
b0f4a71
Adds small fixes/edits
creativecoder May 8, 2024
b08f7ad
Resolve linting issues and integrate phpcs config better with monorepo
creativecoder May 16, 2024
85c208c
Fix merged changes to phpcs.xml.dist
creativecoder May 17, 2024
df2f4a1
Fix lint:pkg-json errors
creativecoder May 17, 2024
12fb053
Runs plugin commands from root of repo
creativecoder Jun 4, 2024
548f82b
Adds e2e test for Time to Read block
creativecoder Jun 10, 2024
a24347f
Improve e2e tests
creativecoder Jun 10, 2024
e56ed35
Adds phpunit tests
creativecoder Jun 12, 2024
6e4ceee
Adds block plugins to snapshot tests
creativecoder Jun 12, 2024
ba61b17
Uses block supports for textAlign rather than manual attribute
creativecoder Jun 13, 2024
eb0d85b
Remove var_dump statement
creativecoder Jun 18, 2024
9f5a4c0
WIP Adds plugins readme
creativecoder Jun 25, 2024
f52c7b4
Removes plugin package lock file
creativecoder Jul 1, 2024
b8db311
Expands plugins readme with details about file structure, testing, etc
creativecoder Jul 1, 2024
308a111
Attempts to get unit tests working in CI
creativecoder Jul 1, 2024
3ce89b0
Moves block.json file to make it accessible in phpunit test environment
creativecoder Jul 1, 2024
070d7dd
Updates block.json path glob for fixture tests
creativecoder Jul 1, 2024
ca79a46
Updates readme with block.json location
creativecoder Jul 1, 2024
cf4ee72
Adds .npmpackagejsonlintrc.json for plugins directory to use WordPres…
creativecoder Jul 1, 2024
9b9d044
Excludes plugins/ from core backport check
creativecoder Jul 1, 2024
7dc75fa
Updates the description to indicate the reading time is an estimate
creativecoder Jul 1, 2024
6e204c9
Updates backport check exclusion
creativecoder Jul 1, 2024
8e1b30d
Moves scripts for php into bin/ folder
creativecoder Jul 3, 2024
0c10e45
Updates block plugin description in plugins readme
creativecoder Jul 3, 2024
417c8db
Switches to use mappings in wp-env so plugins are not activated by de…
creativecoder Jul 3, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -466,5 +466,16 @@ module.exports = {
'react/react-in-jsx-scope': 'error',
},
},
{
files: [ 'plugins/time-to-read-block/src/**' ],
rules: {
'@wordpress/i18n-text-domain': [
'error',
{
allowedTextDomain: 'time-to-read-block',
},
],
},
},
],
};
1 change: 1 addition & 0 deletions .github/workflows/check-backport-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
- 'phpunit/**'
- '!phpunit/experimental/**'
- '!phpunit/blocks/**'
- '!phpunit/plugins/**'
- 'packages/**/*.php'
- '!packages/block-library/**'
- '!packages/e2e-tests/**'
Expand Down
3 changes: 3 additions & 0 deletions .wp-env.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"core": "WordPress/WordPress",
"plugins": [ "." ],
"themes": [ "./test/emptytheme" ],
"mappings": {
"wp-content/plugins/time-to-read-block": "./plugins/time-to-read-block"
},
"env": {
"tests": {
"mappings": {
Expand Down
10 changes: 10 additions & 0 deletions bin/format-php.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

./vendor/bin/phpcbf --standard=phpcs.xml.dist --report-summary --report-source

for dir in ./plugins/*/
do
if [ -d "$dir" ] && [ -f "$dir/phpcs.xml.dist" ]; then
./vendor/bin/phpcbf --standard="$dir/phpcs.xml.dist" --report-summary --report-source
fi
done
10 changes: 10 additions & 0 deletions bin/lint-php.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

./vendor/bin/phpcs --standard=phpcs.xml.dist

for dir in ./plugins/*/
do
if [ -d "$dir" ] && [ -f "$dir/phpcs.xml.dist" ]; then
./vendor/bin/phpcs --standard="$dir/phpcs.xml.dist"
fi
done
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
"composer/installers": "~1.0"
},
"scripts": {
"format": "phpcbf --standard=phpcs.xml.dist --report-summary --report-source",
"lint": "phpcs --standard=phpcs.xml.dist",
"format": "bash ./bin/format-php.sh",
"lint": "bash ./bin/lint-php.sh",
"test": "phpunit",
"test:watch": "phpunit-watcher watch < /dev/tty"
}
Expand Down
34 changes: 34 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"config": {
"IS_GUTENBERG_PLUGIN": true
},
"workspaces": [
"plugins/*"
],
"dependencies": {
"@wordpress/a11y": "file:packages/a11y",
"@wordpress/annotations": "file:packages/annotations",
Expand Down Expand Up @@ -268,12 +271,14 @@
"jsdom": "22.1.0"
},
"scripts": {
"build": "npm run build:packages && wp-scripts build",
"build": "npm run build:packages && concurrently 'npm run build:plugins' 'wp-scripts build'",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question to be asked is whether we want to build plugins when we're working on Gutenberg. Building plugins for now is probably very fast but I expect that as we increase the number of canonical blocks, it might become a burden and developers would want to focus on one thing in particular: Gutenberg, a specific block... An option to build everything, would be handy too but I wonder if it should be the default or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My personal expectation is that the primary build command will build the entire project, and that I shouldn't need to run any other commands for a complete build. That said, having a build:gutenberg or similar that only builds the main Gutenberg plugin (and packages) seems like a good idea.

"build:analyze-bundles": "npm run build -- --webpack-bundle-analyzer",
"build:package-types": "node ./bin/packages/validate-typescript-version.js && ( tsc --build || ( echo 'tsc failed. Try cleaning up first: `npm run clean:package-types`'; exit 1 ) ) && node ./bin/packages/check-build-type-declaration-files.js",
"prebuild:packages": "npm run clean:packages && lerna run build",
"build:packages": "npm run --silent build:package-types && node ./bin/packages/build.js",
"build:plugin-zip": "bash ./bin/build-plugin-zip.sh",
"build:plugins": "npm run build --workspace ./plugins",
"build:plugin-zip": "concurrently 'npm run build:plugin-zip:plugins' 'bash ./bin/build-plugin-zip.sh'",
"build:plugin-zip:plugins": "npm run plugin-zip --workspace ./plugins",
youknowriad marked this conversation as resolved.
Show resolved Hide resolved
"clean:package-types": "tsc --build --clean && rimraf \"./packages/*/build-types\"",
"clean:packages": "rimraf \"./packages/*/@(build|build-module|build-style)\"",
"dev": "cross-env NODE_ENV=development npm run build:packages && concurrently \"wp-scripts start\" \"npm run dev:packages\"",
Expand Down
96 changes: 4 additions & 92 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,8 @@
<ruleset name="WordPress Coding Standards for Gutenberg Plugin">
<description>Sniffs for WordPress plugins, with minor modifications for Gutenberg</description>

<!-- Check for cross-version support for PHP 7.2 and higher. -->
<config name="testVersion" value="7.2-"/>
<rule ref="PHPCompatibilityWP">
<include-pattern>*\.php$</include-pattern>
</rule>

<rule ref="WordPress-Core"/>
<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array">
<element value="gutenberg"/>
<element value="default"/>
</property>
</properties>
</rule>

<rule ref="VariableAnalysis.CodeAnalysis.VariableAnalysis">
<properties>
<property name="allowUnusedParametersBeforeUsed" value="true"/>
</properties>
</rule>

<rule ref="PEAR.Functions.FunctionCallSignature">
<properties>
<property name="allowMultipleArguments" value="false"/>
</properties>
</rule>

<rule ref="WordPress.WP.I18n.MissingArgDomainDefault">
<exclude-pattern>/lib/compat/*</exclude-pattern>
<exclude-pattern>/packages/block-library/src/*</exclude-pattern>
<exclude-pattern>/build/block-library/*</exclude-pattern>
</rule>

<arg value="ps"/>
<arg name="extensions" value="php"/>

<!-- Cache the scan results and re-use those for unchanged files on the next scan. -->
<arg name="cache" value=".cache/phpcs.json"/>

<!-- Check up to 20 files simultaneously. -->
<arg name="parallel" value="20"/>
<!-- Import shared rules for monorepo -->
<rule ref="phpcs.xml.shared" />

<file>./bin</file>
<file>./gutenberg.php</file>
Expand All @@ -52,56 +12,6 @@
<file>./phpunit</file>
<file>./post-content.php</file>

<!-- Exclude generated files -->
<exclude-pattern>/packages/block-serialization-spec-parser/parser\.php$</exclude-pattern>
<exclude-pattern>/node_modules/*</exclude-pattern>
<exclude-pattern>/build/*</exclude-pattern>

<!-- Exclude third party libraries -->
<exclude-pattern>/vendor/*</exclude-pattern>
<exclude-pattern>/test/php/gutenberg-coding-standards/*</exclude-pattern>

<!-- Exclude files maintained in WordPress Core and backported to Gutenberg
DO NOT REMOVE these rules; these files are "built" artifacts from Core
and when they are removed it prevents keeping the repos in sync. -->
<exclude-pattern>/lib/compat/wordpress-*/html-api/*\.php$</exclude-pattern>

<!-- Ignore filename error since it requires WP core build process change -->
<rule ref="WordPress.Files.FileName.InvalidClassFileName">
<exclude-pattern>/phpunit/*</exclude-pattern>
<exclude-pattern>/packages/block-library/src/navigation/index\.php$</exclude-pattern>
</rule>

<!-- Ignore empty files in tests/gutenberg-test-themes -->
<rule ref="Internal.NoCodeFound">
<exclude-pattern>/test/gutenberg-test-themes/*</exclude-pattern>
</rule>

<!-- Exclude PHPUnit tests from file and class name sniffs (for Core parity). -->
<rule ref="WordPress.Files.FileName.NotHyphenatedLowercase">
<exclude-pattern>/phpunit/*</exclude-pattern>
<exclude-pattern>*\.asset\.php$</exclude-pattern>
</rule>
<rule ref="PEAR.NamingConventions.ValidClassName.Invalid">
<exclude-pattern>/phpunit/*</exclude-pattern>
</rule>

<!-- Enforce checks against redeclaration for functions and classes. -->
<rule ref="Gutenberg.CodeAnalysis.GuardedFunctionAndClassNames">
<exclude-pattern>/phpunit/*</exclude-pattern>
<exclude-pattern>/packages/*</exclude-pattern>
<exclude-pattern>/bin/generate-gutenberg-php\.php$</exclude-pattern>
<properties>
<property name="functionsWhiteList" type="array">
<element value="/^_?gutenberg.+/"/>
</property>
<property name="classesWhiteList" type="array">
<element value="/^Gutenberg.+/"/>
<element value="/^.+_Gutenberg$/"/>
</property>
</properties>
</rule>

<rule ref="Gutenberg.NamingConventions.ValidBlockLibraryFunctionName">
<include-pattern>/packages/block-library/src/*/*\.php$</include-pattern>
<properties>
Expand Down Expand Up @@ -156,6 +66,7 @@
</property>
</properties>
</rule>

<rule ref="Gutenberg.CodeAnalysis.ForbiddenFunctionsAndClasses">
<include-pattern>/packages/block-library/src/.+/*\.php$</include-pattern>
<!--
Expand All @@ -175,6 +86,7 @@
</property>
</properties>
</rule>

<rule ref="Gutenberg.Commenting.SinceTag">
<!-- The sniff ensures that functions have a valid @since tag but skips checking experimental blocks. -->
<include-pattern>/packages/block-library/src/.+/*\.php$</include-pattern>
Expand Down
97 changes: 97 additions & 0 deletions phpcs.xml.shared
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
<?xml version="1.0"?>
<ruleset name="WordPress Coding Standards for Gutenberg monorepo">
<description>Sniffs defaults for all PHP files in the Gutenberg monorepo</description>

<!-- Check for cross-version support for PHP 7.2 and higher. -->
<config name="testVersion" value="7.2-"/>
<rule ref="PHPCompatibilityWP">
<include-pattern>*\.php$</include-pattern>
</rule>

<rule ref="WordPress-Core"/>
<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array">
<element value="gutenberg"/>
<element value="default"/>
</property>
</properties>
</rule>

<rule ref="VariableAnalysis.CodeAnalysis.VariableAnalysis">
<properties>
<property name="allowUnusedParametersBeforeUsed" value="true"/>
</properties>
</rule>

<rule ref="PEAR.Functions.FunctionCallSignature">
<properties>
<property name="allowMultipleArguments" value="false"/>
</properties>
</rule>

<rule ref="WordPress.WP.I18n.MissingArgDomainDefault">
<exclude-pattern>/lib/compat/*</exclude-pattern>
<exclude-pattern>/packages/block-library/src/*</exclude-pattern>
<exclude-pattern>/build/block-library/*</exclude-pattern>
</rule>

<arg value="ps"/>
<arg name="extensions" value="php"/>

<!-- Cache the scan results and re-use those for unchanged files on the next scan. -->
<arg name="cache" value=".cache/phpcs.json"/>

<!-- Check up to 20 files simultaneously. -->
<arg name="parallel" value="20"/>

<!-- Exclude generated files -->
<exclude-pattern>/packages/block-serialization-spec-parser/parser\.php$</exclude-pattern>
<exclude-pattern>/node_modules/*</exclude-pattern>
<exclude-pattern>/build/*</exclude-pattern>

<!-- Exclude third party libraries -->
<exclude-pattern>/vendor/*</exclude-pattern>
<exclude-pattern>/test/php/gutenberg-coding-standards/*</exclude-pattern>

<!-- Exclude files maintained in WordPress Core and backported to Gutenberg
DO NOT REMOVE these rules; these files are "built" artifacts from Core
and when they are removed it prevents keeping the repos in sync. -->
<exclude-pattern>/lib/compat/wordpress-*/html-api/*\.php$</exclude-pattern>

<!-- Ignore filename error since it requires WP core build process change -->
<rule ref="WordPress.Files.FileName.InvalidClassFileName">
<exclude-pattern>/phpunit/*</exclude-pattern>
<exclude-pattern>/packages/block-library/src/navigation/index\.php$</exclude-pattern>
</rule>

<!-- Ignore empty files in tests/gutenberg-test-themes -->
<rule ref="Internal.NoCodeFound">
<exclude-pattern>/test/gutenberg-test-themes/*</exclude-pattern>
</rule>

<!-- Exclude PHPUnit tests from file and class name sniffs (for Core parity). -->
<rule ref="WordPress.Files.FileName.NotHyphenatedLowercase">
<exclude-pattern>/phpunit/*</exclude-pattern>
<exclude-pattern>*\.asset\.php$</exclude-pattern>
</rule>
<rule ref="PEAR.NamingConventions.ValidClassName.Invalid">
<exclude-pattern>/phpunit/*</exclude-pattern>
</rule>

<!-- Enforce checks against redeclaration for functions and classes. -->
<rule ref="Gutenberg.CodeAnalysis.GuardedFunctionAndClassNames">
<exclude-pattern>/phpunit/*</exclude-pattern>
<exclude-pattern>/packages/*</exclude-pattern>
<exclude-pattern>/bin/generate-gutenberg-php\.php$</exclude-pattern>
<properties>
<property name="functionsWhiteList" type="array">
<element value="/^_?gutenberg.+/"/>
</property>
<property name="classesWhiteList" type="array">
<element value="/^Gutenberg.+/"/>
<element value="/^.+_Gutenberg$/"/>
</property>
</properties>
</rule>
</ruleset>
1 change: 1 addition & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<directory suffix="-test.php">./phpunit/</directory>
<directory suffix=".php">./phpunit/tests/</directory>
<directory suffix=".php">./phpunit/blocks/</directory>
<directory suffix=".php">./phpunit/plugins/</directory>
</testsuite>
</testsuites>
<groups>
Expand Down
Loading
Loading