Skip to content

Commit 01418ab

Browse files
committed
refactor: streamline custom blocks build/lint process
- move example blocks into subfolders of src directory - streamline build process for example blocks - support view scripts in example blocks - move wp-scripts to top-level package.json - delete unnecessary dotfiles - update instructions for using/writing custom blocks - use same linters for plugins and other JS/SCSS - remove formatting script of limited use
1 parent 0f71a0c commit 01418ab

31 files changed

+19318
-22474
lines changed

.eslintrc

+20-25
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,22 @@
11
{
2-
"env": {
3-
"es6": true,
4-
"browser": true,
5-
"node": true
6-
},
7-
"parserOptions": {
8-
"sourceType": "module",
9-
"ecmaVersion": "latest"
10-
},
11-
"extends": [
12-
"eslint:recommended",
13-
"plugin:react/recommended",
14-
"plugin:react-hooks/recommended",
15-
"prettier"
16-
],
17-
"settings": {
18-
"react": {
19-
"version": "^18.2.0"
20-
}
21-
},
22-
"ignorePatterns": ["src/js/vendor/**/*.js"],
23-
"rules": {
24-
"react/react-in-jsx-scope": 0,
25-
"react/prop-types": 0
26-
}
2+
"env": {
3+
"es6": true,
4+
"browser": true,
5+
"node": true
6+
},
7+
"parserOptions": {
8+
"sourceType": "module",
9+
"ecmaVersion": "latest"
10+
},
11+
"extends": ["eslint:recommended", "plugin:react/recommended", "plugin:react-hooks/recommended", "prettier"],
12+
"settings": {
13+
"react": {
14+
"version": "^18.2.0"
15+
}
16+
},
17+
"ignorePatterns": ["src/js/vendor/**/*.js", "src/plugins/**/build"],
18+
"rules": {
19+
"react/react-in-jsx-scope": 0,
20+
"react/prop-types": 0
21+
}
2722
}

.github/workflows/deploy.docker.yml

-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ jobs:
2626
- name: Install npm dependencies
2727
run: npm ci
2828

29-
- name: Install custom plugin npm dependencies
30-
run: npm run plugins:install
31-
3229
- name: Install PHP dependencies with Composer
3330
uses: php-actions/composer@v6
3431
with:

.github/workflows/deploy.pantheon.yml

-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@ jobs:
2626
- name: Install npm dependencies
2727
run: npm ci
2828

29-
- name: Install custom plugin npm dependencies
30-
run: npm run plugins:install
31-
3229
- name: Install PHP dependencies with Composer
3330
uses: php-actions/composer@v6
3431
with:

.github/workflows/validation.yml

-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,6 @@ jobs:
5050
- name: Install npm dependencies
5151
run: npm ci
5252

53-
- name: Install custom plugin npm dependencies
54-
run: npm run plugins:install
55-
5653
- name: Lint
5754
run: npm run lint
5855
env:

.prettierignore

+2
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,5 @@ theme
3636
uploads
3737
vendor
3838
plugins
39+
!src/plugins
40+
src/plugins/**/build

CONTRIBUTING.md

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ Here's a few things you should know before you submit your PR:
1111

1212
- Clone/Fork the repo
1313
- Install dependencies: `npm install`
14-
- Install plugin dependencies `npm run plugins:install`
1514
- Start the development process `npm start`
1615
- Ensure linters pass: `npm run lint`
1716
- Ensure tests pass: `npm test`

README.md

+11-14
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ This project requires [Docker][docker] and [Node.js][node] for local development
4141

4242
1. Duplicate `.env.example` and rename it `.env`, changing variables [as needed](#setting-local-environment-variables)
4343
1. Run `npm install`
44-
1. Run `npm run plugins:install` (this is necessary for the plugin for custom blocks)
4544
1. Either run `npm start` or run `npm run build:dev` and `npm run serve:dev` in separate terminals
4645
1. Based on whether you have a database to import or not, do one of the following:
4746
- Visit `https://localhost:8000/wp-admin` and run through the WordPress setup
@@ -403,34 +402,32 @@ This is a non-comprehensive list of plugins that we have found useful on other p
403402

404403
## Custom Blocks
405404

406-
We have a plugin for custom blocks called `example-blocks`, which lives in `src/plugins`. For the blocks to be available in WordPress, these steps must be taken:
405+
We have a plugin for custom blocks called `example-blocks`, which lives in `src/plugins`. For the blocks to be available in WordPress, you must activate the "Example Blocks" plugin from the WordPress admin's plugins page.
407406

408-
1. Run `npm run plugins:install` to install the plugin's npm dependencies
409-
1. Run `npm start` for local development (this runs the plugin's `npm start` command)
410-
1. Activate the "Example Blocks" plugin from the WordPress menu
411-
412-
For production builds, running `npm run build:prod` will also work, outputting production bundles for the blocks.
407+
The plugins can be built with `npm run plugins:dev` or `npm run plugins:build`, but that generally shouldn't be necessary, since those scripts are run as part of the standard `npm start` and `npm run build:prod` scripts.
413408

414409
### Creating a New Custom Block
415410

416411
Follow these steps to create a new custom block and wire it up with the normal development/build processes:
417412

418-
1. Create a new folder at `src/plugins/example-blocks/blocks/<block-name>`
413+
1. Create a new folder at `src/plugins/example-blocks/src/<block-name>`
419414
1. Either copy files from another block or manually create these files:
420415
- `block.json`: configuration/metadata for the block
421-
- `src/index.js`: entry point for the JS bundle
422-
- `src/edit.js`: the component used while editing
423-
- `src/save.js`: the component rendered on the site
424-
- `src/editor.scss`: custom styles for the editor view
425-
- `src/style.scss`: custom styles for the block when rendered on the site
426-
1. Configure the custom block by updating `block.json`, namely the `name`, `title`, `icon`, and `description` fields
416+
- `index.js`: entry point for the JS bundle
417+
- `edit.js`: the component used while editing
418+
- `save.js`: the component rendered on the site
419+
- `view.js`: any JS that needs to run when the block is rendered on a non-admin page (optional)
420+
- `editor.scss`: custom styles for the editor view
421+
- `style.scss`: custom styles for the block when rendered on the site
422+
1. Configure the custom block by updating `block.json`, namely the `name`, `title`, `icon`, and `description` fields. If you don't need a `view.js` file, delete the `viewScript` key.
427423
1. Implement the edit function, which will usually be form controls corresponding to attributes that you define in `index.js`
428424
1. Implement the save function, which will consume the attributes defined in `index.js` and render the block's desired markup
429425

430426
### Useful Resources
431427

432428
- [Create a Block Tutorial](https://developer.wordpress.org/block-editor/getting-started/create-block/)
433429
- [Component Reference](https://developer.wordpress.org/block-editor/reference-guides/components/)
430+
- [@wordpress/scripts Reference](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-scripts/)
434431

435432
## Deployment
436433

0 commit comments

Comments
 (0)