diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..3ad908b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +indent_style = space +indent_size = 4 +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[{*.(yml, json)}] +indent_size = 2 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..fe91b31 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,16 @@ +* text=auto + +/.github export-ignore +/art export-ignore +/docs export-ignore +/tests export-ignore +/scripts export-ignore +.editorconfig export-ignore +.gitattributes export-ignore +.gitignore export-ignore +phpstan.neon.dist export-ignore +phpunit.xml.dist export-ignore +CONTRIBUTING.md export-ignore +CHANGELOG.md export-ignore +CONTRIBUTING.md export-ignore +README.md export-ignore diff --git a/.github/ISSUE_TEMPLATE /bug.yml b/.github/ISSUE_TEMPLATE /bug.yml new file mode 100644 index 0000000..5d42a20 --- /dev/null +++ b/.github/ISSUE_TEMPLATE /bug.yml @@ -0,0 +1,66 @@ +name: Bug Report +description: Report an Issue or Bug with the Package +title: "[Bug]: " +labels: ["bug"] +body: + - type: markdown + attributes: + value: | + We're sorry to hear you have a problem. Can you help us solve it by providing the following details. + - type: textarea + id: what-happened + attributes: + label: What happened? + description: What did you expect to happen? + placeholder: I cannot currently do X thing because when I do, it breaks X thing. + validations: + required: true + - type: textarea + id: how-to-reproduce + attributes: + label: How to reproduce the bug + description: How did this occur, please add any config values used and provide a set of reliable steps if possible. + placeholder: When I do X I see Y. + validations: + required: true + - type: input + id: package-version + attributes: + label: Package Version + description: What version of our Package are you running? Please be as specific as possible + placeholder: 1.0.0 + validations: + required: true + - type: input + id: php-version + attributes: + label: PHP Version + description: What version of PHP are you running? Please be as specific as possible + placeholder: 8.2.0 + validations: + required: true + - type: input + id: laravel-version + attributes: + label: Laravel Version + description: What version of Laravel are you running? Please be as specific as possible + placeholder: 10.0.0 + validations: + required: true + - type: dropdown + id: operating-systems + attributes: + label: Which operating systems does with happen with? + description: You may select more than one. + multiple: true + options: + - macOS + - Windows + - Linux + - type: textarea + id: notes + attributes: + label: Notes + description: Use this field to provide any other notes that you feel might be relevant to the issue. + validations: + required: false diff --git a/.github/ISSUE_TEMPLATE /config.yml b/.github/ISSUE_TEMPLATE /config.yml new file mode 100644 index 0000000..b9c3555 --- /dev/null +++ b/.github/ISSUE_TEMPLATE /config.yml @@ -0,0 +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 + about: Ask the community for help + - name: Request a feature + url: https://github.com/red-explosion/package_slug/discussions/new?category=ideas + about: Share ideas for new features diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..8dfe314 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: "/" + schedule: + interval: "weekly" + commit-message: + prefix: fix + prefix-development: chore + include: scope diff --git a/.github/semantic.yml b/.github/semantic.yml new file mode 100644 index 0000000..f6d43e2 --- /dev/null +++ b/.github/semantic.yml @@ -0,0 +1,5 @@ +# Always validate the PR title AND all the commits +titleAndCommits: true +# Allows use of Merge commits (e.g. on GitHub: "Merge branch 'main' into feature/ride-unicorns") +# this is only relevant when using commitsOnly: true (or titleAndCommits: true) +allowMergeCommits: true diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml new file mode 100644 index 0000000..1f2ccdb --- /dev/null +++ b/.github/workflows/coding-standards.yml @@ -0,0 +1,42 @@ +name: coding standards + +on: + push: + branches: [ main ] + pull_request: + +permissions: + contents: read + +jobs: + lint: + name: Coding Standards + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[ci skip]')" + + steps: + - name: Checkout the code + uses: actions/checkout@v4 + + - name: Get composer cache directory path + id: composercache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache composer + uses: actions/cache@v3 + with: + path: ${{ steps.composercache.outputs.dir }} + key: dependencies-composer-${{ hashFiles('composer.json') }} + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + tools: composer:v2 + coverage: none + + - name: Install dependencies + run: composer update --prefer-dist --no-interaction --no-progress + + - name: Run Laravel Pint + run: ./vendor/bin/pint --config vendor/red-explosion/pint-config/pint.json --test diff --git a/.github/workflows/init.yml b/.github/workflows/init.yml new file mode 100644 index 0000000..917ca06 --- /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-template' && 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.php + + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: "chore: initialise project" diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 0000000..318162e --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,42 @@ +name: static analysis + +on: + push: + branches: [ main ] + pull_request: + +permissions: + contents: read + +jobs: + phpstan: + name: Static Analysis + runs-on: ubuntu-latest + if: "!contains(github.event.head_commit.message, '[ci skip]')" + + steps: + - name: Checkout the code + uses: actions/checkout@v4 + + - name: Get composer cache directory path + id: composercache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache composer + uses: actions/cache@v3 + with: + path: ${{ steps.composercache.outputs.dir }} + key: dependencies-composer-${{ hashFiles('composer.json') }} + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: 8.2 + tools: composer:v2 + coverage: none + + - name: Install dependencies + run: composer update --prefer-dist --no-interaction --no-progress + + - name: Execute type checking + run: ./vendor/bin/phpstan analyse --error-format=github diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..4f7ab11 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,50 @@ +name: tests + +on: + push: + branches: [ main ] + pull_request: + +permissions: + contents: write + +jobs: + tests: + runs-on: ubuntu-latest + + strategy: + fail-fast: true + matrix: + php: [ 8.2, 8.3 ] + laravel: [ 10.* ] + + name: PHP ${{ matrix.php }} - Laravel ${{ matrix.laravel }} + + steps: + - name: Checkout the code + uses: actions/checkout@v4 + + - name: Get composer cache directory path + id: composercache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache composer + uses: actions/cache@v3 + with: + path: ${{ steps.composercache.outputs.dir }} + key: dependencies-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }} + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip + coverage: none + + - name: Install dependencies + run: | + composer require "illuminate/contracts:${{ matrix.laravel }}" --no-interaction --no-progress --no-update + composer update --prefer-dist --no-interaction --no-progress + + - name: Execute the tests + run: ./vendor/bin/pest --compact diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml new file mode 100644 index 0000000..e47470b --- /dev/null +++ b/.github/workflows/update-changelog.yml @@ -0,0 +1,31 @@ +name: update changelog + +on: + release: + types: [released] + +permissions: + contents: write + +jobs: + changelog: + 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@v5 + with: + branch: main + commit_message: Update CHANGELOG + file_pattern: CHANGELOG.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ce9caa0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +# exclude OS files +.DS_Store + +# exclude IDE files +/.fleet +/.idea +/.vscode + +# exclude composer files +/vendor + +# exclude local testing files +.phpunit.cache +phpunit.xml + +# exclude because with package development it doesnt matter and reduces unnecessary merge conflicts +composer.lock + +# exclude local static analysis files +phpstan.neon diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..1d013ff --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,6 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), +and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..6f1fa0a --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,60 @@ +# Contributing + +Contributions are **welcome** and will be fully **credited**. + +Please read and understand the contribution guide before creating an issue or pull request. + +## Etiquette + +This project is open source, and as such, the maintainers give their free time to build and maintain the source code +held within. They make the code freely available in the hope that it will be of use to other developers. It would be +extremely unfair for them to suffer abuse or anger for their hard work. + +Please be considerate towards maintainers when raising issues or presenting pull requests. Let's show the world that +developers are civilized and selfless people. + +It's the duty of the maintainer to ensure that all submissions to the project are of sufficient quality to benefit the +project. Many developers have different skillsets, strengths, and weaknesses. Respect the maintainer's decision, and do +not be upset or abusive if your submission is not used. + +## Viability + +When requesting or submitting new features, first consider whether it might be useful to others. Open source projects +are used by many developers, who may have entirely different needs to your own. Think about whether or not your feature +is likely to be used by other users of the project. + +## Procedure + +Before filing an issue: + +- Attempt to replicate the problem, to ensure that it wasn't a coincidental incident. +- Check to make sure your feature suggestion isn't already present within the project. +- Check the pull requests tab to ensure that the bug doesn't have a fix in progress. +- Check the pull requests tab to ensure that the feature isn't already in progress. + +Before submitting a pull request: + +- Check the codebase to ensure that your feature doesn't already exist. +- Check the pull requests to ensure that another person hasn't already submitted the feature or fix. + +## Requirements + +If the project maintainer has any additional requirements, you will find them listed here. + +- **[PER Coding Standard](https://github.com/php-fig/per-coding-style/blob/2.0.0/spec.md)** - The easiest way to apply these conventions is to use the `composer lint` command. + +- **Add tests!** - This helps to ensure the codebase is easily maintable. + +- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept + up-to-date. + +- **Consider our release cycle** - We try to follow [SemVer v2.0.0](https://semver.org/). Randomly breaking public APIs is not an + option. + +- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests. + +- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make + multiple intermediate commits while developing, please [squash them](https://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) + before submitting. + +**Happy coding**! diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..cae5bdf --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) Red Explosion + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..befc7cf --- /dev/null +++ b/README.md @@ -0,0 +1,76 @@ +# 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.yml?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. +--- + +This is where your description should go. Limit it to a paragraph or two. Consider adding a small example. + +## Installation + +You can install the package via composer: + +```bash +composer require red-explosion/package_slug +``` + +You can publish and run the migrations with: + +```bash +php artisan vendor:publish --tag="skeleton-migrations" +php artisan migrate +``` + +You can publish the config file with: + +```bash +php artisan vendor:publish --tag="skeleton-config" +``` + +Optionally, you can publish the views using + +```bash +php artisan vendor:publish --tag="skeleton-views" +``` + +## Usage + +```php +$variable = new RedExplosion\Skeleton(); +echo $variable->echoPhrase('Hello, Red Explosion!'); +``` + +## Testing + +```bash +composer test +``` + +## Changelog + +Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. + +## Contributing + +Please see [CONTRIBUTING](CONTRIBUTING.md) for details. + +## Security Vulnerabilities + +If you discover a security vulnerability, please send an e-mail to Ben Sherred via ben@redexplosion.co.uk. All security +vulnerabilities will be promptly addressed. + +## Credits + +- [author_name](https://github.com/author_username) +- [All Contributors](../../contributors) + +## License + +package_name is open-sourced software licensed under the [MIT license](LICENSE.md). diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..02289ac --- /dev/null +++ b/composer.json @@ -0,0 +1,67 @@ +{ + "name": "red-explosion/package_slug", + "description": "package_description", + "license": "MIT", + "homepage": "https://github.com/red-explosion/package_slug", + "type": "library", + "keywords": [ + "red-explosion", + "laravel", + "package_slug" + ], + "authors": [ + { + "name": "author_name", + "email": "author@email.com" + } + ], + "require": { + "php": "^8.2", + "illuminate/support": "^10.0" + }, + "require-dev": { + "laravel/pint": "^1.10", + "orchestra/testbench": "^8.0", + "pestphp/pest": "^2.6", + "pestphp/pest-plugin-arch": "^2.1", + "phpstan/phpstan": "^1.10", + "red-explosion/pint-config": "^1.1", + "spatie/laravel-ray": "^1.32" + }, + "autoload": { + "psr-4": { + "RedExplosion\\Skeleton\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "RedExplosion\\Skeleton\\Tests\\": "tests/" + } + }, + "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": "./vendor/bin/phpstan analyse --ansi", + "test:unit": "./vendor/bin/pest --compact --colors=always", + "test": [ + "@test:lint", + "@test:types", + "@test:unit" + ] + }, + "extra": { + "laravel": { + "providers": [ + "RedExplosion\\Skeleton\\SkeletonServiceProvider" + ] + } + }, + "config": { + "sort-packages": true, + "allow-plugins": { + "pestphp/pest-plugin": true + } + }, + "minimum-stability": "dev", + "prefer-stable": true +} diff --git a/config/skeleton.php b/config/skeleton.php new file mode 100644 index 0000000..0dae23d --- /dev/null +++ b/config/skeleton.php @@ -0,0 +1,5 @@ +.*/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 => [], + }; +} diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..a3ec122 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,11 @@ +parameters: + paths: + - src/ + + level: max + + ignoreErrors: + + excludePaths: + + checkMissingIterableValueType: false diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..f9575ed --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,17 @@ + + + + + ./tests + + + + + ./src + + + diff --git a/resources/views/.gitkeep b/resources/views/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/SkeletonServiceProvider.php b/src/SkeletonServiceProvider.php new file mode 100644 index 0000000..ebb8d62 --- /dev/null +++ b/src/SkeletonServiceProvider.php @@ -0,0 +1,30 @@ +mergeConfigFrom( + path: __DIR__ . '/../config/skeleton.php', + key: 'skeleton', + ); + } + + public function boot(): void + { + if ($this->app->runningInConsole()) { + $this->publishes( + paths: [ + __DIR__ . '/../config/skeleton.php' => config_path('skeleton.php'), + ], + groups: 'skeleton-config', + ); + } + } +} diff --git a/tests/ArchTest.php b/tests/ArchTest.php new file mode 100644 index 0000000..e36f861 --- /dev/null +++ b/tests/ArchTest.php @@ -0,0 +1,7 @@ +expect(['dd', 'ddd', 'dump', 'var_dump', 'ray']) + ->each->not->toBeUsed(); diff --git a/tests/Pest.php b/tests/Pest.php new file mode 100644 index 0000000..eeadeec --- /dev/null +++ b/tests/Pest.php @@ -0,0 +1,7 @@ +in(__DIR__); diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..1ba2dc9 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,18 @@ +