From b852532ad13aca7752f1bbc00247c17fbdacf9eb Mon Sep 17 00:00:00 2001 From: CodeWithDennis <23448484+CodeWithDennis@users.noreply.github.com> Date: Thu, 27 Jun 2024 09:36:57 +0200 Subject: [PATCH] Initial commit --- .editorconfig | 15 + .gitattributes | 28 ++ .github/CONTRIBUTING.md | 55 +++ .github/FUNDING.yml | 1 + .github/ISSUE_TEMPLATE/bug.yml | 66 ++++ .github/ISSUE_TEMPLATE/config.yml | 11 + .github/SECURITY.md | 3 + .github/dependabot.yml | 12 + .github/workflows/dependabot-auto-merge.yml | 33 ++ .../workflows/fix-php-code-style-issues.yml | 27 ++ .github/workflows/phpstan.yml | 26 ++ .github/workflows/run-tests.yml | 51 +++ .github/workflows/update-changelog.yml | 31 ++ .gitignore | 13 + .prettierrc | 5 + CHANGELOG.md | 7 + LICENSE.md | 21 + README.md | 86 ++++ bin/build.js | 50 +++ composer.json | 79 ++++ config/skeleton.php | 6 + configure.php | 370 ++++++++++++++++++ database/factories/ModelFactory.php | 19 + .../migrations/create_skeleton_table.php.stub | 19 + package.json | 26 ++ phpstan-baseline.neon | 0 phpstan.neon.dist | 14 + phpunit.xml.dist | 38 ++ pint.json | 14 + postcss.config.cjs | 8 + resources/css/index.css | 1 + resources/dist/.gitkeep | 0 resources/js/index.js | 0 resources/lang/en/skeleton.php | 6 + resources/views/.gitkeep | 0 src/Commands/SkeletonCommand.php | 19 + src/Facades/Skeleton.php | 16 + src/Skeleton.php | 7 + src/SkeletonPlugin.php | 37 ++ src/SkeletonServiceProvider.php | 154 ++++++++ src/SkeletonTheme.php | 39 ++ src/Testing/TestsSkeleton.php | 13 + stubs/.gitkeep | 0 tailwind.config.js | 10 + tests/ArchTest.php | 5 + tests/ExampleTest.php | 5 + tests/Pest.php | 5 + tests/TestCase.php | 60 +++ 48 files changed, 1511 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .github/CONTRIBUTING.md create mode 100644 .github/FUNDING.yml create mode 100644 .github/ISSUE_TEMPLATE/bug.yml create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/SECURITY.md create mode 100644 .github/dependabot.yml create mode 100644 .github/workflows/dependabot-auto-merge.yml create mode 100644 .github/workflows/fix-php-code-style-issues.yml create mode 100644 .github/workflows/phpstan.yml create mode 100644 .github/workflows/run-tests.yml create mode 100644 .github/workflows/update-changelog.yml create mode 100644 .gitignore create mode 100644 .prettierrc create mode 100644 CHANGELOG.md create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 bin/build.js create mode 100644 composer.json create mode 100644 config/skeleton.php create mode 100644 configure.php create mode 100644 database/factories/ModelFactory.php create mode 100644 database/migrations/create_skeleton_table.php.stub create mode 100644 package.json create mode 100644 phpstan-baseline.neon create mode 100644 phpstan.neon.dist create mode 100644 phpunit.xml.dist create mode 100644 pint.json create mode 100644 postcss.config.cjs create mode 100644 resources/css/index.css create mode 100644 resources/dist/.gitkeep create mode 100644 resources/js/index.js create mode 100644 resources/lang/en/skeleton.php create mode 100644 resources/views/.gitkeep create mode 100644 src/Commands/SkeletonCommand.php create mode 100644 src/Facades/Skeleton.php create mode 100644 src/Skeleton.php create mode 100644 src/SkeletonPlugin.php create mode 100644 src/SkeletonServiceProvider.php create mode 100644 src/SkeletonTheme.php create mode 100644 src/Testing/TestsSkeleton.php create mode 100644 stubs/.gitkeep create mode 100644 tailwind.config.js create mode 100644 tests/ArchTest.php create mode 100644 tests/ExampleTest.php create mode 100644 tests/Pest.php create mode 100644 tests/TestCase.php diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..dd9a2b5 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,15 @@ +root = true + +[*] +charset = utf-8 +end_of_line = lf +indent_size = 4 +indent_style = space +insert_final_newline = true +trim_trailing_whitespace = true + +[*.md] +trim_trailing_whitespace = false + +[*.{yml,yaml}] +indent_size = 2 diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..9c9472b --- /dev/null +++ b/.gitattributes @@ -0,0 +1,28 @@ +# Path-based git attributes +# https://www.kernel.org/pub/software/scm/git/docs/gitattributes.html + +# Ignore all test and documentation with "export-ignore". +/.github export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.idea export-ignore +/.prettierrc export-ignore +/.package-lock.json export-ignore +/.editorconfig export-ignore +/.php_cs.dist.php export-ignore +/.vscode export-ignore +/art export-ignore +/docs export-ignore +/images export-ignore +/tests export-ignore +/package.json export-ignore +/phpstan-baseline.neon export-ignore +/phpstan.neon.dist export-ignore +/postcss.config.js export-ignore +/phpunit.xml.dist export-ignore +/pint.json export-ignore +/psalm.xml export-ignore +/psalm.xml.dist export-ignore +/tailwind.config.js export-ignore +/testbench.yaml export-ignore +/UPGRADING.md export-ignore diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..b0ee5d8 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,55 @@ +# 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 skills, 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. + +- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](https://pear.php.net/package/PHP_CodeSniffer). + +- **Add tests!** - Your patch won't be accepted if it doesn't have tests. + +- **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/.github/FUNDING.yml b/.github/FUNDING.yml new file mode 100644 index 0000000..c68765b --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: :vendor_name diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml new file mode 100644 index 0000000..8fa85ce --- /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: 2.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: 9.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..96701be --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,11 @@ +blank_issues_enabled: false +contact_links: + - name: Ask a question + url: https://github.com/:vendor_name/:package_name/discussions/new?category=q-a + about: Ask the community for help + - name: Request a feature + url: https://github.com/:vendor_name/:package_name/discussions/new?category=ideas + about: Share ideas for new features + - name: Report a security issue + url: https://github.com/:vendor_name/:package_name/security/policy + about: Learn how to notify us for sensitive bugs diff --git a/.github/SECURITY.md b/.github/SECURITY.md new file mode 100644 index 0000000..12ab7c2 --- /dev/null +++ b/.github/SECURITY.md @@ -0,0 +1,3 @@ +# Security Policy + +If you discover any security related issues, please email author@domain.com instead of using the issue tracker. diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..30c8a49 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,12 @@ +# 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" + labels: + - "dependencies" \ No newline at end of file diff --git a/.github/workflows/dependabot-auto-merge.yml b/.github/workflows/dependabot-auto-merge.yml new file mode 100644 index 0000000..d266418 --- /dev/null +++ b/.github/workflows/dependabot-auto-merge.yml @@ -0,0 +1,33 @@ +name: "Dependabot Auto-Merge" + +on: pull_request_target + +permissions: + pull-requests: write + contents: write + +jobs: + dependabot: + runs-on: ubuntu-latest + if: ${{ github.actor == 'dependabot[bot]' }} + steps: + + - name: Dependabot metadata + id: metadata + uses: dependabot/fetch-metadata@v1.6.0 + with: + github-token: "${{ secrets.GITHUB_TOKEN }}" + + - name: Auto-merge Dependabot PRs for semver-minor updates + if: ${{steps.metadata.outputs.update-type == 'version-update:semver-minor'}} + run: gh pr merge --auto --merge "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + + - name: Auto-merge Dependabot PRs for semver-patch updates + if: ${{steps.metadata.outputs.update-type == 'version-update:semver-patch'}} + run: gh pr merge --auto --merge "$PR_URL" + env: + PR_URL: ${{github.event.pull_request.html_url}} + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/.github/workflows/fix-php-code-style-issues.yml b/.github/workflows/fix-php-code-style-issues.yml new file mode 100644 index 0000000..756a961 --- /dev/null +++ b/.github/workflows/fix-php-code-style-issues.yml @@ -0,0 +1,27 @@ +name: "Fix PHP Code Styling" + +on: + push: + paths: + - '**.php' + +permissions: + contents: write + +jobs: + php-code-styling: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + ref: ${{ github.head_ref }} + + - name: Fix PHP code style issues + uses: aglipanci/laravel-pint-action@2.4 + + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: Fix styling diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml new file mode 100644 index 0000000..3855a08 --- /dev/null +++ b/.github/workflows/phpstan.yml @@ -0,0 +1,26 @@ +name: PHPStan + +on: + push: + paths: + - '**.php' + - 'phpstan.neon.dist' + +jobs: + phpstan: + name: phpstan + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.1' + coverage: none + + - name: Install composer dependencies + uses: ramsey/composer-install@v3 + + - name: Run PHPStan + run: ./vendor/bin/phpstan --error-format=github diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml new file mode 100644 index 0000000..7c60f1f --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,51 @@ +name: run-tests + +on: + push: + branches: [main] + pull_request: + branches: [main] + +jobs: + test: + runs-on: ${{ matrix.os }} + strategy: + fail-fast: true + matrix: + os: [ubuntu-latest, windows-latest] + php: [8.2, 8.1] + laravel: [10.*] + stability: [prefer-lowest, prefer-stable] + include: + - laravel: 10.* + testbench: 8.* + carbon: 2.* + + name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }} + + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php }} + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick, fileinfo + coverage: none + + - name: Setup problem matchers + run: | + echo "::add-matcher::${{ runner.tool_cache }}/php.json" + echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json" + + - name: Install dependencies + run: | + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" "nesbot/carbon:${{ matrix.carbon }}" --no-interaction --no-update + composer update --${{ matrix.stability }} --prefer-dist --no-interaction + + - name: List Installed Dependencies + run: composer show -D + + - name: Execute tests + run: vendor/bin/pest --ci diff --git a/.github/workflows/update-changelog.yml b/.github/workflows/update-changelog.yml new file mode 100644 index 0000000..ec40921 --- /dev/null +++ b/.github/workflows/update-changelog.yml @@ -0,0 +1,31 @@ +name: "Update Changelog" + +on: + release: + types: [released] + +permissions: + contents: write + +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@v5 + with: + branch: main + commit_message: Update CHANGELOG + file_pattern: CHANGELOG.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8271e65 --- /dev/null +++ b/.gitignore @@ -0,0 +1,13 @@ +.DS_Store +.idea +.phpunit.result.cache +.vscode +build +composer.lock +coverage +docs +node_modules +phpunit.xml +phpstan.neon +testbench.yaml +vendor diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..98406c6 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "semi": false, + "singleQuote": true, + "trailingComma": "all" +} diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..767365d --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,7 @@ +# Changelog + +All notable changes to `:package_name` will be documented in this file. + +## 1.0.0 - 202X-XX-XX + +- initial release diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..58c9ad4 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) :vendor_name + +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..98f321d --- /dev/null +++ b/README.md @@ -0,0 +1,86 @@ +# :package_description + +[![Latest Version on Packagist](https://img.shields.io/packagist/v/:vendor_slug/:package_slug.svg?style=flat-square)](https://packagist.org/packages/:vendor_slug/:package_slug) +[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/:vendor_slug/:package_slug/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/:vendor_slug/:package_slug/actions?query=workflow%3Arun-tests+branch%3Amain) +[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/:vendor_slug/:package_slug/fix-php-code-styling.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/:vendor_slug/:package_slug/actions?query=workflow%3A"Fix+PHP+code+styling"+branch%3Amain) +[![Total Downloads](https://img.shields.io/packagist/dt/:vendor_slug/:package_slug.svg?style=flat-square)](https://packagist.org/packages/:vendor_slug/:package_slug) + + +--- +This repo can be used to scaffold a Filament plugin. 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. +3. Make something great! +--- + + +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 :vendor_slug/:package_slug +``` + +You can publish and run the migrations with: + +```bash +php artisan vendor:publish --tag=":package_slug-migrations" +php artisan migrate +``` + +You can publish the config file with: + +```bash +php artisan vendor:publish --tag=":package_slug-config" +``` + +Optionally, you can publish the views using + +```bash +php artisan vendor:publish --tag=":package_slug-views" +``` + +This is the contents of the published config file: + +```php +return [ +]; +``` + +## Usage + +```php +$variable = new VendorName\Skeleton(); +echo $variable->echoPhrase('Hello, VendorName!'); +``` + +## Testing + +```bash +composer test +``` + +## Changelog + +Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently. + +## Contributing + +Please see [CONTRIBUTING](.github/CONTRIBUTING.md) for details. + +## Security Vulnerabilities + +Please review [our security policy](../../security/policy) on how to report security vulnerabilities. + +## Credits + +- [:author_name](https://github.com/:author_username) +- [All Contributors](../../contributors) + +## License + +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. diff --git a/bin/build.js b/bin/build.js new file mode 100644 index 0000000..913baf4 --- /dev/null +++ b/bin/build.js @@ -0,0 +1,50 @@ +import esbuild from 'esbuild' + +const isDev = process.argv.includes('--dev') + +async function compile(options) { + const context = await esbuild.context(options) + + if (isDev) { + await context.watch() + } else { + await context.rebuild() + await context.dispose() + } +} + +const defaultOptions = { + define: { + 'process.env.NODE_ENV': isDev ? `'development'` : `'production'`, + }, + bundle: true, + mainFields: ['module', 'main'], + platform: 'neutral', + sourcemap: isDev ? 'inline' : false, + sourcesContent: isDev, + treeShaking: true, + target: ['es2020'], + minify: !isDev, + plugins: [{ + name: 'watchPlugin', + setup: function (build) { + build.onStart(() => { + console.log(`Build started at ${new Date(Date.now()).toLocaleTimeString()}: ${build.initialOptions.outfile}`) + }) + + build.onEnd((result) => { + if (result.errors.length > 0) { + console.log(`Build failed at ${new Date(Date.now()).toLocaleTimeString()}: ${build.initialOptions.outfile}`, result.errors) + } else { + console.log(`Build finished at ${new Date(Date.now()).toLocaleTimeString()}: ${build.initialOptions.outfile}`) + } + }) + } + }], +} + +compile({ + ...defaultOptions, + entryPoints: ['./resources/js/index.js'], + outfile: './resources/dist/skeleton.js', +}) diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..bb6be65 --- /dev/null +++ b/composer.json @@ -0,0 +1,79 @@ +{ + "name": ":vendor_slug/:package_slug", + "description": ":package_description", + "keywords": [ + ":vendor_name", + "laravel", + ":package_slug" + ], + "homepage": "https://github.com/:vendor_slug/:package_slug", + "support": { + "issues": "https://github.com/:vendor_slug/:package_slug/issues", + "source": "https://github.com/:vendor_slug/:package_slug" + }, + "license": "MIT", + "authors": [ + { + "name": ":author_name", + "email": "author@domain.com", + "role": "Developer" + } + ], + "require": { + "php": "^8.1", + "filament/filament": "^3.0", + "filament/forms": "^3.0", + "filament/tables": "^3.0", + "spatie/laravel-package-tools": "^1.15.0" + }, + "require-dev": { + "laravel/pint": "^1.0", + "nunomaduro/collision": "^7.9", + "nunomaduro/larastan": "^2.0.1", + "orchestra/testbench": "^8.0", + "pestphp/pest": "^2.1", + "pestphp/pest-plugin-arch": "^2.0", + "pestphp/pest-plugin-laravel": "^2.0", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan-deprecation-rules": "^1.0", + "phpstan/phpstan-phpunit": "^1.0", + "spatie/laravel-ray": "^1.26" + }, + "autoload": { + "psr-4": { + "VendorName\\Skeleton\\": "src/", + "VendorName\\Skeleton\\Database\\Factories\\": "database/factories/" + } + }, + "autoload-dev": { + "psr-4": { + "VendorName\\Skeleton\\Tests\\": "tests/" + } + }, + "scripts": { + "post-autoload-dump": "@php ./vendor/bin/testbench package:discover --ansi", + "analyse": "vendor/bin/phpstan analyse", + "test": "vendor/bin/pest", + "test-coverage": "vendor/bin/pest --coverage", + "format": "vendor/bin/pint" + }, + "config": { + "sort-packages": true, + "allow-plugins": { + "pestphp/pest-plugin": true, + "phpstan/extension-installer": true + } + }, + "extra": { + "laravel": { + "providers": [ + "VendorName\\Skeleton\\SkeletonServiceProvider" + ], + "aliases": { + "Skeleton": "VendorName\\Skeleton\\Facades\\Skeleton" + } + } + }, + "minimum-stability": "dev", + "prefer-stable": true +} diff --git a/config/skeleton.php b/config/skeleton.php new file mode 100644 index 0000000..7e74186 --- /dev/null +++ b/config/skeleton.php @@ -0,0 +1,6 @@ +" : '') . "\e[0m"); +writeln("Namespace : \e[0;36m$vendorNamespace\\$className\e[0m"); +writeln("Class name : \e[0;36m$className\e[0m"); +writeln('---'); +writeln("\e[1;37mPackages & Utilities\e[0m"); +writeln('Larastan/PhpStan : ' . ($usePhpStan ? "\e[0;32mYes" : "\e[0;31mNo") . "\e[0m"); +writeln('Pint : ' . ($usePint ? "\e[0;32mYes" : "\e[0;31mNo") . "\e[0m"); +writeln('Use Dependabot : ' . ($useDependabot ? "\e[0;32mYes" : "\e[0;31mNo") . "\e[0m"); +writeln('Use Ray : ' . ($useLaravelRay ? "\e[0;32mYes" : "\e[0;31mNo") . "\e[0m"); +writeln('Auto-Changelog : ' . ($useUpdateChangelogWorkflow ? "\e[0;32mYes" : "\e[0;31mNo") . "\e[0m"); +if ($formsOnly) { + writeln("Filament/Forms : \e[0;32mYes\e[0m"); +} elseif ($tablesOnly) { + writeln("Filament/Tables : \e[0;32mYes\e[0m"); +} else { + writeln("Filament/Filament : \e[0;32mYes\e[0m"); +} +writeln('------'); +writeln("\r"); +writeln('This script will replace the above values in all relevant files in the project directory.'); +writeln("\r"); + +if (! confirm('Modify files?', true)) { + exit(1); +} + +if ($formsOnly) { + safeUnlink(__DIR__ . '/src/SkeletonTheme.php'); + safeUnlink(__DIR__ . '/src/SkeletonPlugin.php'); + + removeComposerDeps([ + 'filament/filament', + 'filament/tables', + ], 'require'); +} elseif ($tablesOnly) { + safeUnlink(__DIR__ . '/src/SkeletonTheme.php'); + safeUnlink(__DIR__ . '/src/SkeletonPlugin.php'); + + removeComposerDeps([ + 'filament/filament', + 'filament/forms', + ], 'require'); +} else { + if ($isTheme) { + safeUnlink(__DIR__ . '/src/SkeletonServiceProvider.php'); + safeUnlink(__DIR__ . '/src/SkeletonPlugin.php'); + safeUnlink(__DIR__ . '/src/Skeleton.php'); + removeDirectory(__DIR__ . '/bin'); + removeDirectory(__DIR__ . '/config'); + removeDirectory(__DIR__ . '/database'); + removeDirectory(__DIR__ . '/stubs'); + removeDirectory(__DIR__ . '/resources/js'); + removeDirectory(__DIR__ . '/resources/lang'); + removeDirectory(__DIR__ . '/resources/views'); + removeDirectory(__DIR__ . '/src/Commands'); + removeDirectory(__DIR__ . '/src/Facades'); + removeDirectory(__DIR__ . '/src/Testing'); + + setupPackageJsonForTheme(); + + } else { + safeUnlink(__DIR__ . '/src/SkeletonTheme.php'); + } + + removeComposerDeps([ + 'filament/forms', + 'filament/tables', + ], 'require'); +} + +$files = (str_starts_with(strtoupper(PHP_OS), 'WIN') ? replaceForWindows() : replaceForAllOtherOSes()); + +foreach ($files as $file) { + replaceInFile($file, [ + ':author_name' => $authorName, + ':author_username' => $authorUsername, + 'author@domain.com' => $authorEmail, + ':vendor_name' => $vendorName, + ':vendor_slug' => $vendorSlug, + 'VendorName' => $vendorNamespace, + ':package_name' => $packageName, + ':package_slug' => $packageSlug, + ':package_slug_without_prefix' => $packageSlugWithoutPrefix, + 'Skeleton' => $className, + 'skeleton' => $packageSlug, + 'migration_table_name' => titleSnake($packageSlug), + 'variable' => $variableName, + ':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('src/SkeletonTheme.php')) => rename($file, determineSeparator('./src/' . $className . (str_ends_with($className, 'Theme') ? '.php' : 'Theme.php'))), + str_contains($file, determineSeparator('src/SkeletonPlugin.php')) => rename($file, determineSeparator('./src/' . $className . 'Plugin.php')), + str_contains($file, determineSeparator('src/Facades/Skeleton.php')) => rename($file, determineSeparator('./src/Facades/' . $className . '.php')), + str_contains($file, determineSeparator('src/Commands/SkeletonCommand.php')) => rename($file, determineSeparator('./src/Commands/' . $className . 'Command.php')), + str_contains($file, determineSeparator('src/Testing/TestsSkeleton.php')) => rename($file, determineSeparator('./src/Testing/Tests' . $className . '.php')), + str_contains($file, determineSeparator('database/migrations/create_skeleton_table.php.stub')) => rename($file, determineSeparator('./database/migrations/create_' . titleSnake($packageSlugWithoutPrefix) . '_table.php.stub')), + str_contains($file, determineSeparator('config/skeleton.php')) => rename($file, determineSeparator('./config/' . $packageSlugWithoutPrefix . '.php')), + str_contains($file, determineSeparator('resources/lang/en/skeleton.php')) => rename($file, determineSeparator('./resources/lang/en/' . $packageSlugWithoutPrefix . '.php')), + str_contains($file, 'README.md') => removeTag($file, 'delete'), + default => [], + }; +} + +if (! $useDependabot) { + safeUnlink(__DIR__ . '/.github/dependabot.yml'); + safeUnlink(__DIR__ . '/.github/workflows/dependabot-auto-merge.yml'); +} + +if (! $useLaravelRay) { + removeComposerDeps(['spatie/laravel-ray'], 'require-dev'); +} + +if (! $usePhpStan) { + safeUnlink(__DIR__ . '/phpstan.neon.dist'); + safeUnlink(__DIR__ . '/phpstan-baseline.neon'); + safeUnlink(__DIR__ . '/.github/workflows/phpstan.yml'); + + removeComposerDeps([ + 'phpstan/extension-installer', + 'phpstan/phpstan-deprecation-rules', + 'phpstan/phpstan-phpunit', + 'nunomaduro/larastan', + ], 'require-dev'); + + removeComposerDeps(['analyse'], 'scripts'); +} + +if (! $usePint) { + safeUnlink(__DIR__ . '/.github/workflows/fix-php-code-style-issues.yml'); + safeUnlink(__DIR__ . '/pint.json'); + + removeComposerDeps([ + 'laravel/pint', + ], 'require-dev'); + + removeComposerDeps(['format'], 'scripts'); +} + +if (! $useUpdateChangelogWorkflow) { + safeUnlink(__DIR__ . '/.github/workflows/update-changelog.yml'); +} + +confirm('Execute `composer install`?') && run('composer install'); + +if (confirm('Let this script delete itself?', true)) { + unlink(__FILE__); +} + +function ask(string $question, string $default = ''): string +{ + $def = $default ? "\e[0;33m ($default)" : ''; + $answer = readline("\e[0;32m" . $question . $def . ": \e[0m"); + + if (! $answer) { + return $default; + } + + return $answer; +} + +function confirm(string $question, bool $default = false): bool +{ + $answer = ask($question, ($default ? 'Y/n' : 'y/N')); + + if (strtolower($answer) === 'y/n') { + return $default; + } + + return strtolower($answer) === 'y'; +} + +function writeln(string $line): void +{ + echo $line . PHP_EOL; +} + +function run(string $command): string +{ + return trim((string) shell_exec($command)); +} + +function slugify(string $subject): string +{ + return strtolower(trim(preg_replace('/[^A-Za-z0-9-]+/', '-', $subject), '-')); +} + +function titleCase(string $subject): string +{ + return str_replace(' ', '', ucwords(str_replace(['-', '_'], ' ', $subject))); +} + +function titleSnake(string $subject, string $replace = '_'): string +{ + return str_replace(['-', '_'], $replace, $subject); +} + +function replaceInFile(string $file, array $replacements): void +{ + $contents = file_get_contents($file); + + file_put_contents( + $file, + str_replace( + array_keys($replacements), + array_values($replacements), + $contents + ) + ); +} + +function removePrefix(string $prefix, string $content): string +{ + if (str_starts_with($content, $prefix)) { + return substr($content, strlen($prefix)); + } + + return $content; +} + +function removeComposerDeps(array $names, string $location): void +{ + $data = json_decode(file_get_contents(__DIR__ . '/composer.json'), true); + + foreach ($data[$location] as $name => $version) { + if (in_array($name, $names, true)) { + unset($data[$location][$name]); + } + } + + file_put_contents(__DIR__ . '/composer.json', json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); +} + +function removeNpmDeps(array $names, string $location): void +{ + $data = json_decode(file_get_contents(__DIR__ . '/package.json'), true); + + foreach ($data[$location] as $name => $version) { + if (in_array($name, $names, true)) { + unset($data[$location][$name]); + } + } + + file_put_contents(__DIR__ . '/package.json', json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | + JSON_UNESCAPED_UNICODE)); +} + +function removeTag(string $file, string $tag): void +{ + $contents = file_get_contents($file); + + file_put_contents( + $file, + preg_replace('/.*/s', '', $contents) ?: $contents + ); +} + +function setupPackageJsonForTheme(): void +{ + removeNpmDeps([ + 'purge', + 'dev', + 'dev:scripts', + 'build', + 'build:scripts', + ], 'scripts'); + + removeNpmDeps([ + '@awcodes/filament-plugin-purge', + 'esbuild', + 'npm-run-all', + 'prettier', + 'prettier-plugin-tailwindcss', + ], 'devDependencies'); + + replaceInFile(__DIR__ . '/package.json', [ + 'dev:styles' => 'dev', + 'build:styles' => 'build', + ]); +} + +function safeUnlink(string $filename): void +{ + if (file_exists($filename) && is_file($filename)) { + unlink($filename); + } +} + +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 :vendor :package VendorName skeleton migration_table_name vendor_name vendor_slug author@domain.com"')); +} + +function replaceForAllOtherOSes(): array +{ + return explode(PHP_EOL, run('find ./* ./.github/* -name "vendor" -type d -prune \ + -o -name "configure.php" -prune \ + -o -type f -print0 | xargs -0 grep -E -r -l -i ":author|:vendor|:package|VendorName|skeleton|migration_table_name|vendor_name|vendor_slug|author@domain.com"')); +} + +function removeDirectory($dir): void +{ + if (is_dir($dir)) { + $objects = scandir($dir); + foreach ($objects as $object) { + if ($object != '.' && $object != '..') { + if (filetype($dir . '/' . $object) == 'dir') { + removeDirectory($dir . '/' . $object); + } else { + unlink($dir . '/' . $object); + } + } + } + rmdir($dir); + } +} diff --git a/database/factories/ModelFactory.php b/database/factories/ModelFactory.php new file mode 100644 index 0000000..c51604f --- /dev/null +++ b/database/factories/ModelFactory.php @@ -0,0 +1,19 @@ +id(); + + // add fields + + $table->timestamps(); + }); + } +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..afec3c0 --- /dev/null +++ b/package.json @@ -0,0 +1,26 @@ +{ + "private": true, + "type": "module", + "scripts": { + "dev:styles": "npx tailwindcss -i resources/css/index.css -o resources/dist/skeleton.css --postcss --watch", + "dev:scripts": "node bin/build.js --dev", + "build:styles": "npx tailwindcss -i resources/css/index.css -o resources/dist/skeleton.css --postcss --minify && npm run purge", + "build:scripts": "node bin/build.js", + "purge": "filament-purge -i resources/dist/skeleton.css -o resources/dist/skeleton.css -v 3.x", + "dev": "npm-run-all --parallel dev:*", + "build": "npm-run-all build:*" + }, + "devDependencies": { + "@awcodes/filament-plugin-purge": "^1.1.1", + "@tailwindcss/forms": "^0.5.4", + "@tailwindcss/typography": "^0.5.9", + "autoprefixer": "^10.4.14", + "esbuild": "^0.19.2", + "npm-run-all": "^4.1.5", + "postcss": "^8.4.26", + "postcss-import": "^15.1.0", + "prettier": "^2.7.1", + "prettier-plugin-tailwindcss": "^0.1.13", + "tailwindcss": "^3.3.3" + } +} diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..e69de29 diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..a91953b --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,14 @@ +includes: + - phpstan-baseline.neon + +parameters: + level: 4 + paths: + - src + - config + - database + tmpDir: build/phpstan + checkOctaneCompatibility: true + checkModelProperties: true + checkMissingIterableValueType: false + diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..e953c0e --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,38 @@ + + + + + tests + + + + + + + + + + + + + + + ./src + + + diff --git a/pint.json b/pint.json new file mode 100644 index 0000000..c6ddb49 --- /dev/null +++ b/pint.json @@ -0,0 +1,14 @@ +{ + "preset": "laravel", + "rules": { + "blank_line_before_statement": true, + "concat_space": { + "spacing": "one" + }, + "method_argument_space": true, + "single_trait_insert_per_statement": true, + "types_spaces": { + "space": "single" + } + } +} diff --git a/postcss.config.cjs b/postcss.config.cjs new file mode 100644 index 0000000..2855394 --- /dev/null +++ b/postcss.config.cjs @@ -0,0 +1,8 @@ +module.exports = { + plugins: { + "postcss-import": {}, + "tailwindcss/nesting": {}, + tailwindcss: {}, + autoprefixer: {}, + }, +} diff --git a/resources/css/index.css b/resources/css/index.css new file mode 100644 index 0000000..b3949d5 --- /dev/null +++ b/resources/css/index.css @@ -0,0 +1 @@ +@import '../../vendor/filament/filament/resources/css/theme.css'; diff --git a/resources/dist/.gitkeep b/resources/dist/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/resources/js/index.js b/resources/js/index.js new file mode 100644 index 0000000..e69de29 diff --git a/resources/lang/en/skeleton.php b/resources/lang/en/skeleton.php new file mode 100644 index 0000000..d1b24d9 --- /dev/null +++ b/resources/lang/en/skeleton.php @@ -0,0 +1,6 @@ +comment('All done'); + + return self::SUCCESS; + } +} diff --git a/src/Facades/Skeleton.php b/src/Facades/Skeleton.php new file mode 100644 index 0000000..1fa9076 --- /dev/null +++ b/src/Facades/Skeleton.php @@ -0,0 +1,16 @@ +getId()); + + return $plugin; + } +} diff --git a/src/SkeletonServiceProvider.php b/src/SkeletonServiceProvider.php new file mode 100644 index 0000000..266d50d --- /dev/null +++ b/src/SkeletonServiceProvider.php @@ -0,0 +1,154 @@ +name(static::$name) + ->hasCommands($this->getCommands()) + ->hasInstallCommand(function (InstallCommand $command) { + $command + ->publishConfigFile() + ->publishMigrations() + ->askToRunMigrations() + ->askToStarRepoOnGitHub(':vendor_slug/:package_slug'); + }); + + $configFileName = $package->shortName(); + + if (file_exists($package->basePath("/../config/{$configFileName}.php"))) { + $package->hasConfigFile(); + } + + if (file_exists($package->basePath('/../database/migrations'))) { + $package->hasMigrations($this->getMigrations()); + } + + if (file_exists($package->basePath('/../resources/lang'))) { + $package->hasTranslations(); + } + + if (file_exists($package->basePath('/../resources/views'))) { + $package->hasViews(static::$viewNamespace); + } + } + + public function packageRegistered(): void + { + } + + public function packageBooted(): void + { + // Asset Registration + FilamentAsset::register( + $this->getAssets(), + $this->getAssetPackageName() + ); + + FilamentAsset::registerScriptData( + $this->getScriptData(), + $this->getAssetPackageName() + ); + + // Icon Registration + FilamentIcon::register($this->getIcons()); + + // Handle Stubs + if (app()->runningInConsole()) { + foreach (app(Filesystem::class)->files(__DIR__ . '/../stubs/') as $file) { + $this->publishes([ + $file->getRealPath() => base_path("stubs/skeleton/{$file->getFilename()}"), + ], 'skeleton-stubs'); + } + } + + // Testing + Testable::mixin(new TestsSkeleton()); + } + + protected function getAssetPackageName(): ?string + { + return ':vendor_slug/:package_slug'; + } + + /** + * @return array + */ + protected function getAssets(): array + { + return [ + // AlpineComponent::make('skeleton', __DIR__ . '/../resources/dist/components/skeleton.js'), + Css::make('skeleton-styles', __DIR__ . '/../resources/dist/skeleton.css'), + Js::make('skeleton-scripts', __DIR__ . '/../resources/dist/skeleton.js'), + ]; + } + + /** + * @return array + */ + protected function getCommands(): array + { + return [ + SkeletonCommand::class, + ]; + } + + /** + * @return array + */ + protected function getIcons(): array + { + return []; + } + + /** + * @return array + */ + protected function getRoutes(): array + { + return []; + } + + /** + * @return array + */ + protected function getScriptData(): array + { + return []; + } + + /** + * @return array + */ + protected function getMigrations(): array + { + return [ + 'create_skeleton_table', + ]; + } +} diff --git a/src/SkeletonTheme.php b/src/SkeletonTheme.php new file mode 100644 index 0000000..6c647e0 --- /dev/null +++ b/src/SkeletonTheme.php @@ -0,0 +1,39 @@ +font('DM Sans') + ->primaryColor(Color::Amber) + ->secondaryColor(Color::Gray) + ->warningColor(Color::Amber) + ->dangerColor(Color::Rose) + ->successColor(Color::Green) + ->grayColor(Color::Gray) + ->theme('skeleton'); + } + + public function boot(Panel $panel): void + { + // + } +} diff --git a/src/Testing/TestsSkeleton.php b/src/Testing/TestsSkeleton.php new file mode 100644 index 0000000..0e33b51 --- /dev/null +++ b/src/Testing/TestsSkeleton.php @@ -0,0 +1,13 @@ +expect(['dd', 'dump', 'ray']) + ->each->not->toBeUsed(); diff --git a/tests/ExampleTest.php b/tests/ExampleTest.php new file mode 100644 index 0000000..5d36321 --- /dev/null +++ b/tests/ExampleTest.php @@ -0,0 +1,5 @@ +toBeTrue(); +}); diff --git a/tests/Pest.php b/tests/Pest.php new file mode 100644 index 0000000..7fe1500 --- /dev/null +++ b/tests/Pest.php @@ -0,0 +1,5 @@ +in(__DIR__); diff --git a/tests/TestCase.php b/tests/TestCase.php new file mode 100644 index 0000000..14a77a0 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,60 @@ + 'VendorName\\Skeleton\\Database\\Factories\\' . class_basename($modelName) . 'Factory' + ); + } + + protected function getPackageProviders($app) + { + return [ + ActionsServiceProvider::class, + BladeCaptureDirectiveServiceProvider::class, + BladeHeroiconsServiceProvider::class, + BladeIconsServiceProvider::class, + FilamentServiceProvider::class, + FormsServiceProvider::class, + InfolistsServiceProvider::class, + LivewireServiceProvider::class, + NotificationsServiceProvider::class, + SupportServiceProvider::class, + TablesServiceProvider::class, + WidgetsServiceProvider::class, + SkeletonServiceProvider::class, + ]; + } + + public function getEnvironmentSetUp($app) + { + config()->set('database.default', 'testing'); + + /* + $migration = include __DIR__.'/../database/migrations/create_skeleton_table.php.stub'; + $migration->up(); + */ + } +}