Skip to content

Commit 101f60c

Browse files
authored
Improve configuration script (#464)
* Use the proper command at the end * Remove asset method from plugin file after removing assets * Remove the phpstan paths for frontend assets * Fix the removal of front-end tests (previously took too much) * Switch to lint beingh used
1 parent 3dfb3cf commit 101f60c

File tree

2 files changed

+27
-16
lines changed

2 files changed

+27
-16
lines changed

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@
6565
"rector": "rector process --dry-run",
6666
"release": "npx @alleyinteractive/create-release@latest",
6767
"test": [
68-
"@phpcs",
69-
"@phpstan",
68+
"@lint",
7069
"@phpunit"
7170
]
7271
}

configure.php

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -284,28 +284,40 @@ function remove_assets_require(): void {
284284
return;
285285
}
286286

287-
file_put_contents(
288-
$plugin_file,
289-
trim( (string) preg_replace( '/require_once __DIR__ \. \'\/src\/assets.php\';\\n/s', '', $contents ) ?: $contents ) . PHP_EOL,
290-
);
287+
// Remove the assets.php require.
288+
$contents = (string) ( preg_replace( '/require_once __DIR__ \. \'\/src\/assets.php\';\\n/s', '', $contents ) ?: $contents );
289+
290+
// Remove the load_scripts() call.
291+
$contents = str_replace( "load_scripts();\n", '', $contents );
292+
293+
file_put_contents( $plugin_file, trim( $contents ) . PHP_EOL );
291294
}
292295

293-
/* Remove the node tests from within the all-pr-tests.yml file. */
296+
/* Remove the tests that support front-end assets. */
294297
function remove_assets_test(): void {
295298
$file = __DIR__ . '/.github/workflows/all-pr-tests.yml';
296299

297-
if ( ! file_exists( $file ) ) {
298-
return;
300+
if ( file_exists( $file ) ) {
301+
$contents = preg_replace(
302+
'/(- name: Run Node Tests.*)(- name: Run)/s',
303+
'$2',
304+
file_get_contents( $file ),
305+
);
306+
307+
file_put_contents( $file, $contents );
299308
}
300309

310+
// Replace the phpstan paths.
311+
if ( file_exists( 'phpstan.neon' ) ) {
312+
$phpstan_contents = file_get_contents( 'phpstan.neon' );
301313

302-
$contents = preg_replace(
303-
'/(- name: Run Node Tests.*)(- name:)/s',
304-
'$2',
305-
file_get_contents( $file ),
306-
);
314+
if ( ! empty( $phpstan_contents ) ) {
315+
$phpstan_contents = str_replace( '- blocks/', '# - blocks/', $phpstan_contents );
316+
$phpstan_contents = str_replace( '- entries/', '# - entries/', $phpstan_contents );
307317

308-
file_put_contents( $file, $contents );
318+
file_put_contents( 'phpstan.neon', $phpstan_contents );
319+
}
320+
}
309321
}
310322

311323
function determine_separator( string $path ): string {
@@ -814,7 +826,7 @@ function enable_sqlite_testing(): void {
814826
// Offer some information about built releases if the workflow still exists.
815827
if ( file_exists( '.github/workflows/built-release.yml' ) ) {
816828
echo <<<INFO
817-
When you are ready to release the plugin, you can run `npm run release`
829+
When you are ready to release the plugin, you can run `composer release`
818830
to generate a new release.
819831
820832
The Built Release workflow will take care of the rest by building the plugin's

0 commit comments

Comments
 (0)