Skip to content

Commit

Permalink
Merge pull request #32 from wp-oop/feature/rework-modules
Browse files Browse the repository at this point in the history
Port module setup from latest project
  • Loading branch information
XedinUnknown committed Aug 12, 2023
2 parents f03094d + 9ce4942 commit 4d8915e
Show file tree
Hide file tree
Showing 47 changed files with 1,048 additions and 192 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ PROJECT_MOUNT_PATH=/var/www/html/wp-content/plugins/plugin
DOCROOT_PATH=/var/www/html
BUILD_ROOT_PATH=/app/
PROJECT_NAME=me_plugin
LANGS_PATH=languages

PHP_BUILD_VERSION=7.2
PHP_TEST_VERSION=7.4
PHP_MEMORY_LIMIT=256M
WORDPRESS_VERSION=5.6
NODE_VERSION=20.2.0

DB_ROOT_PASSWORD=root
DB_NAME=wordpress
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
php-version: ${{ matrix.php-versions }}

- name: Analysing source code
run: find ./src/ ./inc/ ./tests/ -type f -name '*.php' -print0 | xargs -0 -L 1 -P 4 -- php -l
run: find ./src/ ./tests/ -type f -name '*.php' -print0 | xargs -0 -L 1 -P 4 -- php -l

- name: Validate composer.json and composer.lock
run: composer validate
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/vendor/
/node_modules/
/build/
/wordpress/
/languages/
/.idea/workspace.xml
/.idea/codeStyles/
/.idea/inspectionProfiles/
Expand Down
19 changes: 12 additions & 7 deletions .idea/php.xml

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

4 changes: 2 additions & 2 deletions .idea/phpunit.xml

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

8 changes: 6 additions & 2 deletions .idea/plugin.iml

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

16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Changed
- Renamed `modules.local` to simply `modules` (#28).
- Now using [`dhii/services`][] to declare services (#31).
- Reworked modules (#32):
* No more `inc`: sources live in `src`.
* No more `module.php`: simply autoload them.
* Main module: `modules` entirely optional.
* Reworked bootstrap: now more re-usable.
* Reworked tests: now with base classes for different "levels".

### Fixed
- Missing WP plugin API functions (#32).

### Added
- WordPress directory mapping: easier debugging, and more IDE features (#32).
- Modules added to tools: tests being run, code being scanned (#32).
- Modular build script: build the plugin, including modules, in place (#32).
- Application init test (#32).
- Node and WP-CLI now parts of relevant services (#32).

### Added
- Now building on PHP 8.1 and 8.2 as well (#30).
Expand Down
55 changes: 55 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
MODULE_DIRS := $(wildcard modules/* )
.PHONY: all \
build \
install \
install-php \
i18n \
i18n-makepot \
qa \
scan \
test \
test-php \
$(MODULE_DIRS)

include .env

all: build

build: install
$(MAKE) build-modules
$(MAKE) i18n
wait

build-modules: $(MODULE_DIRS)

$(MODULE_DIRS):
@if [ -f "$@/Makefile" ]; then echo "$@/Makefile exists!"; $(MAKE) -C $@ build; fi

install:
$(MAKE) install-php

install-php: composer.lock
composer install

i18n: i18n-makepot i18n-makemo

i18n-makepot:
wp i18n make-pot . $(LANGS_PATH)/strings.pot --allow-root

i18n-makemo:
wp i18n make-mo $(LANGS_PATH) --allow-root

qa:
$(MAKE) test
$(MAKE) scan
wait

test:
$(MAKE) test-php

test-php:
vendor/bin/phpunit

scan:
vendor/bin/psalm
vendor/bin/phpcs -s
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ Use this project as a starter for your [modular][modularity] WordPress plugin!
- **Modularity** - Keep concerns separated into [modules][modularity], which can be freely
moved out of the package at any time thanks to the [`composer-merge-plugin`][].

- **Build Script** - Use a single [GNU Make][] entrypoint to build the plugin in place,
including modules.


### Usage

#### Getting Started
Expand Down Expand Up @@ -118,8 +122,40 @@ Use this project as a starter for your [modular][modularity] WordPress plugin!
case, they should be added to the directory `modules`. One such module, the `core`
module of the plugin, is already included in the package. Its `composer.json` should
also be personalized, just like the `composer.json` of this package.

3. Build everything

1. Build the environment.

In order to develop, build, and test the plugin, certain things are required first.
These include: the database, WordPress core, PHP, Composer, and web server.
The project ships with all of this pre-configured, and the Docker services must first
be built:

```
docker-compose build
```
2. Build the plugin in place.

In order for the project source files to have the desired effect,
they first must be built into their runtime version. This may include:
installing dependencies, transpilation, copying or archiving files, whatever
the modules require to have desired effect, etc.
At the same time, a single entrypoint to various tasks performed as part
of the project build or QA allows for more centralized and automated control
over the project.

For this reason, the Makefile is shipped with the project, declaring commands
for commonly run tasks, including build. Run the following command to build
the plugin, including modules, in the plugin source directory: this makes it
possible to preview and test changes instantly after they are made.

```
docker-compose run --rm build make build
```
3. Spin up the dev environment
4. Spin up the dev environment

Run the following command in the terminal. If you use Docker Machine, you will need to
start it and configure your environment first with [`docker-machine start`][] and
Expand Down Expand Up @@ -316,6 +352,7 @@ provide assistance during coding.
[Psalm]: https://psalm.dev/
[PHPCS]: https://github.com/squizlabs/PHP_CodeSniffer
[PHPCBF]: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Fixing-Errors-Automatically
[GNU Make]: https://www.gnu.org/software/make/manual/make.html
[GitHub Actions]: https://github.com/features/actions
[Dhii modules]: https://github.com/Dhii/module-interface
[hosts file]: https://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-your-hosts-file/
Expand Down
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
"php": "^7.2 | ^8.0",
"dhii/module-interface": "^0.3-alpha1",
"psr/container": "^1.0",
"dhii/versions": "^0.1.0-alpha2",
"dhii/containers": "^0.1.4-alpha2",
"dhii/services": "^0.1.1-alpha3",
"wp-oop/wordpress-interface": "^0.1.0-alpha1",
"wikimedia/composer-merge-plugin": "^2.0.1"
},
"require-dev": {
"phpunit/phpunit": "^7.0 | ^8.0 | ^9.0",
"brain/monkey": "^2.6",
"vimeo/psalm": "^3.11.7 | ^4.0",
"slevomat/coding-standard": "^6.0",
"webmozart/path-util": "^2.3@stable",
Expand All @@ -32,7 +35,7 @@
},
"autoload-dev": {
"psr-4": {
"Me\\Plugin\\Test\\": "tests"
"Me\\Plugin\\Test\\": "tests/phpunit"
}
},
"extra": {
Expand Down
Loading

0 comments on commit 4d8915e

Please sign in to comment.