Colored output for TTYs, props added
This commit is contained in:
@ -38,7 +38,12 @@ class PharBuilder
|
||||
{
|
||||
// Create the phar
|
||||
$phar = new \Phar($this->tempFile);
|
||||
$vo = posix_isatty(STDOUT);
|
||||
|
||||
// verbatim add
|
||||
$verbatim = $this->manifest->getVerbatim();
|
||||
if ($verbatim) {
|
||||
log_debug("Note: Creating verbatim archive without minification");
|
||||
}
|
||||
|
||||
// Add files
|
||||
log_debug("Adding files to phar archive...");
|
||||
@ -48,20 +53,23 @@ class PharBuilder
|
||||
foreach ($this->files as $file) {
|
||||
$i++;
|
||||
$tp = dirname($file->src);
|
||||
if ($tp!=$lp) {
|
||||
if (($tp!=$lp) && (IS_TTY)) {
|
||||
$lp=$tp;
|
||||
printf("\r\e[K%d/%d %s", $i, $t, $tp);
|
||||
}
|
||||
if (fnmatch("*.php",$file->src)) {
|
||||
|
||||
if (fnmatch("*.php",$file->src) && (!$verbatim)) {
|
||||
$min = php_strip_whitespace($file->src);
|
||||
$size_tot += filesize($file->src);
|
||||
$size_min += strlen($min);
|
||||
$phar->addFromString($file->dest?:$file->src, $min);
|
||||
} else {
|
||||
$size_tot += filesize($file->src);
|
||||
$size_min += filesize($file->src);
|
||||
$phar->addFile($file->dest?:$file->src, $file->src);
|
||||
}
|
||||
}
|
||||
($vo) && printf("\r\e[K");
|
||||
(IS_TTY) && printf("\r\e[K");
|
||||
$phar->stopBuffering();
|
||||
|
||||
// Helper to format sizes
|
||||
@ -72,9 +80,13 @@ class PharBuilder
|
||||
};
|
||||
// Format the status
|
||||
$str_tot = $formatSize($size_tot);
|
||||
$str_min = $formatSize($size_min);
|
||||
$str_rat = sprintf("%.2f%%", 100/$str_tot*$str_min);
|
||||
log_debug("Size: %s, Minified: %s (%s)", $str_tot, $str_min, $str_rat);
|
||||
if (!$verbatim) {
|
||||
$str_min = $formatSize($size_min);
|
||||
$str_rat = sprintf("%.2f%%", 100/$str_tot*$str_min);
|
||||
log_debug("Size: %s, Minified: %s (%s)", $str_tot, $str_min, $str_rat);
|
||||
} else {
|
||||
log_debug("Size: %s", $str_tot);
|
||||
}
|
||||
|
||||
// Create stub
|
||||
if ($this->manifest->getIsLibrary()) {
|
||||
@ -82,6 +94,9 @@ class PharBuilder
|
||||
// Create library stub
|
||||
$stub = '<?php ';
|
||||
$stub.= 'require_once __DIR__."/vendor/autoload.php";';
|
||||
foreach ($this->manifest->getProps() as $k=>$v) {
|
||||
$stub.= sprintf('define(%s,%s);', var_export($k,true), var_export($v,true));
|
||||
}
|
||||
if (($stubfile = $this->manifest->getStubFile())) {
|
||||
$stub.= 'require_once __DIR__."/'.ltrim($stubfile,'/').'";';
|
||||
}
|
||||
@ -90,7 +105,11 @@ class PharBuilder
|
||||
log_debug("Creating application stub...");
|
||||
// Write application stub
|
||||
$stubfile = $this->manifest->getStubFile();
|
||||
$stub = '<?php require_once __DIR__."/'.ltrim($stubfile,'/').'";';
|
||||
$stub = '<?php ';
|
||||
foreach ($this->manifest->getProps() as $k=>$v) {
|
||||
$stub.= sprintf('define(%s,%s);', var_export($k,true), var_export($v,true));
|
||||
}
|
||||
$stub.= 'require_once __DIR__."/'.ltrim($stubfile,'/').'";';
|
||||
$phar->addFromString("index.php", $stub);
|
||||
// Make the phar stub executable
|
||||
$mainstub = $phar->createDefaultStub("index.php");
|
||||
@ -116,7 +135,7 @@ class PharBuilder
|
||||
if (file_exists($output)) {
|
||||
unlink($output);
|
||||
}
|
||||
log_debug("Writing %s", $output);
|
||||
log_info("Writing %s", $output);
|
||||
rename($this->tempFile, $output);
|
||||
|
||||
if (!$this->manifest->getIsLibrary()) {
|
||||
|
Reference in New Issue
Block a user