diff --git a/.github/ISSUE_TEMPLATE /config.yml b/.github/ISSUE_TEMPLATE /config.yml index 992233b..b9c3555 100644 --- a/.github/ISSUE_TEMPLATE /config.yml +++ b/.github/ISSUE_TEMPLATE /config.yml @@ -1,8 +1,8 @@ blank_issues_enabled: false contact_links: - name: Ask a question - url: https://github.com/red-explosion/:package_slug/discussions/new?category=q-a + url: https://github.com/red-explosion/package_slug/discussions/new?category=q-a about: Ask the community for help - name: Request a feature - url: https://github.com/red-explosion/:package_slug/discussions/new?category=ideas + url: https://github.com/red-explosion/package_slug/discussions/new?category=ideas about: Share ideas for new features diff --git a/.github/workflows/init.yml b/.github/workflows/init.yml new file mode 100644 index 0000000..802c8df --- /dev/null +++ b/.github/workflows/init.yml @@ -0,0 +1,42 @@ +name: init package + +on: + push: + branches: [ main ] + +jobs: + init: + name: Init Package + runs-on: ubuntu-latest + + # Only run this job when a repository has been created from the template, and it's an initial push (first commit) + if: github.repository != 'red-explosion/laravel-package-skeleton' && github.run_number == 1 && github.event.base_ref == null + + steps: + - name: Checkout the code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + coverage: none + + - name: Init + run: php init.php "$PACKAGE_NAME" "$PACKAGE_DESCRIPTION" "$AUTHOR_NAME" "AUTHOR_USERNAME" "AUTHOR_EMAIL" + env: + PACKAGE_NAME: ${{ github.event.repository.name }} + PACKAGE_DESCRIPTION: ${{ github.event.repository.description }} + AUTHOR_NAME: ${{ github.event.commits[0].author.name }} + AUTHOR_USERNAME: ${{ github.actor }} + AUTHOR_EMAIL: ${{ github.event.pusher.email }} + + - name: Delete init files + run: | + rm .github/workflows/init.yml + rm init.yml + + - name: Apply changes + uses: stefanzweifel/git-auto-commit-action@v4 + with: + commit_message: "chore: initialise project" diff --git a/README.md b/README.md index c2824c8..6ead8da 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,14 @@ -# :package_name +# package_name -[![Latest Version on Packagist](https://img.shields.io/packagist/v/red-explosion/:package_slug.svg?style=flat-square)](https://packagist.org/packages/red-explosion/:package_slug) -[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/red-explosion/:package_slug/tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/red-explosion/:package_slug/actions/workflows/tests.yaml?query=branch:main) -[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/red-explosion/:package_slug/coding-standards.yml?label=code%20style&style=flat-square)](https://github.com/red-explosion/:package_slug/actions/workflows/coding-standards.yml?query=branch:main) -[![Total Downloads](https://img.shields.io/packagist/dt/red-explosion/:package_slug.svg?style=flat-square)](https://packagist.org/packages/red-explosion/:package_slug) +[![Latest Version on Packagist](https://img.shields.io/packagist/v/red-explosion/package_slug.svg?style=flat-square)](https://packagist.org/packages/red-explosion/package_slug) +[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/red-explosion/package_slug/tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/red-explosion/package_slug/actions/workflows/tests.yaml?query=branch:main) +[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/red-explosion/package_slug/coding-standards.yml?label=code%20style&style=flat-square)](https://github.com/red-explosion/package_slug/actions/workflows/coding-standards.yml?query=branch:main) +[![Total Downloads](https://img.shields.io/packagist/dt/red-explosion/package_slug.svg?style=flat-square)](https://packagist.org/packages/red-explosion/package_slug) --- This repo can be used to scaffold a Red Explosion Laravel package. Follow these steps to get started: 1. Press the "Use this template" button at the top of this repo to create a new repo with the contents of this skeleton. -2. Run "php ./configure.php" to run a script that will replace all placeholders throughout all the files. --- This is where your description should go. Limit it to a paragraph or two. Consider adding a small example. @@ -19,33 +18,33 @@ This is where your description should go. Limit it to a paragraph or two. Consid You can install the package via composer: ```bash -composer require red-explosion/:package_slug +composer require red-explosion/package_slug ``` You can publish and run the migrations with: ```bash -php artisan vendor:publish --tag=":package_slug-migrations" +php artisan vendor:publish --tag="skeleton-migrations" php artisan migrate ``` You can publish the config file with: ```bash -php artisan vendor:publish --tag=":package_slug-config" +php artisan vendor:publish --tag="skeleton-config" ``` Optionally, you can publish the views using ```bash -php artisan vendor:publish --tag=":package_slug-views" +php artisan vendor:publish --tag="skeleton-views" ``` ## Usage ```php $variable = new RedExplosion\Skeleton(); -echo $variable->echoPhrase('Hello, RedExplosion!'); +echo $variable->echoPhrase('Hello, Red Explosion!'); ``` ## Testing diff --git a/composer.json b/composer.json index 7016b3f..02289ac 100644 --- a/composer.json +++ b/composer.json @@ -1,18 +1,18 @@ { - "name": "red-explosion/:package_slug", - "description": ":package_description", + "name": "red-explosion/package_slug", + "description": "package_description", "license": "MIT", - "homepage": "https://github.com/red-explosion/:package_slug", + "homepage": "https://github.com/red-explosion/package_slug", "type": "library", "keywords": [ "red-explosion", "laravel", - ":package_slug" + "package_slug" ], "authors": [ { - "name": ":author_name", - "email": "author@domain.com" + "name": "author_name", + "email": "author@email.com" } ], "require": { @@ -41,7 +41,7 @@ "scripts": { "lint": "./vendor/bin/pint --config vendor/red-explosion/pint-config/pint.json", "test:lint": "./vendor/bin/pint --config vendor/red-explosion/pint-config/pint.json --test", - "test:types": "phpstan analyse --ansi", + "test:types": "./vendor/bin/phpstan analyse --ansi", "test:unit": "./vendor/bin/pest --compact --colors=always", "test": [ "@test:lint", diff --git a/config/skeleton.php b/config/skeleton.php index 45f0f2d..0dae23d 100644 --- a/config/skeleton.php +++ b/config/skeleton.php @@ -2,5 +2,4 @@ declare(strict_types=1); -// Config for :package_slug return []; diff --git a/configure.php b/configure.php deleted file mode 100644 index 0ac33c9..0000000 --- a/configure.php +++ /dev/null @@ -1,154 +0,0 @@ -#!/usr/bin/env php -.*/s', '', $contents) ?: $contents - ); -} - -function determineSeparator(string $path): string -{ - return str_replace('/', DIRECTORY_SEPARATOR, $path); -} - -function replaceForWindows(): array -{ - return preg_split('/\\r\\n|\\r|\\n/', run('dir /S /B * | findstr /v /i .git\ | findstr /v /i vendor | findstr /v /i '.basename(__FILE__).' | findstr /r /i /M /F:/ ":author_name :author_username author@domain.com :package_name :package_slug Skeleton skeleton :package_description"')); -} - -function replaceForAllOtherOSes(): array -{ - return explode(PHP_EOL, run('grep -E -r -l -i ":author_name|:author_username|author@domain.com|:package_name|:package_slug|Skeleton|skeleton|:package_description" --exclude-dir=vendor ./* ./.github/* | grep -v '.basename(__FILE__))); -} - -$gitName = run('git config user.name'); -$authorName = ask('Author name', $gitName); - -$gitEmail = run('git config user.email'); -$authorEmail = ask('Author email', $gitEmail); - -$usernameGuess = explode(':', run('git config remote.origin.url'))[1]; -$usernameGuess = dirname($usernameGuess); -$usernameGuess = basename($usernameGuess); -$authorUsername = ask('Author username', $usernameGuess); - -$currentDirectory = getcwd(); -$folderName = basename($currentDirectory); - -$packageName = ask('Package name', $folderName); -$packageSlug = slugify($packageName); -$packageSlugWithoutPrefix = remove_prefix('laravel-', $packageSlug); - -$className = title_case($packageName); -$className = ask('Class name', $className); -$description = ask('Package description', "This is my package {$packageSlug}"); - -writeln('------'); -writeln("Author : {$authorName} ({$authorUsername}, {$authorEmail})"); -writeln("Package : {$packageSlug} <{$description}>"); -writeln("Class name : {$className}"); -writeln('------'); - -writeln('This script will replace the above values in all relevant files in the project directory.'); - -if (! confirm('Modify files?', true)) { - exit(1); -} - -$files = (str_starts_with(mb_strtoupper(PHP_OS), 'WIN') ? replaceForWindows() : replaceForAllOtherOSes()); - -foreach ($files as $file) { - replace_in_file($file, [ - ':author_name' => $authorName, - ':author_username' => $authorUsername, - 'author@domain.com' => $authorEmail, - ':package_name' => $packageName, - ':package_slug' => $packageSlug, - 'Skeleton' => $className, - 'skeleton' => $packageSlug, - ':package_description' => $description, - ]); - - match (true) { - str_contains($file, determineSeparator('src/Skeleton.php')) => rename($file, determineSeparator('./src/'.$className.'.php')), - str_contains($file, determineSeparator('src/SkeletonServiceProvider.php')) => rename($file, determineSeparator('./src/'.$className.'ServiceProvider.php')), - str_contains($file, determineSeparator('config/skeleton.php')) => rename($file, determineSeparator('./config/'.$packageSlugWithoutPrefix.'.php')), - str_contains($file, 'README.md') => remove_readme_paragraphs($file), - default => [], - }; -} - - -confirm('Execute `composer install` and run tests?') && run('composer install && composer test'); - -confirm('Let this script delete itself?', true) && unlink(__FILE__); diff --git a/init.php b/init.php new file mode 100644 index 0000000..ec70011 --- /dev/null +++ b/init.php @@ -0,0 +1,90 @@ +#!/usr/bin/env php +.*/s', replacement: '', subject: $contents) ?: $contents + ); +} + +$packageSlug = $argv[1]; +$packageSlugWithoutPrefix = removePrefix(prefix: 'laravel-', content: $packageSlug); +$packageName = ucwords(string: str_replace(search: '-', replace: ' ', subject: $packageSlug)); +$packageDescription = $argv[2]; + +$authorName = $argv[3]; +$authorUsername = $argv[4]; +$authorEmail = $argv[5]; + +$className = removePrefix(prefix: 'Laravel', content: titleCase(subject: $packageName)); + +foreach (files() as $file) { + replaceInFile($file, [ + 'package_name' => $packageName, + 'package_slug' => $packageSlug, + 'package_description' => $packageDescription, + 'author_name' => $authorName, + 'author_username' => $authorUsername, + 'author@email.com' => $authorEmail, + 'skeleton' => $packageSlugWithoutPrefix, + 'Skeleton' => $className, + ]); + + match (true) { + str_contains($file, determineSeparator(path: 'src/Skeleton.php')) => rename($file, determineSeparator(path: './src/' . $className . '.php')), + str_contains($file, determineSeparator(path: 'src/SkeletonServiceProvider.php')) => rename($file, determineSeparator(path: './src/' . $className . 'ServiceProvider.php')), + str_contains($file, determineSeparator(path: 'config/skeleton.php')) => rename($file, determineSeparator(path: './config/' . $packageSlugWithoutPrefix . '.php')), + str_contains($file, 'README.md') => removeReadmeParagraphs($file), + default => [], + }; +}