From 1a0926062a06bd9d3f736f6aadc96367f9d4736a Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Thu, 16 Jun 2016 09:51:47 +1200 Subject: [PATCH] FIX: Fix binary generation to include composer files. --- src/SSPakFile.php | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/SSPakFile.php b/src/SSPakFile.php index 5c8a1a6..42b3c6d 100644 --- a/src/SSPakFile.php +++ b/src/SSPakFile.php @@ -12,7 +12,7 @@ function __construct($path, $executor, $pharAlias = 'sspak.phar') { $this->pharAlias = $pharAlias; $this->pharPath = $path; - + // Executable Phar version if(substr($path,-5) === '.phar') { $this->phar = new Phar($path, FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME, @@ -38,15 +38,28 @@ function makeExecutable() { throw new Exception("Please set phar.readonly to false in your php.ini."); } + passthru("composer install -d " . escapeshellarg(PACKAGE_ROOT) . " --no-dev"); + $root = PACKAGE_ROOT; - $srcRoot = PACKAGE_ROOT . 'src/'; + $srcRoots = [ + 'src/', + 'vendor/', + ]; // Add the bin file, but strip of the #! exec header. $this->phar['bin/sspak'] = preg_replace("/^#!\/usr\/bin\/env php\n/", '', file_get_contents($root . "bin/sspak")); - foreach(scandir($srcRoot) as $file) { - if($file[0] == '.') continue; - $this->phar['src/'.$file] = file_get_contents($srcRoot . $file); + foreach($srcRoots as $srcRoot) { + foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($root . $srcRoot)) as $fileObj) { + if($fileObj->isFile()) { + $file = $fileObj->getRealPath(); + + $relativeFile = str_replace($root, '', $file); + + echo "Adding $relativeFile\n"; + $this->phar[$relativeFile] = file_get_contents($file); + } + } } $stub = <<phar->setStub($stub); chmod($this->path, 0775); + + passthru("composer install -d " . escapeshellarg(PACKAGE_ROOT)); } /**