Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
TMP
Browse files Browse the repository at this point in the history
Aeliot-Tm committed Aug 21, 2024
1 parent b9e78a6 commit 456cebb
Showing 3 changed files with 35 additions and 24 deletions.
2 changes: 1 addition & 1 deletion bin/pcsf-baseline
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ $autoloaderPath = (static function (): string {
throw new RuntimeException('Cannot find autoloader');
})();

require_once $autoloaderPath;
require $autoloaderPath;

$projectPath = dirname($autoloaderPath, 2);

1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -41,6 +41,7 @@
"baseline"
],
"scripts": {
"build": "php --define phar.readonly=0 scripts/phar/create.php",
"cs-check": "@cs-fixer-check",
"cs-fix": "@cs-fixer-fix",
"cs-fixer-check": "vendor/bin/php-cs-fixer fix --dry-run",
56 changes: 33 additions & 23 deletions scripts/phar/create.php
Original file line number Diff line number Diff line change
@@ -7,40 +7,50 @@

ini_set("phar.readonly", 0);

$pharFile = __DIR__ . '/../../pcsf-baseline.phar';
$basedir = dirname(__DIR__, 2);
require_once $basedir . '/vendor/autoload.php';

$pharFile = $basedir . '/pcsf-baseline.phar';

// clean up
if (file_exists($pharFile)) {
unlink($pharFile);
}

/**
* @return iterable<\SplFileInfo>
*/
function getFiles(): iterable
{
return (new Finder())
->files()
->in([
__DIR__ . '/../../src',
__DIR__ . '/../../vendor',
])
->append([
__DIR__ . '/../../bin/pcsf-baseline',
__DIR__ . '/../../LICENSE',
__DIR__ . '/../../README.md',
]);
}
$finder = (new Finder())
->files()
->in([
$basedir . '/bin',
$basedir . '/src',
$basedir . '/vendor',
])
->append([
$basedir . '/bin/pcsf-baseline',
$basedir . '/LICENSE',
$basedir . '/README.md',
])
->filter(static function (SplFileInfo $file): bool {
return !preg_match('~/tests?/~i', $file->getRealPath());
});

// create phar
$phar = new Phar($pharFile);

// creating our library using whole directory
foreach (getFiles() as $file) {
$phar->addFile($file->getRealPath());
// start buffering. Mandatory to modify stub to add shebang
$phar->startBuffering();

//$phar->buildFromIterator($finder, $dirname);
$basedirLen = strlen($basedir);
foreach ($finder as $file) {
$realPath = $file->getRealPath();
$phar->addFile($realPath, substr($realPath, $basedirLen));
}

// pointing main file which requires all classes
$phar->setDefaultStub('bin/pcsf-baseline');

echo "$pharFile successfully created";
$phar->stopBuffering();

# Make the file executable
chmod($pharFile, 0770);

echo "$pharFile successfully created\n";

0 comments on commit 456cebb

Please sign in to comment.