Repository: configuredco/haulable
Branch: main
Commit: a8526c260d7b
Files: 26
Total size: 17.2 MB
Directory structure:
gitextract_gek_81al/
├── .editorconfig
├── .gitattributes
├── .gitignore
├── LICENSE
├── README.md
├── app/
│ ├── Commands/
│ │ ├── .gitkeep
│ │ └── Package.php
│ ├── Enums/
│ │ └── Platform.php
│ └── Providers/
│ └── AppServiceProvider.php
├── bootstrap/
│ └── app.php
├── box.json
├── builds/
│ └── haulable
├── composer.json
├── config/
│ ├── app.php
│ ├── commands.php
│ ├── filesystems.php
│ └── view.php
├── haulable
├── phpunit.xml.dist
├── pint.json
├── resources/
│ └── views/
│ ├── error.blade.php
│ ├── intro.blade.php
│ └── packaging-successful.blade.php
└── tests/
├── CreatesApplication.php
├── Pest.php
└── TestCase.php
================================================
FILE CONTENTS
================================================
================================================
FILE: .editorconfig
================================================
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
[*.md]
trim_trailing_whitespace = false
[*.yml]
indent_style = space
indent_size = 2
================================================
FILE: .gitattributes
================================================
* text=auto eol=lf
/.github export-ignore
.scrutinizer.yml export-ignore
BACKERS.md export-ignore
CONTRIBUTING.md export-ignore
CHANGELOG.md export-ignore
================================================
FILE: .gitignore
================================================
/vendor
/.idea
/.vscode
/.vagrant
.phpunit.result.cache
macos_intel
macos_apple
linux_x86_64
linux_aarch64
windows_x64
================================================
FILE: LICENSE
================================================
MIT License
Copyright (c) 2023 Joe Campo
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.
================================================
FILE: README.md
================================================

Haulable is a CLI tool that packages your existing PHP CLI Phar with [PHP Micro CLI](https://github.com/dixyes/phpmicro) for MacOS (Apple/Intel), Linux, and Windows. This enables your existing PHP CLI app built with something like [Laravel Zero](https://github.com/laravel-zero/laravel-zero) to be truly portable as the end user will no longer need PHP to be installed to run your application.
### Requirements
* Haulable currently only runs on MacOS/Linux; however, it will package your CLI for Windows.
* Your CLI application must be built using PHP8.0+
### Installation
To install Haulable, you can use `composer` to install globally, or you can use the Phar directly by downloading the latest build.
```bash
composer global require configured/haulable
```
### Usage
To use Haulable, once installed, you can simply run `haulable your_cli_app.phar`. Haulable will then ask you for what target system(s) you'd like to package your CLI app for.

#### Options
Haulable accepts options and arguments to make it easier to use in CI pipelines
##### Platform
An option can be one of the following:
* All Platforms
* MacOS (Intel)
* MacOS (Apple)
* Linux (x86_64)
* Linux (aarch64)
* Windows (x64)
```bash
haulable your_cli_app.phar --platform=""
```
## License
Haulable is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
================================================
FILE: app/Commands/.gitkeep
================================================
================================================
FILE: app/Commands/Package.php
================================================
argument('phar'))) {
$this->error('The path to the PHAR could not be found.');
exit();
}
$this->setupProgress();
render(view('intro', ['version' => app('git.version')]));
$this->determinePlatform();
match ($this->platform) {
Platform::ALL_PLATFORMS => $this->packageForAllPlatforms(),
null => $this->error('The specified --platform option is invalid.'),
default => $this->package($this->platform)
};
}
private function determinePlatform(): void
{
if (! $choice = $this->option('platform')) {
$choice = $this->choice('Create for which platform?', array_column(Platform::cases(), 'value'));
}
$this->platform = Platform::tryFrom($choice);
}
private function packageForAllPlatforms(): void
{
collect(Platform::cases())->skip(1)->each(fn (Platform $platform) => $this->package($platform));
}
private function package(Platform $platform, string $phpVersion = null): void
{
$sfx = $this->downloadSfx($platform, $phpVersion);
$dir = getcwd().'/'.str($platform->value)->lower()->replace(['(', ')'], '')->replace(' ', '_')->value;
$buildName = basename($this->argument('phar'));
$fileExtension = $platform === Platform::WINDOWS ? '.exe' : '';
if (! File::isDirectory($dir)) {
File::makeDirectory($dir);
}
$result = Process::run("cat {$sfx} {$this->argument('phar')} > {$dir}/{$buildName}{$fileExtension}");
match (true) {
$result->successful() => render(
view('packaging-successful', [
'platform' => $platform,
'dir' => $dir,
'buildName' => $buildName,
'fileExtension' => $fileExtension,
])
),
default => render(view('error'))
};
}
private function downloadSfx(Platform $platform, string $phpVersion = null): string
{
$filename = $this->sfxFilename($platform, $phpVersion);
if (Storage::exists($filename)) {
return Storage::path($filename);
}
render('💾 Downloading PHP Micro CLI for '.$platform->value);
$context = stream_context_create([], [
'notification' => function ($code, $severity, $message, $messageCode, $bytesTransferred, $bytesMax) {
match ($code) {
STREAM_NOTIFY_FILE_SIZE_IS => $this->progress->start($bytesMax),
STREAM_NOTIFY_PROGRESS => $this->progress->setProgress($bytesTransferred),
default => null
};
},
]);
$file = file_get_contents(self::STORAGE_URL.$filename, false, $context);
Storage::put($filename, $file);
$this->progress->finish();
render(PHP_EOL);
return Storage::path($filename);
}
private function sfxFilename(Platform $platform, string $phpVersion = null): ?string
{
$phpVersion ??= $this->phpVersion();
return match ([$platform, $phpVersion]) {
[Platform::MACOS_INTEL, '8.0'] => 'micro-cli_8.0_macos_intel.sfx',
[Platform::MACOS_APPLE, '8.0'] => 'micro-cli_8.0_macos_apple.sfx',
[Platform::LINUX, '8.0'] => 'micro-cli_8.0_linux_x86_64.sfx',
[Platform::LINUX_ARM, '8.0'] => 'micro-cli_8.0_linux_aarch64.sfx',
[Platform::WINDOWS, '8.0'] => 'micro-cli_8.0_windows_x64.sfx',
[Platform::MACOS_INTEL, '8.1'] => 'micro-cli_8.1_macos_intel.sfx',
[Platform::MACOS_APPLE, '8.1'] => 'micro-cli_8.1_macos_apple.sfx',
[Platform::LINUX, '8.1'] => 'micro-cli_8.1_linux_x86_64.sfx',
[Platform::LINUX_ARM, '8.1'] => 'micro-cli_8.1_linux_aarch64.sfx',
[Platform::WINDOWS, '8.1'] => 'micro-cli_8.1_windows_x64.sfx',
[Platform::MACOS_INTEL, '8.2'] => 'micro-cli_8.2_macos_intel.sfx',
[Platform::MACOS_APPLE, '8.2'] => 'micro-cli_8.2_macos_apple.sfx',
[Platform::LINUX, '8.2'] => 'micro-cli_8.2_linux_x86_64.sfx',
[Platform::LINUX_ARM, '8.2'] => 'micro-cli_8.2_linux_aarch64.sfx',
[Platform::WINDOWS, '8.2'] => 'micro-cli_8.2_windows_x64.sfx',
default => $this->throwInvalidPhpVersion($phpVersion)
};
}
private function phpVersion(): string
{
return $this->option('php') ?? str(phpversion())->beforeLast('.')->value();
}
private function setupProgress(): void
{
$this->progress = $this->output->createProgressBar();
$this->progress->setFormat('[%bar%] %percent%%');
}
private function throwInvalidPhpVersion(string $phpVersion): void
{
$this->error("The needed PHP Micro version could not be found for your PHP version ({$phpVersion}).");
exit();
}
}
================================================
FILE: app/Enums/Platform.php
================================================
singleton(
Illuminate\Contracts\Console\Kernel::class,
LaravelZero\Framework\Kernel::class
);
$app->singleton(
Illuminate\Contracts\Debug\ExceptionHandler::class,
Illuminate\Foundation\Exceptions\Handler::class
);
/*
|--------------------------------------------------------------------------
| Return The Application
|--------------------------------------------------------------------------
|
| This script returns the application instance. The instance is given to
| the calling script so we can separate the building of the instances
| from the actual running of the application and sending responses.
|
*/
return $app;
================================================
FILE: box.json
================================================
{
"chmod": "0755",
"directories": [
"app",
"bootstrap",
"config",
"vendor",
"resources"
],
"files": [
"composer.json"
],
"exclude-dev-files": false,
"exclude-composer-files": false,
"compression": "GZ",
"compactors": [
"KevinGH\\Box\\Compactor\\Php",
"KevinGH\\Box\\Compactor\\Json"
]
}
================================================
FILE: builds/haulable
================================================
[File too large to display: 17.2 MB]
================================================
FILE: composer.json
================================================
{
"name": "configured/haulable",
"description": "Create standalone PHP CLI applications with PHP Micro CLI",
"keywords": ["framework", "laravel", "laravel zero", "console", "cli"],
"type": "project",
"license": "MIT",
"support": {
"issues": "https://github.com/configuredco/haulable/issues",
"source": "https://github.com/configuredco/haulable"
},
"authors": [
{
"name": "Joe Campo",
"email": "joe@configured.co"
}
],
"require": {
"php": "^8.1"
},
"require-dev": {
"laravel-zero/framework": "^10.0",
"nunomaduro/termwind": "^1.15",
"laravel/pint": "^1.5",
"mockery/mockery": "^1.5.1",
"pestphp/pest": "^1.22.3"
},
"autoload": {
"psr-4": {
"App\\": "app/",
"Database\\Factories\\": "database/factories/",
"Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Tests\\": "tests/"
}
},
"config": {
"preferred-install": "dist",
"sort-packages": true,
"optimize-autoloader": true,
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"minimum-stability": "stable",
"prefer-stable": true,
"bin": ["builds/haulable"]
}
================================================
FILE: config/app.php
================================================
'Haulable',
/*
|--------------------------------------------------------------------------
| Application Version
|--------------------------------------------------------------------------
|
| This value determines the "version" your application is currently running
| in. You may want to follow the "Semantic Versioning" - Given a version
| number MAJOR.MINOR.PATCH when an update happens: https://semver.org.
|
*/
'version' => app('git.version'),
/*
|--------------------------------------------------------------------------
| Application Environment
|--------------------------------------------------------------------------
|
| This value determines the "environment" your application is currently
| running in. This may determine how you prefer to configure various
| services the application utilizes. This can be overridden using
| the global command line "--env" option when calling commands.
|
*/
'env' => 'development',
/*
|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. We have gone
| ahead and set this to a sensible default for you out of the box.
|
*/
'timezone' => 'UTC',
/*
|--------------------------------------------------------------------------
| Autoloaded Service Providers
|--------------------------------------------------------------------------
|
| The service providers listed here will be automatically loaded on the
| request to your application. Feel free to add your own services to
| this array to grant expanded functionality to your applications.
|
*/
'providers' => [
App\Providers\AppServiceProvider::class,
],
];
================================================
FILE: config/commands.php
================================================
App\Commands\Package::class,
/*
|--------------------------------------------------------------------------
| Commands Paths
|--------------------------------------------------------------------------
|
| This value determines the "paths" that should be loaded by the console's
| kernel. Foreach "path" present on the array provided below the kernel
| will extract all "Illuminate\Console\Command" based class commands.
|
*/
'paths' => [app_path('Commands')],
/*
|--------------------------------------------------------------------------
| Added Commands
|--------------------------------------------------------------------------
|
| You may want to include a single command class without having to load an
| entire folder. Here you can specify which commands should be added to
| your list of commands. The console's kernel will try to load them.
|
*/
'add' => [
// ..
],
/*
|--------------------------------------------------------------------------
| Hidden Commands
|--------------------------------------------------------------------------
|
| Your application commands will always be visible on the application list
| of commands. But you can still make them "hidden" specifying an array
| of commands below. All "hidden" commands can still be run/executed.
|
*/
'hidden' => [
NunoMaduro\LaravelConsoleSummary\SummaryCommand::class,
Symfony\Component\Console\Command\DumpCompletionCommand::class,
Symfony\Component\Console\Command\HelpCommand::class,
Illuminate\Console\Scheduling\ScheduleRunCommand::class,
Illuminate\Console\Scheduling\ScheduleListCommand::class,
Illuminate\Console\Scheduling\ScheduleFinishCommand::class,
Illuminate\Foundation\Console\VendorPublishCommand::class,
LaravelZero\Framework\Commands\StubPublishCommand::class,
],
/*
|--------------------------------------------------------------------------
| Removed Commands
|--------------------------------------------------------------------------
|
| Do you have a service provider that loads a list of commands that
| you don't need? No problem. Laravel Zero allows you to specify
| below a list of commands that you don't to see in your app.
|
*/
'remove' => [
// ..
],
];
================================================
FILE: config/filesystems.php
================================================
'local',
'disks' => [
'local' => [
'driver' => 'local',
'root' => getenv('HOME').'/.haulable',
],
],
];
================================================
FILE: config/view.php
================================================
[
resource_path('views'),
],
'compiled' => sys_get_temp_dir().'/haulable',
];
================================================
FILE: haulable
================================================
#!/usr/bin/env php
make(Illuminate\Contracts\Console\Kernel::class);
$status = $kernel->handle(
$input = new Symfony\Component\Console\Input\ArgvInput,
new Symfony\Component\Console\Output\ConsoleOutput
);
/*
|--------------------------------------------------------------------------
| Shutdown The Application
|--------------------------------------------------------------------------
|
| Once Artisan has finished running, we will fire off the shutdown events
| so that any final work may be done by the application before we shut
| down the process. This is the last thing to happen to the request.
|
*/
$kernel->terminate($input, $status);
exit($status);
================================================
FILE: phpunit.xml.dist
================================================
./tests/Feature
./tests/Unit
./app
================================================
FILE: pint.json
================================================
{
"preset": "laravel"
}
================================================
FILE: resources/views/error.blade.php
================================================
😖 Something unexpected went wrong.
================================================
FILE: resources/views/intro.blade.php
================================================
_ _ _ _
| | | | | | | |
| | __, | | __, | | | | _
|/ \ / | | | |/ / | |/ \_|/ |/
| |_/\_/|_/ \_/|_/|__/\_/|_/\_/ |__/|__/
by ⚙️ Configured
{{ $version }}
Create portable PHP CLI applications w/ PHP Micro
================================================
FILE: resources/views/packaging-successful.blade.php
================================================
📦 Packaging for {{ $platform->value }} successful.
================================================
FILE: tests/CreatesApplication.php
================================================
make(Kernel::class)->bootstrap();
return $app;
}
}
================================================
FILE: tests/Pest.php
================================================
in('Feature');
/*
|--------------------------------------------------------------------------
| Expectations
|--------------------------------------------------------------------------
|
| When you're writing tests, you often need to check that values meet certain conditions. The
| "expect()" function gives you access to a set of "expectations" methods that you can use
| to assert different things. Of course, you may extend the Expectation API at any time.
|
*/
expect()->extend('toBeOne', function () {
return $this->toBe(1);
});
/*
|--------------------------------------------------------------------------
| Functions
|--------------------------------------------------------------------------
|
| While Pest is very powerful out-of-the-box, you may have some testing code specific to your
| project that you don't want to repeat in every file. Here you can also expose helpers as
| global functions to help you to reduce the number of lines of code in your test files.
|
*/
function something(): void
{
// ..
}
================================================
FILE: tests/TestCase.php
================================================