-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 409eb6f
Showing
19 changed files
with
11,894 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.DS_Store | ||
/vendor | ||
/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
// Prefer adding customizations to pint.json unless adding custom fixers | ||
|
||
use PhpCsFixer\Config; | ||
use PhpCsFixer\Finder; | ||
|
||
$finder = Finder::create() | ||
->in([ | ||
__DIR__ . '/src', | ||
// __DIR__ . '/config', | ||
__DIR__ . '/tests', | ||
]) | ||
->name('*.php') | ||
->notName('*.blade.php') | ||
->ignoreDotFiles(true) | ||
->ignoreVCS(true); | ||
|
||
return (new Config) | ||
->setFinder($finder) | ||
->setRules([]) | ||
->setRiskyAllowed(true) | ||
->setUsingCache(false); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<?xml version="1.0"?> | ||
<ruleset name="Gedachtegoed"> | ||
<description>Gedachtegoed PHP CS rules for PHP packages</description> | ||
|
||
<file>src</file> | ||
<file>config</file> | ||
<file>tests</file> | ||
|
||
<description>Gedachtegoed PHP CS rules for PHP packages</description> | ||
|
||
<!-- Ignore normal Laravel files and folders --> | ||
<exclude-pattern>*/cache/*</exclude-pattern> | ||
<exclude-pattern>*/*.js</exclude-pattern> | ||
<exclude-pattern>*/*.css</exclude-pattern> | ||
<exclude-pattern>*/*.xml</exclude-pattern> | ||
<exclude-pattern>*/*.blade.php</exclude-pattern> | ||
<exclude-pattern>*/autoload.php</exclude-pattern> | ||
<exclude-pattern>*/storage/*</exclude-pattern> | ||
<exclude-pattern>*/docs/*</exclude-pattern> | ||
<exclude-pattern>*/vendor/*</exclude-pattern> | ||
<exclude-pattern>*/migrations/*</exclude-pattern> | ||
<exclude-pattern>*/tests/*</exclude-pattern> | ||
|
||
<!-- Hard-code command-line parameters --> | ||
<arg name="colors"/> | ||
<arg value="p"/> | ||
|
||
<!-- PSR1 2.3 Side Effects --> | ||
<rule ref="PSR1.Files.SideEffects"> | ||
<!-- Disable side effects for index file --> | ||
<exclude-pattern>/public/index.php</exclude-pattern> | ||
<!-- Disable side effects for tests (Pest) --> | ||
<exclude-pattern>/tests</exclude-pattern> | ||
</rule> | ||
|
||
<!-- PSR1 3 Namespaces and classes MUST follow PSR-0. --> | ||
<rule ref="PSR1.Classes.ClassDeclaration"/> | ||
|
||
<!-- Disable missing namespace rule for tests and database files --> | ||
<rule ref="PSR1.Classes.ClassDeclaration.MissingNamespace"> | ||
<exclude-pattern>*/database/*</exclude-pattern> | ||
<exclude-pattern>*/tests/*</exclude-pattern> | ||
</rule> | ||
|
||
<!-- PSR1 3 Class names MUST be declared in StudlyCaps. --> | ||
<rule ref="Squiz.Classes.ValidClassName"/> | ||
|
||
<!-- PSR1 4.1 Class constants MUST be declared in all upper case with underscore separators. --> | ||
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/> | ||
|
||
<!-- PSR1 4.3 Method names MUST be declared in camelCase(). --> | ||
<rule ref="PSR1.Methods.CamelCapsMethodName"/> | ||
|
||
<!-- Disable camel caps rule for tests --> | ||
<rule ref="PSR1.Methods.CamelCapsMethodName.NotCamelCaps"> | ||
<exclude-pattern>*/tests/*</exclude-pattern> | ||
</rule> | ||
|
||
<!-- No compact() and no 'dumps' --> | ||
<rule ref="Generic.PHP.ForbiddenFunctions"> | ||
<properties> | ||
<property name="forbiddenFunctions" type="array"> | ||
<element key="compact" value="null"/> | ||
<element key="dd" value="null"/> | ||
<element key="dump" value="null"/> | ||
<element key="var_dump" value="null"/> | ||
<element key="ray" value="null"/> | ||
</property> | ||
</properties> | ||
</rule> | ||
|
||
<rule ref="Generic.PHP.ForbiddenFunctions"> | ||
<exclude-pattern>/config/*</exclude-pattern> | ||
<properties> | ||
<property name="forbiddenFunctions" type="array"> | ||
<element key="env" value="null"/> | ||
</property> | ||
</properties> | ||
</rule> | ||
|
||
<!-- Class name should match the file name --> | ||
<rule ref="Squiz.Classes.ClassFileName"/> | ||
|
||
</ruleset> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) [2024] [Gerrit Willem Leuverink] | ||
|
||
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Auto inject package assets | ||
|
||
[![codestyle](https://github.com/gwleuverink/inject-assets/actions/workflows/codestyle.yml/badge.svg)](https://github.com/gwleuverink/inject-assets/actions/workflows/codestyle.yml) | ||
[![tests](https://github.com/gwleuverink/inject-assets/actions/workflows/tests.yml/badge.svg)](https://github.com/gwleuverink/inject-assets/actions/workflows/tests.yml) | ||
|
||
No need to ask you package user to manually include any scripts or styles. Automatically inject them in the response instead 🚀 | ||
|
||
## Installation | ||
|
||
```bash | ||
composer require leuverink/inject-assets | ||
``` | ||
|
||
## Usage | ||
|
||
After installing, you need to bind a concrete implementation to the AssetInjector interface in your packages Service Provider. | ||
|
||
```php | ||
namespace YourPackage; | ||
|
||
use Illuminate\Support\ServiceProvider as BaseServiceProvider; | ||
use Leuverink\InjectAssets\Contracts\AssetInjector; | ||
|
||
class ServiceProvider extends BaseServiceProvider | ||
{ | ||
public function register() | ||
{ | ||
$this->app->bind( | ||
AssetInjector::class, | ||
fn() => new \YourPackage\InjectAssets | ||
); | ||
} | ||
} | ||
``` | ||
|
||
And ofcource implement that class. | ||
|
||
```php | ||
namespace YourPackage; | ||
|
||
use Leuverink\InjectAssets\Contracts\AssetInjector; | ||
|
||
|
||
class InjectAssets implements AssetInjector | ||
{ | ||
// Used to determine if assets were already injected in the response | ||
public string $identifier = 'MY_PACKAGE'; | ||
|
||
// Will inject return value in head tag or befor html close if no head is present | ||
public function inject(): string | ||
{ | ||
$js = file_get_contents(__DIR__ . '/../build/my-package.js'); | ||
$css = file_get_contents(__DIR__ . '/../build/my-package.css'); | ||
|
||
return <<< HTML | ||
<script type="module">{$js}</script> | ||
<style>{$css}</style> | ||
HTML; | ||
} | ||
} | ||
``` | ||
|
||
This serves as an example. You may return any string you like from the `inject` method. | ||
|
||
## Configuration | ||
|
||
## Development | ||
|
||
```bash | ||
composer lint # run all linters | ||
composer fix # run all fixers | ||
|
||
composer analyze # run static analysis | ||
composer baseline # generate static analysis baseline | ||
|
||
composer test # run test suite | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
{ | ||
"name": "leuverink/inject-assets", | ||
"description": "Automatically inject your package assets onto the page", | ||
"type": "library", | ||
"license": "MIT", | ||
"autoload": { | ||
"psr-4": { | ||
"Leuverink\\InjectAssets\\": "src/", | ||
"Tests\\": "tests/" | ||
} | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "gwleuverink", | ||
"email": "willem@leuver.ink" | ||
} | ||
], | ||
"minimum-stability": "stable", | ||
"require": { | ||
"php": "^8.1", | ||
"illuminate/contracts": "^10|^11", | ||
"illuminate/support": "^10|^11" | ||
}, | ||
"require-dev": { | ||
"friendsofphp/php-cs-fixer": "^3", | ||
"laravel/pint": "^1", | ||
"larastan/larastan": "^2.9", | ||
"squizlabs/php_codesniffer": "^3", | ||
"tightenco/duster": "^3", | ||
"tightenco/tlint": "^9", | ||
"orchestra/testbench": "^9", | ||
"pestphp/pest": "^2.35" | ||
}, | ||
"extra": { | ||
"laravel": { | ||
"providers": [ | ||
"Leuverink\\InjectAssets\\ServiceProvider" | ||
] | ||
} | ||
}, | ||
"scripts": { | ||
"lint": "vendor/bin/duster lint", | ||
"fix": "vendor/bin/duster fix", | ||
"analyze": "vendor/bin/phpstan analyse", | ||
"baseline": "vendor/bin/phpstan analyse --generate-baseline", | ||
|
||
"test": "@php vendor/bin/pest --bail" | ||
}, | ||
"config": { | ||
"allow-plugins": { | ||
"pestphp/pest-plugin": true | ||
} | ||
} | ||
} |
Oops, something went wrong.