From 6e62bea3878930536890eb313b633f7946f00a6b Mon Sep 17 00:00:00 2001 From: mogmarsh Date: Tue, 19 Sep 2023 20:37:40 +0000 Subject: [PATCH] Built changes for v0.1.0 --- .deployignore | 22 - .github/dependabot.yml | 25 - .github/workflows/built-branch.yml | 11 - .github/workflows/built-release.yml | 15 - .github/workflows/coding-quality.yml | 16 - .github/workflows/coding-standards.yml | 16 - .github/workflows/dependabot-auto-approve.yml | 11 - .github/workflows/dependabot-auto-merge.yml | 10 - .../workflows/merge-develop-to-scaffold.yml | 34 - .github/workflows/node-tests.yml | 16 - .github/workflows/unit-test.yml | 21 - .github/workflows/update-changelog.yml | 28 - .../workflows/upgrade-wordpress-plugin.yml | 19 - .gitignore | 44 +- .phpcs.xml | 56 -- .phpcs/.gitkeep | 0 Makefile | 4 - configure.php | 767 ------------------ phpunit.xml | 18 - tests/bootstrap.php | 16 - tests/class-test-case.php | 17 - tests/feature/class-example-feature-test.php | 25 - tests/unit/class-example-unit-test.php | 24 - 23 files changed, 20 insertions(+), 1195 deletions(-) delete mode 100644 .deployignore delete mode 100644 .github/dependabot.yml delete mode 100644 .github/workflows/built-branch.yml delete mode 100644 .github/workflows/built-release.yml delete mode 100644 .github/workflows/coding-quality.yml delete mode 100644 .github/workflows/coding-standards.yml delete mode 100644 .github/workflows/dependabot-auto-approve.yml delete mode 100644 .github/workflows/dependabot-auto-merge.yml delete mode 100644 .github/workflows/merge-develop-to-scaffold.yml delete mode 100644 .github/workflows/node-tests.yml delete mode 100644 .github/workflows/unit-test.yml delete mode 100644 .github/workflows/update-changelog.yml delete mode 100644 .github/workflows/upgrade-wordpress-plugin.yml delete mode 100644 .phpcs.xml delete mode 100644 .phpcs/.gitkeep delete mode 100644 Makefile delete mode 100644 configure.php delete mode 100644 phpunit.xml delete mode 100644 tests/bootstrap.php delete mode 100644 tests/class-test-case.php delete mode 100644 tests/feature/class-example-feature-test.php delete mode 100644 tests/unit/class-example-unit-test.php diff --git a/.deployignore b/.deployignore deleted file mode 100644 index 56180bf..0000000 --- a/.deployignore +++ /dev/null @@ -1,22 +0,0 @@ -.DS_Store -Thumbs.db -wp-cli.local.yml -node_modules/ -*.sql -*.tar.gz -*.zip -.phpunit.result.cache -Dockerfile -output.log -.github -tests -bin -composer.lock -.phpcs.xml -phpunit.xml -configure.php -DOCKER_ENV -phpunit.xml -tests -.phpcs -Makefile diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index 115b12e..0000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,25 +0,0 @@ -# Please see the documentation for all configuration options: -# https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates - -version: 2 -updates: - - - package-ecosystem: "github-actions" - directory: "/" - schedule: - interval: "weekly" - - - package-ecosystem: "composer" - directory: "/" - schedule: - interval: "weekly" - - - package-ecosystem: "npm" - directory: "/" - schedule: - interval: "weekly" - day: "saturday" - time: "09:00" - timezone: "America/New_York" - ignore: - - dependency-name: "@wordpress/*" diff --git a/.github/workflows/built-branch.yml b/.github/workflows/built-branch.yml deleted file mode 100644 index cc53440..0000000 --- a/.github/workflows/built-branch.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: Create a -built branch - -on: - push: - branches: - - main - - develop - -jobs: - built-branch: - uses: alleyinteractive/.github/.github/workflows/built-branch.yml@main diff --git a/.github/workflows/built-release.yml b/.github/workflows/built-release.yml deleted file mode 100644 index 46b1ef2..0000000 --- a/.github/workflows/built-release.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Built Release - -on: - push: - branches: - - develop - - main - - production - -jobs: - built-release: - uses: alleyinteractive/.github/.github/workflows/built-release.yml@main - if: ${{ github.repository != 'alleyinteractive/create-wordpress-plugin' }} - with: - node: 16 diff --git a/.github/workflows/coding-quality.yml b/.github/workflows/coding-quality.yml deleted file mode 100644 index dce22c0..0000000 --- a/.github/workflows/coding-quality.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Code Quality - -on: - push: - branches: - - main - pull_request: - # Uncomment and edit the following to run on a schedule. - # schedule: - # - cron: '45 5 * * 0' # Run once per week at 5:45am UTC on Sundays. - -jobs: - code-quality: - uses: alleyinteractive/.github/.github/workflows/php-code-quality.yml@main - with: - php: '8.2' diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml deleted file mode 100644 index 4adcf4e..0000000 --- a/.github/workflows/coding-standards.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Coding Standards - -on: - push: - branches: - - develop - pull_request: - # Uncomment and edit the following to run on a schedule. - # schedule: - # - cron: '0 5 * * 0' # Run once per week at 5am UTC on Sundays. - -jobs: - coding-standards: - uses: alleyinteractive/.github/.github/workflows/php-coding-standards.yml@main - with: - php: '8.2' diff --git a/.github/workflows/dependabot-auto-approve.yml b/.github/workflows/dependabot-auto-approve.yml deleted file mode 100644 index e2119de..0000000 --- a/.github/workflows/dependabot-auto-approve.yml +++ /dev/null @@ -1,11 +0,0 @@ -name: dependabot-auto-approve -on: - pull_request: - -permissions: - pull-requests: write - contents: write - -jobs: - dependabot: - uses: alleyinteractive/.github/.github/workflows/dependabot-auto-approve.yml@main diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml deleted file mode 100644 index aaed13d..0000000 --- a/.github/workflows/dependabot-auto-merge.yml +++ /dev/null @@ -1,10 +0,0 @@ -name: dependabot-auto-merge -on: pull_request_target - -permissions: - pull-requests: write - contents: write - -jobs: - dependabot: - uses: alleyinteractive/.github/.github/workflows/dependabot-auto-merge.yml@main diff --git a/.github/workflows/merge-develop-to-scaffold.yml b/.github/workflows/merge-develop-to-scaffold.yml deleted file mode 100644 index 5465956..0000000 --- a/.github/workflows/merge-develop-to-scaffold.yml +++ /dev/null @@ -1,34 +0,0 @@ -name: Merge Develop to Scaffold Branch - -on: - push: - branches: - - develop - - remove-scaffold - -jobs: - merge-develop-to-scaffold: - name: merge develop to scaffold - runs-on: ubuntu-latest - - steps: - - name: Merge develop to scaffold - shell: bash - env: - DEVELOP_BRANCH: develop - SCAFFOLD_BRANCH: scaffold - - TOKEN: ${{ secrets.GH_TOKEN }} - run: | - git config --global user.name "$GITHUB_ACTOR" - git config --global user.email "$GITHUB_ACTOR@users.noreply.github.com" - - echo "Cloning alleyinteractive/create-wordpress-plugin..." - git clone --recursive --quiet https://$TOKEN@github.com/alleyinteractive/create-wordpress-plugin.git create-wordpress-plugin -b $SCAFFOLD_BRANCH - cd create-wordpress-plugin - - git fetch origin $DEVELOP_BRANCH - git fetch origin $SCAFFOLD_BRANCH - - git merge origin/$DEVELOP_BRANCH --no-edit - git push -u origin $SCAFFOLD_BRANCH diff --git a/.github/workflows/node-tests.yml b/.github/workflows/node-tests.yml deleted file mode 100644 index 668b078..0000000 --- a/.github/workflows/node-tests.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: Node Tests - -on: - push: - branches: - - develop - pull_request: - # Uncomment and edit the following to run on a schedule. - # schedule: - # - cron: '15 5 * * 0' # Run once per week at 5:15am UTC on Sundays. - -jobs: - node-tests: - uses: alleyinteractive/.github/.github/workflows/node-tests.yml@main - with: - run-audit: true diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml deleted file mode 100644 index 213fbb4..0000000 --- a/.github/workflows/unit-test.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Testing Suite - -on: - push: - branches: - - develop - pull_request: - # Uncomment and edit the following to run on a schedule. - # schedule: - # - cron: '30 5 * * 0' # Run once per week at 5:30am UTC on Sundays. - -jobs: - php-tests: - strategy: - matrix: - php: [8.0, 8.1, 8.2] - wordpress: ["latest"] - uses: alleyinteractive/.github/.github/workflows/php-tests.yml@main - with: - php: ${{ matrix.php }} - wordpress: ${{ matrix.wordpress }} diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml deleted file mode 100644 index 94df2c3..0000000 --- a/.github/workflows/update-changelog.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: "Update Changelog" - -on: - release: - types: [released] - -jobs: - update: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - ref: main - - - name: Update Changelog - uses: stefanzweifel/changelog-updater-action@v1 - with: - latest-version: ${{ github.event.release.name }} - release-notes: ${{ github.event.release.body }} - - - name: Commit updated CHANGELOG - uses: stefanzweifel/git-auto-commit-action@v4 - with: - branch: main - commit_message: Update CHANGELOG - file_pattern: CHANGELOG.md diff --git a/.github/workflows/upgrade-wordpress-plugin.yml b/.github/workflows/upgrade-wordpress-plugin.yml deleted file mode 100644 index 9fdf3c6..0000000 --- a/.github/workflows/upgrade-wordpress-plugin.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: Update WordPress Plugin - -on: - schedule: - - cron: '0 6 1 * *' # Run on the first day of every month at 6am UTC. - -permissions: - contents: write - pull-requests: write - -jobs: - update-plugin: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: alleyinteractive/action-update-wordpress-plugin@v1.2.1 - with: - plugin-file: 'plugin.php' - upgrade-npm-dependencies: "true" diff --git a/.gitignore b/.gitignore index a854579..56180bf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,26 +1,22 @@ -# Build files -build -vendor -composer.lock -node_modules - -# Log files -*.log - -# Cache files -.phpcs/*.json -.phpunit.result.cache - -# Ignore temporary OS files .DS_Store -.DS_Store? -.Spotlight-V100 -.Trashes -ehthumbs.db Thumbs.db -.thumbsdb - -# IDE files -*.code-workspace -.idea -.vscode +wp-cli.local.yml +node_modules/ +*.sql +*.tar.gz +*.zip +.phpunit.result.cache +Dockerfile +output.log +.github +tests +bin +composer.lock +.phpcs.xml +phpunit.xml +configure.php +DOCKER_ENV +phpunit.xml +tests +.phpcs +Makefile diff --git a/.phpcs.xml b/.phpcs.xml deleted file mode 100644 index 8eee4b3..0000000 --- a/.phpcs.xml +++ /dev/null @@ -1,56 +0,0 @@ - - - PHP_CodeSniffer standard for create-wordpress-plugin. - - - - - - - - - - - - - - - - - - - - - build/ - vendor/ - - - - - - - - - - - - - - - - - src/assets.php - blocks - build - entries - - - - src/assets.php - - diff --git a/.phpcs/.gitkeep b/.phpcs/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/Makefile b/Makefile deleted file mode 100644 index d9e033f..0000000 --- a/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -setup: - php ./configure.php - -.PHONY: setup diff --git a/configure.php b/configure.php deleted file mode 100644 index f7037d0..0000000 --- a/configure.php +++ /dev/null @@ -1,767 +0,0 @@ -#!/usr/bin/env php -] - * : The author name. - * - * [--author_email=] - * : The author email. - * - * phpcs:disable - */ - -namespace Create_WordPress_Plugin\Configure; - -if ( ! defined( 'STDIN' ) ) { - die( 'Not in CLI mode.' ); -} - -if ( 0 === strpos( strtoupper( PHP_OS ), 'WIN' ) ) { - die( 'Not supported in Windows. 🪟' ); -} - -if ( version_compare( PHP_VERSION, '8.0.0', '<' ) ) { - die( 'PHP 8.0.0 or greater is required.' ); -} - -// Parse the command line arguments from $argv. -$args = []; -$previous_key = null; - -foreach ( $argv as $value ) { - if ( str_starts_with( $value, '--' ) ) { - if ( false !== strpos( $value, '=' ) ) { - [ $arg, $value ] = explode( '=', substr( $value, 2 ), 2 ); - - $args[ $arg ] = trim( $value ); - - $previous_key = null; - } else { - $args[ substr( $value, 2 ) ] = true; - - $previous_key = substr( $value, 2 ); - } - } elseif ( ! empty( $previous_key ) ) { - $args[ $previous_key ] = trim( $value ); - } else { - $previous_key = trim( $value ); - } -} - -$terminal_width = (int) exec( 'tput cols' ); - -function write( string $text ): void { - global $terminal_width; - echo wordwrap( $text, $terminal_width - 1 ) . PHP_EOL; -} - -function ask( string $question, string $default = '', bool $allow_empty = true ): string { - while ( true ) { - write( $question . ( $default ? " [{$default}]" : '' ) . ': ' ); - $answer = readline( '> ' ); - - $value = $answer ?: $default; - - if ( ! $allow_empty && empty( $value ) ) { - echo "This value can't be empty." . PHP_EOL; - continue; - } - - return $value; - } -} - -function confirm( string $question, bool $default = false ): bool { - write( "{$question} (yes/no) [" . ( $default ? 'yes' : 'no' ) . ']: ' ); - - $answer = readline( '> ' ); - - if ( ! $answer ) { - return $default; - } - - return in_array( strtolower( trim( $answer ) ), [ 'y', 'yes', 'true', '1' ], true ); -} - -function run( string $command, string $dir = null ): string { - $command = $dir ? "cd {$dir} && {$command}" : $command; - - return trim( (string) shell_exec( $command ) ); -} - -function str_after( string $subject, string $search ): string { - $pos = strrpos( $subject, $search ); - - if ( $pos === false ) { - return $subject; - } - - return substr( $subject, $pos + strlen( $search ) ); -} - -function slugify( string $subject ): string { - return strtolower( trim( (string) preg_replace( '/[^A-Za-z0-9-]+/', '-', $subject ), '-' ) ); -} - -function title_case( string $subject ): string { - return ensure_capitalp( str_replace( ' ', '_', ucwords( str_replace( [ '-', '_' ], ' ', $subject ) ) ) ); -} - -function ensure_capitalp( string $text ): string { - return str_replace( 'Wordpress', 'WordPress', $text ); -} - -/** - * @param string $file - * @param array $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, - ) - ); -} - -function remove_readme_paragraphs( string $file ): void { - $contents = file_get_contents( $file ); - - if ( empty( $contents ) ) { - return; - } - - file_put_contents( - $file, - trim( (string) preg_replace( '/.*/s', '', $contents ) ?: $contents ), - ); -} - -function remove_composer_require(): void { - global $plugin_file; - - $contents = file_get_contents( $plugin_file ); - - if ( empty( $contents ) ) { - return; - } - - file_put_contents( - $plugin_file, - trim( (string) preg_replace( '/\n\/\* Start Composer Loader \*\/.*\/\* End Composer Loader \*\/\n/s', '', $contents ) ?: $contents ) . PHP_EOL, - ); - - echo "Removed Composer's vendor/autoload.php from {$plugin_file}" . PHP_EOL; -} - -function remove_composer_wrapper_comments(): void { - global $plugin_file; - - $contents = file_get_contents( $plugin_file ); - - if ( empty( $contents ) ) { - return; - } - - file_put_contents( - $plugin_file, - trim( preg_replace( '/\n\/\* (Start|End) Composer Loader \*\/\n/', '', $contents ) ?: $contents ) . PHP_EOL, - ); - - echo "Removed Composer's wrapper comments from {$plugin_file}" . PHP_EOL; -} - -function remove_composer_files(): void { - $file_list = [ - 'composer.json', - 'composer.lock', - 'vendor/', - ]; - - delete_files( $file_list ); - - write( sprintf( 'Removed %s files.', implode( ', ', $file_list ) ) ); -} - -function remove_project_files(): void { - $file_list = [ - '.buddy', - 'buddy.yml', - 'CHANGELOG.md', - '.deployignore', - '.editorconfig', - '.gitignore', - '.gitattributes', - '.github', - 'LICENSE', - ]; - - delete_files( $file_list ); - - write( sprintf( 'Removed %s files.', implode( ', ', $file_list ) ) ); -} - -function rollup_phpcs_to_parent( string $parent_file, string $local_file, string $plugin_name, string $plugin_domain ): void { - $config = ' - - PHP_CodeSniffer standard for ' . $plugin_name . ' - - - - - - - - - - - - - - - - - - -'; - - if ( file_put_contents( $local_file, $config ) ) { - delete_files( '.phpcs' ); - - echo "Updated {$local_file}.\n"; - } -} - -function remove_assets_readme( bool $keep_contents, string $file = 'README.md' ): void { - $contents = file_get_contents( $file ); - - if ( empty( $contents ) ) { - return; - } - - if ( $keep_contents ) { - $contents = str_replace( '', '', $contents ); - $contents = str_replace( '', '', $contents ); - - file_put_contents( $file, $contents ); - } else { - file_put_contents( - $file, - trim( (string) preg_replace( '/.*/s', '', $contents ) ?: $contents ), - ); - } -} - -function remove_assets_require(): void { - global $plugin_file; - - $contents = file_get_contents( $plugin_file ); - - if ( empty( $contents ) ) { - return; - } - - file_put_contents( - $plugin_file, - trim( (string) preg_replace( '/require_once __DIR__ \. \'\/src\/assets.php\';\\n/s', '', $contents ) ?: $contents ) . PHP_EOL, - ); -} - -function remove_assets_buddy( string $file = 'buddy.yml' ): void { - $contents = file_get_contents( $file ); - - if ( empty( $contents ) ) { - return; - } - - $contents = trim( preg_replace( '/(- action: "npm audit".*)variables:/s', 'variables:', $contents ) ?: $contents ); - $contents = str_replace( ' variables:', ' variables:', $contents ); - - file_put_contents( $file, $contents ); -} - -function determine_separator( string $path ): string { - return str_replace( '/', DIRECTORY_SEPARATOR, $path ); -} - -/** - * @return array - */ -function list_all_files_for_replacement(): array { - return explode( PHP_EOL, run( 'grep -R -l . --exclude LICENSE --exclude configure.php --exclude .phpunit.result.cache --exclude-dir .phpcs --exclude composer.lock --exclude-dir .git --exclude-dir .github --exclude-dir vendor --exclude-dir node_modules --exclude-dir webpack --exclude-dir modules --exclude-dir .phpcs' ) ); -} - -/** - * @param string|array $paths - */ -function delete_files( string|array $paths ): void { - if ( ! is_array( $paths ) ) { - $paths = [ $paths ]; - } - - foreach ( $paths as $path ) { - $path = determine_separator( $path ); - - if ( is_dir( $path ) ) { - run( "rm -rf {$path}" ); - } elseif ( file_exists( $path ) ) { - @unlink( $path ); - } - } -} - -function remove_phpstan(): void { - delete_files( 'phpstan.neon' ); - - // Manually patch the Composer.json file. - if ( file_exists( 'composer.json' ) ) { - $composer_json = (array) json_decode( (string) file_get_contents( 'composer.json' ), true ); - - if ( isset( $composer_json['scripts']['phpstan'] ) ) { // @phpstan-ignore-line - unset( $composer_json['scripts']['phpstan'] ); // @phpstan-ignore-line - - $composer_json['scripts']['test'] = [ // @phpstan-ignore-line - '@phpcs', - '@phpunit', - ]; - - file_put_contents( 'composer.json', json_encode( $composer_json, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) ); - } - } -} - -function contributing_message( string $message ): void { - write( "\n{$message}\n" ); - echo "\t\e]8;;https://github.com/alleyinteractive/.github/blob/main/CONTRIBUTING.md#best-practices\e\\CONTRIBUTING.md\e]8;;\e\\\n\n"; -} - -echo "\nWelcome friend to alleyinteractive/create-wordpress-plugin! 😀\nLet's setup your WordPress Plugin 🚀\n\n"; - -// Always delete the 'merge-develop-to-scaffold.yml' file (this is never used in a scaffolded plugins). -delete_files( '.github/workflows/merge-develop-to-scaffold.yml' ); - -$current_dir = getcwd(); - -if ( ! $current_dir ) { - echo "Could not determine current directory.\n"; - exit( 1 ); -} - -$folder_name = ensure_capitalp( basename( $current_dir ) ); - -$author_email = ask( - question: 'Author email?', - default: (string) ( $args['author_email'] ?? run( 'git config user.email' ) ), - allow_empty: false, -); - -$username_guess = explode( ':', run( 'git config remote.origin.url' ) )[1] ?? ''; -$username_guess = dirname( $username_guess ); -$username_guess = basename( $username_guess ); -$author_username = ask( - question: 'Author username?', - default: $username_guess, - allow_empty: false, -); - -$author_name = ask( - question: 'Author name?', - default: (string) ( $args['author_name'] ?? run( 'git config user.name' ) ), - allow_empty: false, -); - -$vendor_name = ask( - question: 'Vendor name (usually the Github Organization)?', - default: $username_guess, - allow_empty: false, -); - -$vendor_slug = slugify( $vendor_name ); -$is_alley_plugin = 'alleyinteractive' === $vendor_slug; - -$plugin_name = ask( - question: 'Plugin name?', - default: (string) ( $args['plugin_name'] ?? str_replace( '_', ' ', title_case( $folder_name ) ) ), - allow_empty: false, -); - -while ( true ) { - $plugin_name_slug = slugify( ask( - question: 'Plugin slug?', - default: slugify( $plugin_name ), - allow_empty: false, - ) ); - - // Suggest a different plugin name if this is an Alley plugin. - if ( $is_alley_plugin && 0 !== strpos( $plugin_name_slug, 'wp-' ) ) { - $example_slug = "wp-{$plugin_name_slug}"; - - contributing_message( "Alley WordPress plugin slugs should be prefixed with \"wp-\". For example, {$example_slug} would be a great slug. If this plugin isn't meant to be published anywhere, this is fine to ignore. See our CONTRIBUTING.md for more details." ); - - if ( ! confirm( 'Do you wish to continue anyway?', false ) ) { - continue; - } - } - - break; -} - -while ( true ) { - $namespace = ask( - question: 'Plugin namespace?', - default: $is_alley_plugin ? 'Alley\\WP\\' . title_case( $plugin_name ) : title_case( $plugin_name ), - allow_empty: false, - ); - - // Check if the namespace is valid. - if ( ! preg_match( '/^[a-zA-Z0-9_\\\\]+$/', $namespace ) ) { - echo "Invalid namespace, please try again.\n"; - continue; - } - - // Offer to fix the namespace if this is an Alley plugin. - if ( $is_alley_plugin && 0 !== strpos( $namespace, 'Alley\\WP\\' ) ) { - $example_namespace = 'Alley\\WP\\' . title_case( $plugin_name ); - contributing_message( "Alley WordPress plugins should be prefixed with \"Alley\\WP\\\". A namespace such as \"{$example_namespace}\" would work well. If this plugin isn't meant to be published anywhere, this is fine to ignore. See our CONTRIBUTING.md for more details." ); - - if ( confirm( 'Do you wish to continue anyway?', false ) ) { - break; - } - } - - break; -} - -$class_name = ask( 'Base class name for plugin?', title_case( $plugin_name ) ); -$description = ask( 'Plugin description?', "This is my plugin {$plugin_name}" ); - -while ( true ) { - $plugin_file = ask( 'Main plugin file?', "{$plugin_name_slug}.php" ); - - // Validate that plugin file is a valid file name. - if ( ! preg_match( '/^[a-zA-Z0-9-_\.]+\.php$/', $plugin_file ) ) { - echo "Invalid plugin file name. Please try again.\n"; - continue; - } - - // Validate that plugin file does not already exist. - if ( file_exists( $plugin_file ) ) { - echo "Plugin file already exists. Please try again.\n"; - continue; - } - - break; -} - -write( '------' ); -write( "Plugin : {$plugin_name} <{$plugin_name_slug}>" ); -write( "Author : {$author_name} ({$author_email})" ); -write( "Vendor : {$vendor_name} ({$vendor_slug})" ); -write( "Description : {$description}" ); -write( "Namespace : {$namespace}" ); -write( "Main File : {$plugin_file}" ); -write( "Main Class : {$class_name}" ); -write( '------' ); - -write( 'This script will replace the above values in all relevant files in the project directory.' ); - -if ( ! confirm( 'Modify files?', true ) ) { - exit( 1 ); -} - -$search_and_replace = [ - 'author_name' => $author_name, - 'author_username' => $author_username, - 'email@domain.com' => $author_email, - - 'A skeleton WordPress plugin' => $description, - - // Escape the namespace used in composer.json. - '"Create_WordPress_Plugin\\"' => (string) json_encode( $namespace ), - '"Create_WordPress_Plugin\\Tests\\"' => (string) json_encode( $namespace . '\\Tests' ), - - 'Create_WordPress_Plugin' => $namespace, - 'Example_Plugin' => $class_name, - - 'create_wordpress_plugin' => str_replace( '-', '_', $plugin_name_slug ), - 'plugin_name' => $plugin_name, - - 'create-wordpress-plugin' => $plugin_name_slug, - 'Create WordPress Plugin' => $plugin_name, - - 'CREATE_WORDPRESS_PLUGIN' => strtoupper( str_replace( '-', '_', $plugin_name_slug ) ), - 'Skeleton' => $class_name, - 'vendor_name' => $vendor_name, - 'alleyinteractive' => $vendor_slug, - 'plugin.php' => $plugin_file, -]; - -// Patch the Composer.json namespace first before search and replace. -run( - 'composer config extra.wordpress-autoloader.autoload --json \'' . json_encode( [ - $namespace => 'src', - ] ) . '\'', -); - -run( - 'composer config extra.wordpress-autoloader.autoload-dev --json \'' . json_encode( [ - $namespace . '\\Tests' => 'tests', - ] ) . '\'', -); - -foreach ( list_all_files_for_replacement() as $path ) { - echo "Updating $path...\n"; - - replace_in_file( $path, $search_and_replace ); - - if ( str_contains( $path, determine_separator( 'src/class-example-plugin.php' ) ) ) { - rename( $path, determine_separator( './src/class-' . str_replace( '_', '-', strtolower( $class_name ) ) . '.php' ) ); - } - - if ( str_contains( $path, 'README.md' ) ) { - remove_readme_paragraphs( $path ); - } -} - -// Attempt to rename the main plugin file. -if ( 'plugin.php' !== $plugin_file ) { - rename( 'plugin.php', $plugin_file ); - - replace_in_file( './.github/workflows/upgrade-wordpress-plugin.yml', $search_and_replace ); - - echo "Renamed plugin.php to {$plugin_file}\n"; -} - -echo "Done!\n\n"; - -$needs_built_assets = false; -$uses_composer = false; - -if ( confirm( 'Will this plugin be compiling front-end assets (Node)?', true ) ) { - $needs_built_assets = true; - - if ( confirm( 'Do you want to run `npm install` and `npm run build`?', true ) ) { - echo run( 'npm install && npm run build' ); - echo "\n\n\n"; - } - - remove_assets_readme( true ); -} elseif ( confirm( 'Do you want to delete the front-end files? (Such as package.json, webpack.config.js, etc.)', true ) ) { - echo "Deleting...\n"; - - delete_files( - [ - '.github/workflows/node-tests.yml', - '.eslintignore', - '.eslintrc.json', - '.nvmrc', - '.stylelintrc.json', - 'babel.config.js', - 'jest.config.js', - 'jsconfig.json', - 'package.json', - 'package-lock.json', - 'tsconfig.json', - 'webpack.config.js', - 'webpack/', - 'entries/', - 'services/', - 'slotfills/', - 'blocks/', - 'build/', - 'bin/', - 'node_modules/', - 'scaffold', - 'src/assets.php', - ] - ); - - remove_assets_readme( false ); - remove_assets_require(); - remove_assets_buddy(); -} - -if ( confirm( 'Will this plugin be using Composer? (WordPress Composer Autoloader already included! phpcs and phpunit also rely on Composer being installed for testing.)', true ) ) { - $uses_composer = true; - $needs_built_assets = true; - - remove_composer_wrapper_comments(); - - if ( confirm( 'Do you want to run `composer install`?', true ) ) { - if ( file_exists( __DIR__ . '/composer.lock' ) ) { - echo run( 'composer update' ); - } else { - echo run( 'composer install' ); - } - - echo "\n\n"; - } -} elseif ( confirm( 'Do you want to remove the vendor/autoload.php dependency from your main plugin file and the composer.json file?' ) ) { - remove_composer_require(); - - // Prompt the user to delete the composer.json file. Plugins often still - // keep this around for development and Packagist. - if ( confirm( 'Do you want to delete the composer.json and composer.lock files? (This will prevent you from using PHPCS/PHPStan/Composer entirely).', false ) ) { - remove_composer_files(); - } -} - -if ( file_exists( 'composer.json') && ! confirm(' Using PHPStan? (PHPStan is a great static analyzer to help find bugs in your code.)', true) ) { - remove_phpstan(); -} - -$standalone = true; - -// Check if the plugin will be use standalone (as a single repository) or as a -// part of larger project (such as a wp-content-rooted project). Assumes that -// the parent project is located at /wp-content/ and this plugin is located at -// /wp-content/plugins/:plugin/. -if ( - file_exists( '../../.git/index' ) - && ! confirm( - 'Will this be a standalone plugin, not located within a larger project? For example, a standalone plugin will have a separate repository and will be distributed independently.', - false, - ) -) { - $standalone = false; - - $needs_built_assets = false; - - if ( confirm( 'Do you want to remove project-based files, such as GitHub actions? (If this is a standalone plugin, these are probably in the root directory.)', true ) ) { - remove_project_files(); - } - - // Offer to roll up this plugin's dependencies to the parent project's composer. - if ( $uses_composer && file_exists( '../../composer.json' ) ) { - $parent_composer = (string) realpath( '../../composer.json' ); - $parent_folder = dirname( $parent_composer ); - - if ( confirm( "Do you want to rollup the plugin's Composer dependencies to the parent project's composer.json file ({$parent_composer})? This will copy this plugin's dependencies to the parent project and delete the local composer.json file.", true ) ) { - $composer = (array) json_decode( (string) file_get_contents( $parent_composer ), true ); - $plugin_composer = (array) json_decode( (string) file_get_contents( 'composer.json' ), true ); - - $original = $composer; - - $composer['require'] = array_merge( - (array) ( $composer['require'] ?? [] ), - (array) ( $plugin_composer['require'] ?? [] ), - ); - - $composer['require-dev'] = array_merge( - (array) ( $composer['require-dev'] ?? [] ), - (array) ( $plugin_composer['require-dev'] ?? [] ), - ); - - $composer['config']['allow-plugins']['alleyinteractive/composer-wordpress-autoloader'] = true; - - ksort( $composer['require'] ); - ksort( $composer['require-dev'] ); - ksort( $composer['config']['allow-plugins'] ); - - if ( $composer !== $original ) { - file_put_contents( $parent_composer, json_encode( $composer, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) ); - echo "Updated {$parent_composer} with the plugin's composer dependencies.\n"; - - remove_composer_require(); - remove_composer_files(); - - echo "\n\n"; - - if ( confirm( "Do you want to run `composer update` in {$parent_folder}?", true ) ) { - echo run( 'composer update', $parent_folder ); - echo "\n\n"; - } - } - - $parent_files = [ - $parent_folder . '/phpcs.xml', - $parent_folder . '/phpcs.xml.dist', - $parent_folder . '/.phpcs.xml', - ]; - - if ( file_exists( __DIR__ . '/.phpcs.xml' ) ) { - foreach ( $parent_files as $parent_file ) { - if ( ! file_exists( $parent_file ) ) { - continue; - } - - if ( confirm( "Do you want to roll up the phpcs configuration to the parent? (This will change the plugin's phpcs configuration to inherit the parent configuration from {$parent_file}.)" ) ) { - rollup_phpcs_to_parent( - parent_file: '../../' . basename( $parent_file ), - local_file: __DIR__ . '/.phpcs.xml', - plugin_name: $plugin_name, - plugin_domain: $plugin_name_slug, - ); - - break; - } - } - } - } - } - - if ( confirm( 'Do you want to remove the git repository for the plugin?', true ) ) { - delete_files( '.git' ); - } -} - -// Offer to delete the built asset workflows if built assets aren't needed. -if ( ! $needs_built_assets && file_exists( '.github/workflows/built-release.yml' ) && confirm( 'Delete the Github actions for built assets?', true ) ) { - delete_files( - [ - '.github/workflows/built-branch.yml', - '.github/workflows/built-release.yml', - ] - ); -} - -if ( - $standalone && file_exists( __DIR__ . '/buddy.yml' ) && ! confirm( 'Do you need the Buddy CI configuration? (Alley devs only -- if the plugin is open-source it will not be needed)', false ) -) { - delete_files( [ '.buddy', 'buddy.yml' ] ); -} - -if ( confirm( 'Let this script delete itself?', true ) ) { - delete_files( - [ - 'Makefile', - __FILE__, - ] - ); -} - -echo "\n\nWe're done! 🎉\n\n"; - -// Offer some information about built releases if the workflow still exists. -if ( file_exists( '.github/workflows/built-release.yml' ) ) { - echo << - - - tests/feature - - - tests/unit - - - diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index 75e8e4a..0000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,16 +0,0 @@ -maybe_rsync_plugin() - ->with_sqlite() - // Load the main file of the plugin. - ->loaded( fn () => require_once __DIR__ . '/../plugin.php' ) - ->install(); diff --git a/tests/class-test-case.php b/tests/class-test-case.php deleted file mode 100644 index 21860cd..0000000 --- a/tests/class-test-case.php +++ /dev/null @@ -1,17 +0,0 @@ -assertTrue( true ); - $this->assertNotEmpty( home_url() ); - } -} diff --git a/tests/unit/class-example-unit-test.php b/tests/unit/class-example-unit-test.php deleted file mode 100644 index 133db08..0000000 --- a/tests/unit/class-example-unit-test.php +++ /dev/null @@ -1,24 +0,0 @@ -assertTrue( true ); - } -}