Skip to content

Commit 9bcb06b

Browse files
authored
Adding a composer dev command to host the plugin and npm (#469)
* Add wp-env, adjust phpstan removal * Adding a composer dev command to host the plugin and npm * Document composer dev * Add a scheme
1 parent d0ff5e9 commit 9bcb06b

File tree

5 files changed

+112
-72
lines changed

5 files changed

+112
-72
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
/tests export-ignore
1414
/configure.php export-ignore
1515
/Makefile export-ignore
16+
/.wp-env.json export-ignore
1617

1718
#
1819
# Auto detect text files and perform LF normalization.

.wp-env.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"$schema": "https://schemas.wp.org/trunk/wp-env.json",
3+
"core": null,
4+
"plugins": [ "." ]
5+
}

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,22 @@ $plugin = Create_WordPress_Plugin\Skeleton\Example_Plugin();
6464
$plugin->perform_magic();
6565
```
6666
<!--front-end-->
67+
## Development
68+
69+
To setup a WordPress installation and run the plugin in a local environment, you
70+
can use `wp-env` via the `composer dev` command:
71+
72+
```sh
73+
npm install
74+
composer dev
75+
```
76+
77+
The command will start a local WordPress environment with the plugin activated
78+
while also running the front-end assets build process. You can also run `npm run
79+
start` to start the front-end assets build process separately. The front-end
80+
assets will be compiled into the `build` directory and will be enqueued
81+
automatically by the plugin.
82+
6783
## Testing
6884

6985
Run `npm run test` to run Jest tests against JavaScript files. Run

composer.json

Lines changed: 73 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,77 @@
11
{
2-
"name": "alleyinteractive/create-wordpress-plugin",
3-
"description": "A skeleton WordPress plugin",
4-
"type": "wordpress-plugin",
5-
"keywords": [
6-
"alleyinteractive",
7-
"create-wordpress-plugin"
8-
],
9-
"homepage": "https://github.com/alleyinteractive/create-wordpress-plugin",
10-
"license": "GPL-2.0-or-later",
11-
"authors": [
12-
{
13-
"name": "author_name",
14-
"email": "email@domain.com"
15-
}
16-
],
17-
"require": {
18-
"php": "^8.2",
19-
"alleyinteractive/composer-wordpress-autoloader": "^1.0",
20-
"alleyinteractive/wp-type-extensions": "^4.0"
21-
},
22-
"require-dev": {
23-
"alleyinteractive/alley-coding-standards": "^2.0",
24-
"mantle-framework/testkit": "^1.4",
25-
"rector/rector": "^2.0",
26-
"szepeviktor/phpstan-wordpress": "^2.0"
27-
},
28-
"config": {
29-
"allow-plugins": {
30-
"alleyinteractive/composer-wordpress-autoloader": true,
31-
"dealerdirect/phpcodesniffer-composer-installer": true,
32-
"pestphp/pest-plugin": true
33-
},
34-
"sort-packages": true
35-
},
36-
"autoload-dev": {
37-
"psr-4": {
38-
"Alley\\WP\\Create_WordPress_Plugin\\Tests\\": "tests"
39-
}
40-
},
41-
"extra": {
42-
"wordpress-autoloader": {
43-
"autoload": {
44-
"Alley\\WP\\Create_WordPress_Plugin\\": "src"
45-
}
46-
}
2+
"name": "alleyinteractive/create-wordpress-plugin",
3+
"description": "A skeleton WordPress plugin",
4+
"type": "wordpress-plugin",
5+
"keywords": [
6+
"alleyinteractive",
7+
"create-wordpress-plugin"
8+
],
9+
"homepage": "https://github.com/alleyinteractive/create-wordpress-plugin",
10+
"license": "GPL-2.0-or-later",
11+
"authors": [
12+
{
13+
"name": "author_name",
14+
"email": "email@domain.com"
15+
}
16+
],
17+
"require": {
18+
"php": "^8.2",
19+
"alleyinteractive/composer-wordpress-autoloader": "^1.0",
20+
"alleyinteractive/wp-type-extensions": "^4.0"
21+
},
22+
"require-dev": {
23+
"alleyinteractive/alley-coding-standards": "^2.0",
24+
"mantle-framework/testkit": "^1.4",
25+
"rector/rector": "^2.0",
26+
"szepeviktor/phpstan-wordpress": "^2.0"
27+
},
28+
"config": {
29+
"allow-plugins": {
30+
"alleyinteractive/composer-wordpress-autoloader": true,
31+
"dealerdirect/phpcodesniffer-composer-installer": true,
32+
"pestphp/pest-plugin": true
4733
},
48-
"minimum-stability": "dev",
49-
"prefer-stable": true,
50-
"scripts": {
51-
"phpcbf": "phpcbf .",
52-
"phpcs": "phpcs .",
53-
"phpstan": "phpstan --memory-limit=512M",
54-
"lint": [
55-
"@phpcs",
56-
"@phpstan",
57-
"@rector"
58-
],
59-
"lint:fix": [
60-
"@rector:fix",
61-
"@phpcbf"
62-
],
63-
"phpunit": "phpunit",
64-
"rector:fix": "rector process",
65-
"rector": "rector process --dry-run",
66-
"release": "npx @alleyinteractive/create-release@latest",
67-
"test": [
68-
"@lint",
69-
"@phpunit"
70-
]
34+
"sort-packages": true
35+
},
36+
"autoload-dev": {
37+
"psr-4": {
38+
"Alley\\WP\\Create_WordPress_Plugin\\Tests\\": "tests"
39+
}
40+
},
41+
"extra": {
42+
"wordpress-autoloader": {
43+
"autoload": {
44+
"Alley\\WP\\Create_WordPress_Plugin\\": "src"
45+
}
7146
}
47+
},
48+
"minimum-stability": "dev",
49+
"prefer-stable": true,
50+
"scripts": {
51+
"dev": [
52+
"Composer\\Config::disableProcessTimeout",
53+
"npx concurrently -c \"#93c5fd,#fdba74\" \"composer serve\" \"npm run start\" --names=server,webpack"
54+
],
55+
"phpcbf": "phpcbf .",
56+
"phpcs": "phpcs .",
57+
"phpstan": "phpstan --memory-limit=512M",
58+
"lint": [
59+
"@phpcs",
60+
"@phpstan",
61+
"@rector"
62+
],
63+
"lint:fix": [
64+
"@rector:fix",
65+
"@phpcbf"
66+
],
67+
"phpunit": "phpunit",
68+
"rector:fix": "rector process",
69+
"rector": "rector process --dry-run",
70+
"release": "npx @alleyinteractive/create-release@latest",
71+
"serve": "command -v wp-env >/dev/null 2>&1 || npm install -g @wordpress/env && wp-env start",
72+
"test": [
73+
"@lint",
74+
"@phpunit"
75+
]
76+
}
7277
}

configure.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ function remove_project_files(): void {
203203
'.gitignore',
204204
'.gitattributes',
205205
'.github',
206+
'.wp-env.json',
206207
'LICENSE',
207208
];
208209

@@ -389,13 +390,15 @@ function remove_phpstan(): void {
389390
if ( file_exists( 'composer.json' ) ) {
390391
$composer_json = (array) json_decode( (string) file_get_contents( 'composer.json' ), true );
391392

393+
unset( $composer_json['require-dev']['szepeviktor/phpstan-wordpress'] ); // @phpstan-ignore-line
394+
392395
if ( isset( $composer_json['scripts']['phpstan'] ) ) { // @phpstan-ignore-line
393396
unset( $composer_json['scripts']['phpstan'] ); // @phpstan-ignore-line
394397

395-
$composer_json['scripts']['test'] = [ // @phpstan-ignore-line
396-
'@phpcs',
397-
'@phpunit',
398-
];
398+
$composer_json['scripts']['lint'] = array_filter(
399+
$composer_json['scripts']['lint'] ?? [],
400+
fn ( string $script ) => ! str_contains( $script, 'phpstan' ),
401+
);
399402

400403
file_put_contents( 'composer.json', json_encode( $composer_json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) );
401404
}
@@ -668,6 +671,16 @@ function enable_sqlite_testing(): void {
668671
]
669672
);
670673

674+
if ( file_exists( 'composer.json' ) ) {
675+
$plugin_composer = (array) json_decode( (string) file_get_contents( 'composer.json' ), true );
676+
677+
if ( isset( $plugin_composer['scripts']['dev'] ) ) {
678+
unset( $plugin_composer['scripts']['dev'] );
679+
680+
file_put_contents( 'composer.json', json_encode( $plugin_composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) );
681+
}
682+
}
683+
671684
remove_assets_readme( keep_contents: false );
672685
remove_assets_require();
673686
remove_assets_test();

0 commit comments

Comments
 (0)