yfix/packager
Laravel package to help scaffold and manage package structure with common conventions. Provides utilities for generating boilerplate files, organizing configs and service providers, and streamlining local package development and publishing.
Installation
composer require yfix/packager
Add to composer.json under require-dev if only needed for local builds:
"require-dev": {
"yfix/packager": "^1.0"
}
Basic Usage
Create a package.yml file in your project root (MooTools-style syntax):
name: my-package
version: 1.0.0
description: "A Laravel package built with Packager"
files:
- src/
- composer.json
- README.md
First Build Run the build command:
php artisan packager:build
Outputs a .zip file in storage/app/packages/ (default).
config/packager.php (if published via php artisan vendor:publish).php artisan packager:build (core command).Yfix\Packager\PackagerServiceProvider (registers commands).package.yml with your package structure.php artisan packager:build..zip for distribution (e.g., Packagist, GitHub Releases).CI/CD Pipeline
Add to .github/workflows/build.yml:
- name: Build Package
run: php artisan packager:build
Upload the generated .zip as an artifact.
Local Development
Use php artisan packager:build --watch for auto-rebuilding on file changes.
Custom Build Steps Extend the builder via events:
// In a service provider
event(new \Yfix\Packager\Events\PreBuild());
| Pattern | Example |
|---|---|
| Excluding Files | Add exclude: [node_modules/, .env] to package.yml. |
| Custom Output Path | Set in config/packager.php: 'output_path' => 'custom/path'. |
| Versioning | Use {{ version }} in filenames (e.g., my-package-{{ version }}.zip). |
| Post-Build Hooks | Listen for \Yfix\Packager\Events\PostBuild to run scripts. |
php artisan vendor:publish --provider="Yfix\Packager\PackagerServiceProvider"
Packager facade in AppServiceProvider:
$this->app->bind('packager', function ($app) {
return new \Yfix\Packager\Packager();
});
php artisan packager:build --test to validate package.yml syntax.YAML Syntax Errors
package.yml.php artisan packager:validate.File Permissions
.zip file not generated in storage/app/packages/.storage/ is writable:
chmod -R 775 storage/
Version Placeholders
{{ version }} not replaced in filenames.composer.json has a valid version field.Case Sensitivity
package.yml.files: section.Verbose Output:
php artisan packager:build -v
Dry Run:
php artisan packager:build --dry-run
Lists files to be included without creating a .zip.
Log Events:
Enable logging in config/packager.php:
'debug' => env('PACKAGER_DEBUG', false),
Custom Builders
Implement Yfix\Packager\Contracts\Builder:
class CustomBuilder implements Builder {
public function build(array $config) { ... }
}
Register via config/packager.php:
'builder' => \App\Services\CustomBuilder::class,
Pre/Post Build Events
Listen globally in EventServiceProvider:
protected $listen = [
\Yfix\Packager\Events\PreBuild::class => [
\App\Listeners\ValidatePackage::class,
],
];
Override Defaults
Extend Yfix\Packager\Packager class and bind it in AppServiceProvider:
$this->app->singleton('packager', function () {
return new \App\Services\CustomPackager();
});
storage/app/packages/. Change via:
'output_path' => storage_path('custom-packages'),
'compress' => false in config (outputs a .tar instead).tests/*) are supported but may not work as expected on all systems. Test locally.Template Files
Use package.yml templates with extends:
extends: base-package.yml
files:
- src/
(Requires custom builder implementation.)
Git Integration
Auto-generate CHANGELOG.md by hooking into PostBuild:
public function handle(PostBuild $event) {
$this->generateChangelog($event->packagePath);
}
Multi-Package Projects
Use --package flag to build specific packages:
php artisan packager:build --package="admin-panel"
(Requires named package.yml files like admin-panel.yml.)
How can I help you explore Laravel packages today?