Remove daux.phar
This commit is contained in:
parent
0270e14121
commit
0d3e366277
17
bin/compile
17
bin/compile
@ -1,17 +0,0 @@
|
|||||||
#!/usr/bin/env php
|
|
||||||
<?php
|
|
||||||
|
|
||||||
require __DIR__.'/../vendor/autoload.php';
|
|
||||||
|
|
||||||
use Todaymade\Daux\Compiler;
|
|
||||||
|
|
||||||
error_reporting(-1);
|
|
||||||
ini_set('display_errors', 1);
|
|
||||||
|
|
||||||
try {
|
|
||||||
$compiler = new Compiler();
|
|
||||||
$compiler->compile();
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
echo 'Failed to compile phar: ['.get_class($e).'] '.$e->getMessage().' at '.$e->getFile().':'.$e->getLine();
|
|
||||||
exit(1);
|
|
||||||
}
|
|
@ -71,7 +71,7 @@ By default, it will inform you that some pages aren't needed anymore and you can
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
By setting `delete` to `true` (or running `daux.phar` with the `--delete` flag) you tell the generator that it can safely delete the pages.
|
By setting `delete` to `true` (or running `daux` with the `--delete` flag) you tell the generator that it can safely delete the pages.
|
||||||
|
|
||||||
|
|
||||||
## Information message
|
## Information message
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
The recommended way to extend Daux is through Processors.
|
The recommended way to extend Daux is through Processors.
|
||||||
|
|
||||||
The main advantage, is that you can run it with the source or with `daux.phar` independently. You don't need to hack in the core.
|
The main advantage, is that you can run it with the source or with `daux` independently. You don't need to hack in the core.
|
||||||
|
|
||||||
## Adding classes
|
## Adding classes
|
||||||
|
|
||||||
At the same level as your `daux.phar` file, you will see a `daux` directory, you can create all your classes here.
|
Next to your `docs` directory, you can create a `daux` directory that can contain your Processor.
|
||||||
|
|
||||||
The classes must respect the PSR-4 Naming convention. And have `\Todaymade\Daux\Extension` as a base namespace.
|
The classes must respect the PSR-4 Naming convention. And have `\Todaymade\Daux\Extension` as a base namespace.
|
||||||
|
|
||||||
|
@ -1,217 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This class is inspired from Composer's compiler
|
|
||||||
* @see https://github.com/composer/composer/blob/master/src/Composer/Compiler.php
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Todaymade\Daux;
|
|
||||||
|
|
||||||
use Symfony\Component\Finder\Finder;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The Compiler class compiles daux into a phar
|
|
||||||
*
|
|
||||||
* @author Fabien Potencier <fabien@symfony.com>
|
|
||||||
* @author Jordi Boggiano <j.boggiano@seld.be>
|
|
||||||
* @author Stéphane Goetz <stephane.goetz@onigoetz.ch>
|
|
||||||
*/
|
|
||||||
class Compiler
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Compiles composer into a single phar file
|
|
||||||
*
|
|
||||||
* @throws \RuntimeException
|
|
||||||
* @param string $pharFile The full path to the file to create
|
|
||||||
*/
|
|
||||||
public function compile($pharFile = 'daux.phar')
|
|
||||||
{
|
|
||||||
echo "Compiling a new $pharFile\n";
|
|
||||||
|
|
||||||
if (file_exists($pharFile)) {
|
|
||||||
echo "-> Deleting the existing phar\n";
|
|
||||||
unlink($pharFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
echo "-> Creating the new phar\n";
|
|
||||||
$phar = new \Phar($pharFile, 0, 'daux.phar');
|
|
||||||
$phar->setSignatureAlgorithm(\Phar::SHA1);
|
|
||||||
|
|
||||||
$phar->startBuffering();
|
|
||||||
|
|
||||||
// Daux
|
|
||||||
echo "-> Adding all daux files\n";
|
|
||||||
$finder = new Finder();
|
|
||||||
$finder->files()
|
|
||||||
->ignoreVCS(true)
|
|
||||||
->name('*.php')
|
|
||||||
->notName('Compiler.php')
|
|
||||||
->in(__DIR__ . '/../templates')
|
|
||||||
->in(__DIR__);
|
|
||||||
|
|
||||||
foreach ($finder as $file) {
|
|
||||||
$this->addFile($phar, $file);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Composer libraries
|
|
||||||
echo "-> Adding all composer dependencies\n";
|
|
||||||
$finder = new Finder();
|
|
||||||
$finder->files()
|
|
||||||
->ignoreVCS(true)
|
|
||||||
->exclude('Tests')
|
|
||||||
->notName('*.png')
|
|
||||||
->in(__DIR__ . '/../vendor/guzzlehttp/guzzle/src')
|
|
||||||
->in(__DIR__ . '/../vendor/guzzlehttp/promises/src')
|
|
||||||
->in(__DIR__ . '/../vendor/guzzlehttp/psr7/src')
|
|
||||||
->in(__DIR__ . '/../vendor/league/commonmark/src')
|
|
||||||
->in(__DIR__ . '/../vendor/league/plates/src')
|
|
||||||
->in(__DIR__ . '/../vendor/myclabs/deep-copy')
|
|
||||||
->in(__DIR__ . '/../vendor/psr/http-message/src')
|
|
||||||
->in(__DIR__ . '/../vendor/symfony/console')
|
|
||||||
->in(__DIR__ . '/../vendor/symfony/polyfill-mbstring')
|
|
||||||
->in(__DIR__ . '/../vendor/symfony/process')
|
|
||||||
->in(__DIR__ . '/../vendor/symfony/process')
|
|
||||||
->in(__DIR__ . '/../vendor/symfony/yaml')
|
|
||||||
->in(__DIR__ . '/../vendor/webuni/front-matter/src')
|
|
||||||
->in(__DIR__ . '/../vendor/webuni/commonmark-table-extension/src');
|
|
||||||
|
|
||||||
$excluded_files = [
|
|
||||||
'README.md',
|
|
||||||
'composer.json',
|
|
||||||
'LICENSE',
|
|
||||||
'CHANGELOG.md',
|
|
||||||
'phpunit.xml.dist',
|
|
||||||
];
|
|
||||||
|
|
||||||
/** @var \SplFileInfo $file */
|
|
||||||
$count = 0;
|
|
||||||
foreach ($finder as $file) {
|
|
||||||
if (in_array($file->getFilename(), $excluded_files)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$count++;
|
|
||||||
$this->addFile($phar, $file);
|
|
||||||
}
|
|
||||||
echo " Imported $count files\n";
|
|
||||||
|
|
||||||
// Composer autoload
|
|
||||||
echo "-> Adding the composer autoloader\n";
|
|
||||||
$this->addComposer($phar);
|
|
||||||
|
|
||||||
echo "-> Adding the main binary\n";
|
|
||||||
$this->addBinary($phar);
|
|
||||||
|
|
||||||
echo "-> Writing the stub\n";
|
|
||||||
$phar->setStub($this->getStub());
|
|
||||||
|
|
||||||
$phar->stopBuffering();
|
|
||||||
|
|
||||||
echo "-> Writing the licence\n";
|
|
||||||
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../LICENSE'), false);
|
|
||||||
|
|
||||||
chmod($pharFile, 0775);
|
|
||||||
|
|
||||||
unset($phar);
|
|
||||||
|
|
||||||
echo "Done.\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addFile($phar, $file, $strip = true)
|
|
||||||
{
|
|
||||||
$path = strtr(str_replace(dirname(__DIR__) . DIRECTORY_SEPARATOR, '', $file->getRealPath()), '\\', '/');
|
|
||||||
|
|
||||||
$content = file_get_contents($file);
|
|
||||||
if ($strip) {
|
|
||||||
$content = $this->stripWhitespace($content);
|
|
||||||
} elseif ('LICENSE' === basename($file)) {
|
|
||||||
$content = "\n" . $content . "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
$phar->addFromString($path, $content);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addComposer($phar)
|
|
||||||
{
|
|
||||||
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/autoload.php'));
|
|
||||||
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/composer/autoload_classmap.php'));
|
|
||||||
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/composer/autoload_files.php'));
|
|
||||||
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/composer/autoload_namespaces.php'));
|
|
||||||
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/composer/autoload_real.php'));
|
|
||||||
$this->addFile($phar, new \SplFileInfo(__DIR__ . '/../vendor/composer/ClassLoader.php'));
|
|
||||||
|
|
||||||
if (file_exists(__DIR__ . '/../vendor/composer/autoload_static.php')) {
|
|
||||||
$content = file_get_contents(__DIR__ . '/../vendor/composer/autoload_static.php');
|
|
||||||
$content = str_replace('__DIR__ . \'/../..\' . \'/daux\'', 'PHAR_DIR . \'/daux\'', $content);
|
|
||||||
$phar->addFromString('vendor/composer/autoload_static.php', $content);
|
|
||||||
}
|
|
||||||
|
|
||||||
$content = file_get_contents(__DIR__ . '/../vendor/composer/autoload_psr4.php');
|
|
||||||
$content = str_replace('$baseDir . \'/daux\'', 'PHAR_DIR . \'/daux\'', $content);
|
|
||||||
$phar->addFromString('vendor/composer/autoload_psr4.php', $content);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function addBinary($phar)
|
|
||||||
{
|
|
||||||
$content = file_get_contents(__DIR__ . '/../bin/daux');
|
|
||||||
$content = preg_replace('{^#!/usr/bin/env php\s*}', '', $content);
|
|
||||||
$phar->addFromString('bin/daux', $content);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Removes whitespace from a PHP source string while preserving line numbers.
|
|
||||||
*
|
|
||||||
* @param string $source A PHP string
|
|
||||||
* @return string The PHP string with the whitespace removed
|
|
||||||
*/
|
|
||||||
private function stripWhitespace($source)
|
|
||||||
{
|
|
||||||
if (!function_exists('token_get_all')) {
|
|
||||||
return $source;
|
|
||||||
}
|
|
||||||
|
|
||||||
$output = '';
|
|
||||||
foreach (token_get_all($source) as $token) {
|
|
||||||
if (is_string($token)) {
|
|
||||||
$output .= $token;
|
|
||||||
} elseif (in_array($token[0], [T_COMMENT, T_DOC_COMMENT])) {
|
|
||||||
$output .= str_repeat("\n", substr_count($token[1], "\n"));
|
|
||||||
} elseif (T_WHITESPACE === $token[0]) {
|
|
||||||
// reduce wide spaces
|
|
||||||
$whitespace = preg_replace('{[ \t]+}', ' ', $token[1]);
|
|
||||||
// normalize newlines to \n
|
|
||||||
$whitespace = preg_replace('{(?:\r\n|\r|\n)}', "\n", $whitespace);
|
|
||||||
// trim leading spaces
|
|
||||||
$whitespace = preg_replace('{\n +}', "\n", $whitespace);
|
|
||||||
$output .= $whitespace;
|
|
||||||
} else {
|
|
||||||
$output .= $token[1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $output;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getStub()
|
|
||||||
{
|
|
||||||
return <<<'EOF'
|
|
||||||
#!/usr/bin/env php
|
|
||||||
<?php
|
|
||||||
/*
|
|
||||||
* This file is part of Daux.
|
|
||||||
*
|
|
||||||
* (c) Stéphane Goetz <onigoetz@onigoetz.ch>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view
|
|
||||||
* the license that is located at the bottom of this file.
|
|
||||||
*/
|
|
||||||
|
|
||||||
define('PHAR_DIR', dirname(__FILE__));
|
|
||||||
|
|
||||||
Phar::mapPhar('daux.phar');
|
|
||||||
|
|
||||||
require 'phar://daux.phar/bin/daux';
|
|
||||||
|
|
||||||
__HALT_COMPILER();
|
|
||||||
EOF;
|
|
||||||
}
|
|
||||||
}
|
|
@ -15,14 +15,10 @@ class Template
|
|||||||
*/
|
*/
|
||||||
public function __construct($base, $theme)
|
public function __construct($base, $theme)
|
||||||
{
|
{
|
||||||
// Use internal templates or the ones in the phar
|
// Use internal templates if no templates
|
||||||
// archive if no templates dir exists in the working directory
|
// dir exists in the working directory
|
||||||
if (!is_dir($base)) {
|
if (!is_dir($base)) {
|
||||||
if (is_dir(__DIR__ . '/../../../templates')) {
|
$base = __DIR__ . '/../../../templates';
|
||||||
$base = __DIR__ . '/../../../templates';
|
|
||||||
} else {
|
|
||||||
$base = 'phar://daux.phar/templates';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create new Plates instance
|
// Create new Plates instance
|
||||||
|
@ -11,14 +11,7 @@ function loadApp() {
|
|||||||
return require_once __DIR__ . '/../vendor/autoload.php';
|
return require_once __DIR__ . '/../vendor/autoload.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Loaded in the project itself, when vendor isn't installed
|
throw new Exception('Impossible to load Daux, missing vendor/');
|
||||||
if (file_exists(__DIR__ . '/../daux.phar')) {
|
|
||||||
define('PHAR_DIR', __DIR__ . '/..');
|
|
||||||
|
|
||||||
return require_once 'phar://' . __DIR__ . '/../daux.phar/vendor/autoload.php';
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new Exception('Impossible to load Daux, missing vendor/ or daux.phar');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$loader = loadApp();
|
$loader = loadApp();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user