Skip to content

Commit

Permalink
FIX: Fix binary generation to include composer files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Minnee committed Jun 15, 2016
1 parent 4a153d1 commit 1a09260
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/SSPakFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = <<<STUB
Expand All @@ -60,6 +73,8 @@ function makeExecutable() {

$this->phar->setStub($stub);
chmod($this->path, 0775);

passthru("composer install -d " . escapeshellarg(PACKAGE_ROOT));
}

/**
Expand Down

0 comments on commit 1a09260

Please sign in to comment.