From c356d7eed7824be75ae05bf77d8f1523ee99c864 Mon Sep 17 00:00:00 2001 From: Dauren Kambarov Date: Tue, 12 Mar 2024 14:58:00 +0600 Subject: [PATCH] Initial commit --- .editorconfig | 15 + .gitattributes | 19 ++ .github/ISSUE_TEMPLATE/bug.yml | 66 +++++ .github/ISSUE_TEMPLATE/config.yml | 11 + .github/dependabot.yml | 12 + .github/workflows/dependabot-auto-merge.yml | 32 +++ .../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 | 11 + CHANGELOG.md | 3 + LICENSE.md | 21 ++ README.md | 98 +++++++ composer.json | 78 +++++ config/skeleton.php | 6 + configure.php | 271 ++++++++++++++++++ database/factories/SingleNameFactory.php | 18 ++ .../migrations/create_skeleton_table.php.stub | 25 ++ phpstan-baseline.neon | 0 phpstan.neon.dist | 14 + phpunit.xml.dist | 36 +++ resources/lang/en/skeleton_without_prefix.php | 14 + resources/lang/ru/skeleton_without_prefix.php | 14 + resources/views/.gitkeep | 0 src/Commands/SkeletonCommand.php | 19 ++ src/Facades/Skeleton.php | 16 ++ src/FilamentPlugin.php | 31 ++ src/Models/SingleName.php | 33 +++ src/Providers/RouteServiceProvider.php | 20 ++ src/Skeleton.php | 7 + src/SkeletonServiceProvider.php | 32 +++ src/UI/API/Controllers/Controller.php | 13 + .../API/Controllers/SingleNameController.php | 20 ++ src/UI/API/Routes/api.php | 7 + .../Filament/Resources/SingleNameResource.php | 87 ++++++ .../Pages/CreateSingleName.php | 23 ++ .../Pages/EditSingleName.php | 19 ++ .../Pages/ListSingleName.php | 19 ++ tests/ArchTest.php | 5 + tests/ExampleTest.php | 5 + tests/Pest.php | 5 + tests/TestCase.php | 38 +++ 43 files changed, 1298 insertions(+) create mode 100644 .editorconfig create mode 100644 .gitattributes create mode 100644 .github/ISSUE_TEMPLATE/bug.yml create mode 100644 .github/ISSUE_TEMPLATE/config.yml 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 CHANGELOG.md create mode 100644 LICENSE.md create mode 100644 README.md create mode 100644 composer.json create mode 100644 config/skeleton.php create mode 100644 configure.php create mode 100644 database/factories/SingleNameFactory.php create mode 100644 database/migrations/create_skeleton_table.php.stub create mode 100644 phpstan-baseline.neon create mode 100644 phpstan.neon.dist create mode 100644 phpunit.xml.dist create mode 100644 resources/lang/en/skeleton_without_prefix.php create mode 100644 resources/lang/ru/skeleton_without_prefix.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/FilamentPlugin.php create mode 100644 src/Models/SingleName.php create mode 100644 src/Providers/RouteServiceProvider.php create mode 100755 src/Skeleton.php create mode 100644 src/SkeletonServiceProvider.php create mode 100644 src/UI/API/Controllers/Controller.php create mode 100644 src/UI/API/Controllers/SingleNameController.php create mode 100644 src/UI/API/Routes/api.php create mode 100644 src/UI/Filament/Resources/SingleNameResource.php create mode 100644 src/UI/Filament/Resources/SingleNameResource/Pages/CreateSingleName.php create mode 100644 src/UI/Filament/Resources/SingleNameResource/Pages/EditSingleName.php create mode 100644 src/UI/Filament/Resources/SingleNameResource/Pages/ListSingleName.php 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..9e9519b --- /dev/null +++ b/.gitattributes @@ -0,0 +1,19 @@ +# 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 +/phpunit.xml.dist export-ignore +/art export-ignore +/docs export-ignore +/tests export-ignore +/.editorconfig export-ignore +/.php_cs.dist.php export-ignore +/psalm.xml export-ignore +/psalm.xml.dist export-ignore +/testbench.yaml export-ignore +/UPGRADING.md export-ignore +/phpstan.neon.dist export-ignore +/phpstan-baseline.neon export-ignore diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml new file mode 100644 index 0000000..fe4cfe6 --- /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..3b0259c --- /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/:github_name/:package_name/discussions/new?category=q-a + about: Ask the community for help + - name: Request a feature + url: https://github.com/:github_name/:package_name/discussions/new?category=ideas + about: Share ideas for new features + - name: Report a security issue + url: https://github.com/:github_name/:package_name/security/policy + about: Learn how to notify us for sensitive bugs 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..f98ff2a --- /dev/null +++ b/.github/workflows/dependabot-auto-merge.yml @@ -0,0 +1,32 @@ +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..ab1a6d2 --- /dev/null +++ b/.github/workflows/fix-php-code-style-issues.yml @@ -0,0 +1,27 @@ +name: Fix PHP code style issues + +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.3.1 + + - 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..f17b9d0 --- /dev/null +++ b/.github/workflows/run-tests.yml @@ -0,0 +1,51 @@ +name: run-tests + +on: + push: + branches: [2.x] + pull_request: + branches: [2.x] + +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.63 + + 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..68edce0 --- /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: 2.x + + - 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: 2.x + commit_message: Update CHANGELOG + file_pattern: CHANGELOG.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a7f372d --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +.idea +.phpunit.cache +build +composer.lock +coverage +docs +phpunit.xml +phpstan.neon +testbench.yaml +vendor +node_modules diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..87b3242 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,3 @@ +# Changelog + +All notable changes to `:package_name` will be documented in this file. diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..f334c37 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) :github_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..293a03c --- /dev/null +++ b/README.md @@ -0,0 +1,98 @@ +# :package_description + +[![Latest Version on Packagist](https://img.shields.io/packagist/v/:github_name/:package_slug.svg?style=flat-square)](https://packagist.org/packages/:packagist_name/:package_slug) +[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/:github_name/:package_slug/run-tests.yml?branch=2.x&label=tests&style=flat-square)](https://github.com/:github_name/:package_slug/actions?query=workflow%3Arun-tests+branch%3A2.x) +[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/:github_name/:package_slug/fix-php-code-style-issues.yml?branch=2.x&label=code%20style&style=flat-square)](https://github.com/:github_name/:package_slug/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3A2.x) +[![Total Downloads](https://img.shields.io/packagist/dt/:github_name/:package_slug.svg?style=flat-square)](https://packagist.org/packages/:packagist_name/:package_slug) + +--- +This repo can be used to scaffold a 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. +3. Have fun creating your package. +4. If you need help creating a package, consider picking up our Laravel Package Training video course. +--- + +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 :packagist_name/: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" +``` + +This is the contents of the published config file: + +```php +return [ +]; +``` + +Optionally, you can publish the views using + +```bash +php artisan vendor:publish --tag=":package_slug-views" +``` + +## Usage + +```php +class AdminPanelProvider extends PanelProvider +{ + public function panel(Panel $panel): Panel + { + return $panel + ->default() + ->id('admin') + ->path('admin') + ... + ->plugins([ + ... + \VendorName\Skeleton\FilamentPlugin::make(), + ]); + } +} +``` + +## 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 + +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/composer.json b/composer.json new file mode 100644 index 0000000..9c75524 --- /dev/null +++ b/composer.json @@ -0,0 +1,78 @@ +{ + "name": ":packagist_name/:package_slug", + "description": ":package_description", + "keywords": [ + ":github_name", + "laravel", + ":package_slug" + ], + "homepage": "https://github.com/:github_name/:package_slug", + "license": "MIT", + "authors": [ + { + "name": ":author_name", + "email": "author@domain.com", + "role": "Developer" + } + ], + "require": { + "php": "^8.1", + "filament/filament": "^3.0-stable", + "ibecsystems/admin-kit-core": "^3.1", + "illuminate/contracts": "^10.0", + "spatie/laravel-package-tools": "^1.14.0", + "spatie/laravel-data": "^3.2", + "spatie/laravel-json-api-paginate": "^1.13", + "spatie/laravel-query-builder": "^5.7", + "spatie/laravel-translatable": "^6.5" + }, + "require-dev": { + "laravel/pint": "^1.0", + "nunomaduro/collision": "^7.9", + "nunomaduro/larastan": "^2.0.1", + "orchestra/testbench": "^8.0", + "pestphp/pest": "^2.0", + "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" + }, + "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..435e713 --- /dev/null +++ b/config/skeleton.php @@ -0,0 +1,6 @@ + $version) { + if (in_array($name, $names, true)) { + unset($data['require-dev'][$name]); + } + } + + file_put_contents(__DIR__.'/composer.json', json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); +} + +function remove_composer_script($scriptName) +{ + $data = json_decode(file_get_contents(__DIR__.'/composer.json'), true); + + foreach ($data['scripts'] as $name => $script) { + if ($scriptName === $name) { + unset($data['scripts'][$name]); + break; + } + } + + file_put_contents(__DIR__.'/composer.json', json_encode($data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); +} + +function remove_readme_paragraphs(string $file): void +{ + $contents = file_get_contents($file); + + file_put_contents( + $file, + preg_replace('/.*/s', '', $contents) ?: $contents + ); +} + +function safeUnlink(string $filename) +{ + 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 github_name packagist_name author@domain.com"')); +} + +function replaceForAllOtherOSes(): array +{ + return explode(PHP_EOL, run('grep -E -r -l -i ":author|:vendor|:package|VendorName|skeleton|migration_table_name|github_name|packagist_name|author@domain.com" --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); + +$githubName = 'ibec-box'; +$packagistName = 'ibecsystems'; +$vendorNamespace = 'AdminKit'; + +$currentDirectory = getcwd(); +$folderName = basename($currentDirectory); + +$packageName = ask('Package name', $folderName); +$packageSlug = slugify($packageName); +$packageSlugWithoutPrefix = remove_prefix('admin-kit-', $packageSlug); + +$className = ask('Class name', title_case($packageSlugWithoutPrefix)); +$singleName = ask('Single name', $className); +$description = ask('Package description', "$className package for Admin Kit"); +$variableName = lcfirst($className); + +$usePhpStan = confirm('Enable PhpStan?', true); +$useLaravelPint = confirm('Enable Laravel Pint?', true); +$useDependabot = confirm('Enable Dependabot?', true); +$useUpdateChangelogWorkflow = confirm('Use automatic changelog updater workflow?', true); + +writeln('------'); +writeln("Author : {$authorName} ({$authorUsername}, {$authorEmail})"); +writeln("Vendor : {$githubName} ({$packagistName})"); +writeln("Package : {$packageSlug} <{$description}>"); +writeln("Namespace : {$vendorNamespace}\\{$className}"); +writeln("Class name : {$className}"); +writeln('---'); +writeln('Packages & Utilities'); +writeln('Use Laravel/Pint : '.($useLaravelPint ? 'yes' : 'no')); +writeln('Use Larastan/PhpStan : '.($usePhpStan ? 'yes' : 'no')); +writeln('Use Dependabot : '.($useDependabot ? 'yes' : 'no')); +writeln('Use Auto-Changelog : '.($useUpdateChangelogWorkflow ? 'yes' : 'no')); +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(strtoupper(PHP_OS), 'WIN') ? replaceForWindows() : replaceForAllOtherOSes()); + +foreach ($files as $file) { + replace_in_file($file, [ + ':author_name' => $authorName, + ':author_username' => $authorUsername, + 'author@domain.com' => $authorEmail, + ':github_name' => $githubName, + ':packagist_name' => $packagistName, + 'VendorName' => $vendorNamespace, + ':package_name' => $packageName, + ':package_slug' => $packageSlug, + 'Skeleton' => $className, + 'skeleton_without_prefix' => $packageSlugWithoutPrefix, + 'skeleton' => $packageSlug, + 'SingleName' => $singleName, + 'migration_table_name' => title_snake($packageSlug), + 'variable' => $variableName, + ':package_description' => $description, + ]); + + match (true) { + str_contains($file, determineSeparator('src/UI/API/Controllers/SingleNameController.php')) => rename($file, determineSeparator('./src/UI/API/Controllers/'.$singleName.'Controller.php')), + str_contains($file, determineSeparator('src/UI/Filament/Resources/SingleNameResource.php')) => rename($file, determineSeparator('./src/UI/Filament/Resources/'.$singleName.'Resource.php')), + str_contains($file, determineSeparator('src/UI/Filament/Resources/SingleNameResource/Pages/CreateSingleName.php')) => rename($file, determineSeparator('./src/UI/Filament/Resources/SingleNameResource/Pages/Create'.$singleName.'.php')), + str_contains($file, determineSeparator('src/UI/Filament/Resources/SingleNameResource/Pages/EditSingleName.php')) => rename($file, determineSeparator('./src/UI/Filament/Resources/SingleNameResource/Pages/Edit'.$singleName.'.php')), + str_contains($file, determineSeparator('src/UI/Filament/Resources/SingleNameResource/Pages/ListSingleName.php')) => rename($file, determineSeparator('./src/UI/Filament/Resources/SingleNameResource/Pages/List'.$singleName.'.php')), + str_contains($file, determineSeparator('src/Models/SingleName.php')) => rename($file, determineSeparator('./src/Models/'.$singleName.'.php')), + 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/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('database/factories/SingleNameFactory.php')) => rename($file, determineSeparator('./database/factories/'.$singleName.'Factory.php')), + str_contains($file, determineSeparator('database/migrations/create_skeleton_table.php.stub')) => rename($file, determineSeparator('./database/migrations/create_'.title_snake($packageSlug).'_table.php.stub')), + str_contains($file, determineSeparator('resources/lang/en/skeleton_without_prefix.php')) => rename($file, determineSeparator('./resources/lang/en/'.$packageSlugWithoutPrefix.'.php')), + str_contains($file, determineSeparator('resources/lang/ru/skeleton_without_prefix.php')) => rename($file, determineSeparator('./resources/lang/ru/'.$packageSlugWithoutPrefix.'.php')), + str_contains($file, determineSeparator('config/skeleton.php')) => rename($file, determineSeparator('./config/'.$packageSlug.'.php')), + str_contains($file, 'README.md') => remove_readme_paragraphs($file), + default => [], + }; +} + +rename('src/UI/Filament/Resources/SingleNameResource', determineSeparator('./src/UI/Filament/Resources/'.$singleName.'Resource')); + +if (! $useLaravelPint) { + safeUnlink(__DIR__.'/.github/workflows/fix-php-code-style-issues.yml'); + safeUnlink(__DIR__.'/pint.json'); +} + +if (! $usePhpStan) { + safeUnlink(__DIR__.'/phpstan.neon.dist'); + safeUnlink(__DIR__.'/phpstan-baseline.neon'); + safeUnlink(__DIR__.'/.github/workflows/phpstan.yml'); + + remove_composer_deps([ + 'phpstan/extension-installer', + 'phpstan/phpstan-deprecation-rules', + 'phpstan/phpstan-phpunit', + 'nunomaduro/larastan', + ]); + + remove_composer_script('phpstan'); +} + +if (! $useDependabot) { + safeUnlink(__DIR__.'/.github/dependabot.yml'); + safeUnlink(__DIR__.'/.github/workflows/dependabot-auto-merge.yml'); +} + +if (! $useUpdateChangelogWorkflow) { + safeUnlink(__DIR__.'/.github/workflows/update-changelog.yml'); +} + +confirm('Execute `composer install` and run tests?') && run('composer install && composer test'); + +confirm('Let this script delete itself?', true) && unlink(__FILE__); diff --git a/database/factories/SingleNameFactory.php b/database/factories/SingleNameFactory.php new file mode 100644 index 0000000..b7642e5 --- /dev/null +++ b/database/factories/SingleNameFactory.php @@ -0,0 +1,18 @@ +id(); + + // add fields + $table->jsonb('title')->default('{}'); + + $table->timestamps(); + }); + } + + public function down() + { + Schema::dropIfExists('migration_table_name'); + } +}; 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..0ebf661 --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,36 @@ + + + + + tests + + + + + ./src + + + + + + + + + + + diff --git a/resources/lang/en/skeleton_without_prefix.php b/resources/lang/en/skeleton_without_prefix.php new file mode 100644 index 0000000..7b99a07 --- /dev/null +++ b/resources/lang/en/skeleton_without_prefix.php @@ -0,0 +1,14 @@ + [ + 'label' => 'SingleName', + 'plural_label' => 'Skeleton', + + 'id' => 'ID', + 'title' => 'Title', + + 'created_at' => 'Created At', + 'updated_at' => 'Updated At', + ], +]; diff --git a/resources/lang/ru/skeleton_without_prefix.php b/resources/lang/ru/skeleton_without_prefix.php new file mode 100644 index 0000000..b9df386 --- /dev/null +++ b/resources/lang/ru/skeleton_without_prefix.php @@ -0,0 +1,14 @@ + [ + 'label' => 'SingleName', + 'plural_label' => 'Skeleton', + + 'id' => 'ID', + 'title' => 'Title', + + 'created_at' => 'Создан', + 'updated_at' => 'Обновлен', + ], +]; diff --git a/resources/views/.gitkeep b/resources/views/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/src/Commands/SkeletonCommand.php b/src/Commands/SkeletonCommand.php new file mode 100644 index 0000000..3e5f628 --- /dev/null +++ b/src/Commands/SkeletonCommand.php @@ -0,0 +1,19 @@ +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 @@ +resources([ + SingleNameResource::class, + ]); + } + + public function boot(Panel $panel): void + { + } + + public static function make(): static + { + return app(static::class); + } +} diff --git a/src/Models/SingleName.php b/src/Models/SingleName.php new file mode 100644 index 0000000..500397a --- /dev/null +++ b/src/Models/SingleName.php @@ -0,0 +1,33 @@ +routes(function () { + Route::middleware('api') + ->prefix('api') + ->group(__DIR__.'/../UI/API/Routes/api.php'); + }); + } +} diff --git a/src/Skeleton.php b/src/Skeleton.php new file mode 100755 index 0000000..66fab60 --- /dev/null +++ b/src/Skeleton.php @@ -0,0 +1,7 @@ +name('skeleton') + ->hasConfigFile() + ->hasViews() + ->hasTranslations() + ->hasMigration('create_migration_table_name_table') + ->hasCommand(SkeletonCommand::class); + } + + public function registeringPackage() + { + $this->app->register(RouteServiceProvider::class); + } +} diff --git a/src/UI/API/Controllers/Controller.php b/src/UI/API/Controllers/Controller.php new file mode 100644 index 0000000..3ed7681 --- /dev/null +++ b/src/UI/API/Controllers/Controller.php @@ -0,0 +1,13 @@ +schema([ + TranslatableTabs::make(fn ($locale) => Forms\Components\Tabs\Tab::make($locale)->schema([ + Forms\Components\TextInput::make('title') + ->label(__('skeleton::skeleton_without_prefix.resource.title')) + ->required($locale === app()->getLocale()), + ])), + ]) + ->columns(1); + } + + public static function table(Tables\Table $table): Tables\Table + { + return $table + ->columns([ + Tables\Columns\TextColumn::make('id') + ->label(__('skeleton::skeleton_without_prefix.resource.id')) + ->sortable(), + Tables\Columns\TextColumn::make('title') + ->label(__('skeleton::skeleton_without_prefix.resource.title')), + Tables\Columns\TextColumn::make('created_at') + ->label(__('skeleton::skeleton_without_prefix.resource.created_at')), + ]) + ->defaultSort('id', 'desc') + ->filters([ + // + ]) + ->actions([ + Tables\Actions\EditAction::make(), + Tables\Actions\DeleteAction::make(), + ]) + ->bulkActions([ + Tables\Actions\DeleteBulkAction::make(), + ]) + ->defaultSort('id', 'desc'); + } + + public static function getRelations(): array + { + return [ + // + ]; + } + + public static function getPages(): array + { + return [ + 'index' => Pages\ListSingleName::route('/'), + 'create' => Pages\CreateSingleName::route('/create'), + 'edit' => Pages\EditSingleName::route('/{record}/edit'), + ]; + } + + public static function getLabel(): ?string + { + return __('skeleton::skeleton_without_prefix.resource.label'); + } + + public static function getPluralLabel(): ?string + { + return __('skeleton::skeleton_without_prefix.resource.plural_label'); + } + + public static function getNavigationGroup(): ?string + { + return __('skeleton::skeleton_without_prefix.resource.plural_label'); + } +} diff --git a/src/UI/Filament/Resources/SingleNameResource/Pages/CreateSingleName.php b/src/UI/Filament/Resources/SingleNameResource/Pages/CreateSingleName.php new file mode 100644 index 0000000..efd794f --- /dev/null +++ b/src/UI/Filament/Resources/SingleNameResource/Pages/CreateSingleName.php @@ -0,0 +1,23 @@ +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..00a698c --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,38 @@ + 'VendorName\\Skeleton\\Database\\Factories\\'.class_basename($modelName).'Factory' + ); + } + + protected function getPackageProviders($app) + { + return [ + SkeletonServiceProvider::class, + LivewireServiceProvider::class, + ]; + } + + public function getEnvironmentSetUp($app) + { + config()->set('database.default', 'testing'); + + /* + $migration = include __DIR__.'/../database/migrations/create_skeleton_table.php.stub'; + $migration->up(); + */ + } +}