From e948142ab00ec3d9b318e245672bed97c5cf5628 Mon Sep 17 00:00:00 2001 From: Joao Nascimento Date: Sat, 22 Jun 2024 19:58:10 +0100 Subject: [PATCH] first 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/run-tests.yml | 51 ++++++ .github/workflows/update-changelog.yml | 31 ++++ .gitignore | 13 ++ .prettierrc | 5 + CHANGELOG.md | 7 + LICENSE.md | 21 +++ README.md | 78 +++++++++ bin/build.js | 50 ++++++ composer.json | 71 ++++++++ config/edit-env.php | 6 + database/factories/ModelFactory.php | 19 +++ .../migrations/create_edit_env_table.php.stub | 19 +++ package.json | 26 +++ phpunit.xml.dist | 38 +++++ pint.json | 14 ++ postcss.config.cjs | 8 + resources/css/index.css | 1 + resources/dist/.gitkeep | 0 resources/dist/filament-edit-env.css | 0 resources/dist/filament-edit-env.js | 0 resources/js/index.js | 0 resources/lang/en/edit-env.php | 6 + resources/views/.gitkeep | 0 .../change-env-file-component.blade.php | 5 + src/Commands/FilamentEditEnvCommand.php | 19 +++ src/Facades/FilamentEditEnv.php | 16 ++ src/FilamentEditEnv.php | 7 + src/FilamentEditEnvPlugin.php | 73 +++++++++ src/FilamentEditEnvServiceProvider.php | 154 ++++++++++++++++++ src/Livewire/ChangeEnvFileComponent.php | 50 ++++++ src/Testing/TestsFilamentEditEnv.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 +++++++ 47 files changed, 1137 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/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/edit-env.php create mode 100644 database/factories/ModelFactory.php create mode 100644 database/migrations/create_edit_env_table.php.stub create mode 100644 package.json 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/dist/filament-edit-env.css create mode 100644 resources/dist/filament-edit-env.js create mode 100644 resources/js/index.js create mode 100644 resources/lang/en/edit-env.php create mode 100644 resources/views/.gitkeep create mode 100644 resources/views/livewire/change-env-file-component.blade.php create mode 100644 src/Commands/FilamentEditEnvCommand.php create mode 100644 src/Facades/FilamentEditEnv.php create mode 100644 src/FilamentEditEnv.php create mode 100644 src/FilamentEditEnvPlugin.php create mode 100644 src/FilamentEditEnvServiceProvider.php create mode 100644 src/Livewire/ChangeEnvFileComponent.php create mode 100644 src/Testing/TestsFilamentEditEnv.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..c9b14f1 --- /dev/null +++ b/.github/FUNDING.yml @@ -0,0 +1 @@ +github: joaopaulolndev 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..d3a7cc6 --- /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/joaopaulolndev/filament-edit-env/discussions/new?category=q-a + about: Ask the community for help + - name: Request a feature + url: https://github.com/joaopaulolndev/filament-edit-env/discussions/new?category=ideas + about: Share ideas for new features + - name: Report a security issue + url: https://github.com/joaopaulolndev/filament-edit-env/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..be1a5b4 --- /dev/null +++ b/.github/SECURITY.md @@ -0,0 +1,3 @@ +# Security Policy + +If you discover any security related issues, please email joaopauloln7@gmail.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/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..1bf1809 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,7 @@ +# Changelog + +All notable changes to `filament-edit-env` 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..0f0390a --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) joaopaulolndev + +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..6ecdaa9 --- /dev/null +++ b/README.md @@ -0,0 +1,78 @@ +# Package to edit env file + +[![Latest Version on Packagist](https://img.shields.io/packagist/v/joaopaulolndev/filament-edit-env.svg?style=flat-square)](https://packagist.org/packages/joaopaulolndev/filament-edit-env) +[![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/joaopaulolndev/filament-edit-env/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/joaopaulolndev/filament-edit-env/actions?query=workflow%3Arun-tests+branch%3Amain) +[![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/joaopaulolndev/filament-edit-env/fix-php-code-styling.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/joaopaulolndev/filament-edit-env/actions?query=workflow%3A"Fix+PHP+code+styling"+branch%3Amain) +[![Total Downloads](https://img.shields.io/packagist/dt/joaopaulolndev/filament-edit-env.svg?style=flat-square)](https://packagist.org/packages/joaopaulolndev/filament-edit-env) + + + +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 joaopaulolndev/filament-edit-env +``` + +You can publish and run the migrations with: + +```bash +php artisan vendor:publish --tag="filament-edit-env-migrations" +php artisan migrate +``` + +You can publish the config file with: + +```bash +php artisan vendor:publish --tag="filament-edit-env-config" +``` + +Optionally, you can publish the views using + +```bash +php artisan vendor:publish --tag="filament-edit-env-views" +``` + +This is the contents of the published config file: + +```php +return [ +]; +``` + +## Usage + +```php +$filamentEditEnv = new Joaopaulolndev\FilamentEditEnv(); +echo $filamentEditEnv->echoPhrase('Hello, Joaopaulolndev!'); +``` + +## 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 + +- [João Paulo Leite Nascimento](https://github.com/joaopaulolndev) +- [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..7e9326e --- /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/filament-edit-env.js', +}) diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..cd048c7 --- /dev/null +++ b/composer.json @@ -0,0 +1,71 @@ +{ + "name": "joaopaulolndev/filament-edit-env", + "description": "Package to edit env file", + "keywords": [ + "joaopaulolndev", + "laravel", + "filament-edit-env" + ], + "homepage": "https://github.com/joaopaulolndev/filament-edit-env", + "support": { + "issues": "https://github.com/joaopaulolndev/filament-edit-env/issues", + "source": "https://github.com/joaopaulolndev/filament-edit-env" + }, + "license": "MIT", + "authors": [ + { + "name": "João Paulo Leite Nascimento", + "email": "joaopauloln7@gmail.com", + "role": "Developer" + } + ], + "require": { + "php": "^8.1", + "filament/filament": "^3.0", + "spatie/laravel-package-tools": "^1.15.0" + }, + "require-dev": { + "laravel/pint": "^1.0", + "nunomaduro/collision": "^7.9", + "orchestra/testbench": "^8.0", + "pestphp/pest": "^2.1", + "pestphp/pest-plugin-arch": "^2.0", + "pestphp/pest-plugin-laravel": "^2.0" + }, + "autoload": { + "psr-4": { + "Joaopaulolndev\\FilamentEditEnv\\": "src/", + "Joaopaulolndev\\FilamentEditEnv\\Database\\Factories\\": "database/factories/" + } + }, + "autoload-dev": { + "psr-4": { + "Joaopaulolndev\\FilamentEditEnv\\Tests\\": "tests/" + } + }, + "scripts": { + "post-autoload-dump": "@php ./vendor/bin/testbench package:discover --ansi", + "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": [ + "Joaopaulolndev\\FilamentEditEnv\\FilamentEditEnvServiceProvider" + ], + "aliases": { + "FilamentEditEnv": "Joaopaulolndev\\FilamentEditEnv\\Facades\\FilamentEditEnv" + } + } + }, + "minimum-stability": "dev", + "prefer-stable": true +} \ No newline at end of file diff --git a/config/edit-env.php b/config/edit-env.php new file mode 100644 index 0000000..7d49605 --- /dev/null +++ b/config/edit-env.php @@ -0,0 +1,6 @@ +id(); + + // add fields + + $table->timestamps(); + }); + } +}; diff --git a/package.json b/package.json new file mode 100644 index 0000000..640dd3f --- /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/filament-edit-env.css --postcss --watch", + "dev:scripts": "node bin/build.js --dev", + "build:styles": "npx tailwindcss -i resources/css/index.css -o resources/dist/filament-edit-env.css --postcss --minify && npm run purge", + "build:scripts": "node bin/build.js", + "purge": "filament-purge -i resources/dist/filament-edit-env.css -o resources/dist/filament-edit-env.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/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..cd7c25f --- /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/dist/filament-edit-env.css b/resources/dist/filament-edit-env.css new file mode 100644 index 0000000..e69de29 diff --git a/resources/dist/filament-edit-env.js b/resources/dist/filament-edit-env.js 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/edit-env.php b/resources/lang/en/edit-env.php new file mode 100644 index 0000000..7edeeab --- /dev/null +++ b/resources/lang/en/edit-env.php @@ -0,0 +1,6 @@ + + {{$this->editAction()}} + + + diff --git a/src/Commands/FilamentEditEnvCommand.php b/src/Commands/FilamentEditEnvCommand.php new file mode 100644 index 0000000..ca9609c --- /dev/null +++ b/src/Commands/FilamentEditEnvCommand.php @@ -0,0 +1,19 @@ +comment('All done'); + + return self::SUCCESS; + } +} diff --git a/src/Facades/FilamentEditEnv.php b/src/Facades/FilamentEditEnv.php new file mode 100644 index 0000000..668dea1 --- /dev/null +++ b/src/Facades/FilamentEditEnv.php @@ -0,0 +1,16 @@ +evaluate($this->showButton)) { + return ''; + } + + return Blade::render('@livewire(\'change-env-file\')'); + } + ); + } + + public static function make(): static + { + $plugin = app(static::class); + + $plugin->showButton(fn () => match (app()->environment()) { + 'production', 'prod' => false, + default => true, + }); + + return $plugin; + } + + public static function get(): static + { + /** @var static $plugin */ + $plugin = filament(app(static::class)->getId()); + + return $plugin; + } + + public function showButton(bool | Closure $showButton = true): static + { + $this->showButton = $showButton; + + return $this; + } +} diff --git a/src/FilamentEditEnvServiceProvider.php b/src/FilamentEditEnvServiceProvider.php new file mode 100644 index 0000000..076e35d --- /dev/null +++ b/src/FilamentEditEnvServiceProvider.php @@ -0,0 +1,154 @@ +name(static::$name) + ->hasCommands($this->getCommands()) + ->hasInstallCommand(function (InstallCommand $command) { + $command + ->publishConfigFile() + ->publishMigrations() + ->askToRunMigrations() + ->askToStarRepoOnGitHub('joaopaulolndev/filament-edit-env'); + }); + + $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/filament-edit-env/{$file->getFilename()}"), + ], 'filament-edit-env-stubs'); + } + } + + // Testing + Testable::mixin(new TestsFilamentEditEnv()); + } + + protected function getAssetPackageName(): ?string + { + return 'joaopaulolndev/filament-edit-env'; + } + + /** + * @return array + */ + protected function getAssets(): array + { + return [ + // AlpineComponent::make('filament-edit-env', __DIR__ . '/../resources/dist/components/filament-edit-env.js'), + Css::make('filament-edit-env-styles', __DIR__ . '/../resources/dist/filament-edit-env.css'), + Js::make('filament-edit-env-scripts', __DIR__ . '/../resources/dist/filament-edit-env.js'), + ]; + } + + /** + * @return array + */ + protected function getCommands(): array + { + return [ + FilamentEditEnvCommand::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_filament-edit-env_table', + ]; + } +} diff --git a/src/Livewire/ChangeEnvFileComponent.php b/src/Livewire/ChangeEnvFileComponent.php new file mode 100644 index 0000000..361229b --- /dev/null +++ b/src/Livewire/ChangeEnvFileComponent.php @@ -0,0 +1,50 @@ +icon('heroicon-o-command-line') + ->iconButton() + ->modalHeading(__('Change env file')) + ->modalWidth('lg') + ->form([ + Textarea::make('envFile') + ->required() + ->default(file_get_contents(base_path('.env'))) + ->autofocus(), + ]) + ->action(function (array $data) { + dd($data); + }); + } + + public function saveEnvFileAction() + { + file_put_contents(base_path('.env'), $this->envFile); + + $this->notify(Notification::make(__('Env file saved successfully!'))); + } + + public function render() + { + return view('filament-edit-env::livewire.change-env-file-component'); + } +} diff --git a/src/Testing/TestsFilamentEditEnv.php b/src/Testing/TestsFilamentEditEnv.php new file mode 100644 index 0000000..5ee1962 --- /dev/null +++ b/src/Testing/TestsFilamentEditEnv.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..a8dbbb7 --- /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..a9d3fc3 --- /dev/null +++ b/tests/TestCase.php @@ -0,0 +1,60 @@ + 'Joaopaulolndev\\FilamentEditEnv\\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, + FilamentEditEnvServiceProvider::class, + ]; + } + + public function getEnvironmentSetUp($app) + { + config()->set('database.default', 'testing'); + + /* + $migration = include __DIR__.'/../database/migrations/create_filament-edit-env_table.php.stub'; + $migration->up(); + */ + } +}