Skip to content

Package update #16

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

Merged
merged 14 commits into from
Jul 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
44 changes: 44 additions & 0 deletions .github/workflows/all-pr-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: "All Pull Request Tests"

on:
pull_request:
branches:
- develop
types: [opened, synchronize, reopened, ready_for_review]

jobs:
# We use a single job to ensure that all steps run in the same environment and
# reduce the number of minutes used.
pr-tests:
# Don't run on draft PRs
if: github.event.pull_request.draft == false
# Timeout after 10 minutes
timeout-minutes: 10
# Define a matrix of PHP/WordPress versions to test against
strategy:
fail-fast: false
matrix:
php: [8.1, 8.2, 8.3]
wordpress: ["latest"]
runs-on: ubuntu-latest
# Cancel any existing runs of this workflow
concurrency:
group: ${{ github.workflow }}-${{ github.event_name }}-${{ github.event.pull_request.number || github.ref }}-P${{ matrix.php }}-WP${{ matrix.wordpress }}
cancel-in-progress: true
# Name the job in the matrix
name: "PR Tests PHP ${{ matrix.php }} WordPress ${{ matrix.wordpress }}"
steps:
- uses: actions/checkout@v4

- name: Run General Tests
# See https://github.com/alleyinteractive/action-test-general for more options
uses: alleyinteractive/action-test-general@develop

- name: Run PHP Tests
# See https://github.com/alleyinteractive/action-test-php for more options
uses: alleyinteractive/action-test-php@develop
with:
php-version: '${{ matrix.php }}'
wordpress-version: '${{ matrix.wordpress }}'
skip-wordpress-install: 'true'
skip-services: 'true' # Skip MySQL unless the library is not using SQLite testing.
14 changes: 0 additions & 14 deletions .github/workflows/coding-quality.yml

This file was deleted.

16 changes: 0 additions & 16 deletions .github/workflows/coding-standards.yml

This file was deleted.

16 changes: 0 additions & 16 deletions .github/workflows/unit-test.yml

This file was deleted.

2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
MAKEFLAGS += --no-builtin-rules

setup:
php ./configure.php

Expand Down
110 changes: 0 additions & 110 deletions buddy.yml

This file was deleted.

15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@
"alleyinteractive/composer-wordpress-autoloader": "^1.0"
},
"require-dev": {
"alleyinteractive/alley-coding-standards": "^1.0 || ^2.0",
"mantle-framework/testkit": "^0.12",
"nunomaduro/collision": "^5.0 || ^6.0",
"alleyinteractive/alley-coding-standards": "^2.0",
"mantle-framework/testkit": "^1.0",
"szepeviktor/phpstan-wordpress": "^1.3"
},
"config": {
Expand All @@ -32,13 +31,15 @@
},
"sort-packages": true
},
"autoload-dev": {
"psr-4": {
"Alley\\Create_PHP_Package\\Tests\\": "tests"
}
},
"extra": {
"wordpress-autoloader": {
"autoload": {
"Create_PHP_Package\\": "src"
},
"autoload-dev": {
"Create_PHP_Package\\Tests\\": "tests"
"Alley\\Create_PHP_Package\\": "src"
}
}
},
Expand Down
60 changes: 43 additions & 17 deletions configure.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function writeln( string $line ): void {
function run( string $command, string $dir = null ): string {
$command = $dir ? "cd {$dir} && {$command}" : $command;

return trim( shell_exec( $command ) );
return trim( (string) shell_exec( $command ) );
}

function str_after( string $subject, string $search ): string {
Expand All @@ -55,7 +55,7 @@ function str_after( string $subject, string $search ): string {
}

function slugify( string $subject ): string {
return strtolower( trim( preg_replace( '/[^A-Za-z0-9-]+/', '-', $subject ), '-' ) );
return strtolower( trim( (string) preg_replace( '/[^A-Za-z0-9-]+/', '-', $subject ), '-' ) );
}

function title_case( string $subject ): string {
Expand All @@ -66,22 +66,34 @@ function ensure_capitalp( string $text ): string {
return str_replace( 'Wordpress', 'WordPress', $text );
}

/**
* @param string $file
* @param array<string, string> $replacements
*/
function replace_in_file( string $file, array $replacements ): void {
$contents = file_get_contents( $file );

if ( empty( $contents ) ) {
return;
}

file_put_contents(
$file,
str_replace(
array_keys( $replacements ),
array_values( $replacements ),
$contents
$contents,
)
);
}

function remove_readme_paragraphs( string $file ): void {
$contents = file_get_contents( $file );

if ( empty( $contents ) ) {
return;
}

file_put_contents(
$file,
trim( preg_replace( '/<!--delete-->.*<!--\/delete-->/s', '', $contents ) ?: $contents ),
Expand All @@ -92,11 +104,17 @@ function determine_separator( string $path ): string {
return str_replace( '/', DIRECTORY_SEPARATOR, $path );
}

/**
* @return array<int, string>
*/
function list_all_files_for_replacement(): array {
return explode( PHP_EOL, run( 'grep -R -l ./ --exclude LICENSE --exclude configure.php --exclude composer.lock --exclude-dir .git --exclude-dir .github --exclude-dir vendor --exclude-dir bin --exclude-dir webpack --exclude-dir modules --exclude-dir .phpcs' ) );
return explode( PHP_EOL, run( 'grep -R -l ./ --exclude LICENSE --exclude .phpunit.result.cache --exclude-dir node_modules --exclude configure.php --exclude composer.lock --exclude-dir .git --exclude-dir .github --exclude-dir vendor --exclude-dir bin --exclude-dir webpack --exclude-dir modules --exclude-dir .phpcs' ) );
}

function delete_files( string|array $paths ) {
/**
* @param string|array<int, string> $paths
*/
function delete_files( string|array $paths ): void {
if ( ! is_array( $paths ) ) {
$paths = [ $paths ];
}
Expand All @@ -112,8 +130,19 @@ function delete_files( string|array $paths ) {
}
}

$current_dir = getcwd();

echo "\nWelcome friend to alleyinteractive/create-php-package! 😀\nLet's setup your PHP package 🚀\n\n";

if ( ! $current_dir ) {
die( 'Could not determine current directory.' );
}

$folder_name = ensure_capitalp( basename( $current_dir ) );

$package_name = ask( 'Package name?', str_replace( '_', ' ', title_case( $folder_name ) ) );
$package_name_slug = slugify( $package_name );

$git_name = run( 'git config user.name' );
$author_name = ask( 'Author name?', $git_name );

Expand All @@ -128,13 +157,13 @@ function delete_files( string|array $paths ) {
$vendor_name = ask( 'Vendor name (usually the Github Organization)?', $username_guess );
$vendor_slug = slugify( $vendor_name );

$current_dir = getcwd();
$folder_name = ensure_capitalp( basename( $current_dir ) );
$is_wordpress_package = confirm( 'Is this a WordPress package?', false );

$package_name = ask( 'Package name?', str_replace( '_', ' ', title_case( $folder_name ) ) );
$package_name_slug = slugify( $package_name );
$namespace = ask(
'Package namespace?',
$is_wordpress_package ? 'Alley\\WP\\' . title_case( $package_name ) : 'Alley\\' . title_case( $package_name ),
);

$namespace = ask( 'Package namespace?', title_case( $package_name ) );
$class_name = ask( 'Base class name for package?', title_case( $package_name ) );

$description = ask( 'Package description?', "This is my PHP package {$package_name}" );
Expand All @@ -161,7 +190,10 @@ function delete_files( string|array $paths ) {

'A skeleton PHP package geared for WordPress Development' => $description,

'Create_PHP_Package' => $namespace,
// Extra slashes are here for composer.json.
'Alley\\\Create_PHP_Package\\\\' => str_replace( '\\', '\\\\', $namespace ) . '\\\\',
'Alley\Create_PHP_Package' => $namespace,

'Example_Package' => $class_name,
'package_name' => $package_name,

Expand Down Expand Up @@ -199,12 +231,6 @@ function delete_files( string|array $paths ) {
echo "\n\n";
}

if (
file_exists( __DIR__ . '/buddy.yml' ) && confirm( 'Do you need the Buddy CI configuration? (Alley devs only -- if the package is open-source it will not be needed)', false )
) {
delete_files( [ '.buddy', 'buddy.yml' ] );
}

if ( confirm( 'Let this script delete itself?', true ) ) {
delete_files(
[
Expand Down
2 changes: 1 addition & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<properties>
<property name="prefixes" type="array">
<element value="vendor_name" />
<element value="Create_PHP_Package" />
<element value="Alley" />
</property>
</properties>
</rule>
Expand Down
Loading