Add the daux --serve command to simplify writing documentation and reading.
This commit is contained in:
parent
b090571e4b
commit
ec775de695
9
bin/daux
9
bin/daux
@ -64,14 +64,7 @@ software, even if advised of the possibility of such damage.
|
||||
|
||||
*/
|
||||
|
||||
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
|
||||
require_once(__DIR__ . '/../vendor/autoload.php');
|
||||
} elseif (file_exists(__DIR__ . '/../daux.phar')) {
|
||||
define('PHAR_DIR', __DIR__ . '/..');
|
||||
require_once("phar://" . __DIR__ . "/../daux.phar/vendor/autoload.php");
|
||||
} else {
|
||||
throw new Exception("Impossible to load Daux, missing vendor/ or daux.phar");
|
||||
}
|
||||
require_once(__DIR__ . '/../libs/bootstrap.php');
|
||||
|
||||
$application = new \Todaymade\Daux\Console\Application();
|
||||
$application->run();
|
||||
|
@ -21,7 +21,8 @@
|
||||
"symfony/console": "~3.0",
|
||||
"symfony/finder": "~3.0",
|
||||
"webuni/commonmark-table-extension": "0.4.*",
|
||||
"webuni/front-matter": "^0.2.0"
|
||||
"webuni/front-matter": "^0.2.0",
|
||||
"symfony/process": "^3.1"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
|
53
composer.lock
generated
53
composer.lock
generated
@ -4,8 +4,8 @@
|
||||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"hash": "3f12815cfe3d8c82016da7a7a12021a0",
|
||||
"content-hash": "746afc5f583eddb95134fae836cd66f3",
|
||||
"hash": "1c08a4a8a59aab0bab6eef172eae3a65",
|
||||
"content-hash": "cf6047ce91ccdd654b083807e76e13ac",
|
||||
"packages": [
|
||||
{
|
||||
"name": "guzzlehttp/guzzle",
|
||||
@ -558,6 +558,55 @@
|
||||
],
|
||||
"time": "2016-05-18 14:26:46"
|
||||
},
|
||||
{
|
||||
"name": "symfony/process",
|
||||
"version": "v3.1.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/symfony/process.git",
|
||||
"reference": "5c11a1a4d4016662eeaf0f8757958c7de069f9a0"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/symfony/process/zipball/5c11a1a4d4016662eeaf0f8757958c7de069f9a0",
|
||||
"reference": "5c11a1a4d4016662eeaf0f8757958c7de069f9a0",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=5.5.9"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "3.1-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Symfony\\Component\\Process\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Fabien Potencier",
|
||||
"email": "fabien@symfony.com"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://symfony.com/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Symfony Process Component",
|
||||
"homepage": "https://symfony.com",
|
||||
"time": "2016-06-29 05:42:25"
|
||||
},
|
||||
{
|
||||
"name": "symfony/yaml",
|
||||
"version": "v3.1.2",
|
||||
|
9
generate
9
generate
@ -64,14 +64,7 @@ software, even if advised of the possibility of such damage.
|
||||
|
||||
*/
|
||||
|
||||
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
|
||||
require_once(__DIR__ . '/vendor/autoload.php');
|
||||
} elseif (file_exists('daux.phar')) {
|
||||
define('PHAR_DIR', __DIR__);
|
||||
require_once("phar://" . __DIR__ . "/daux.phar/vendor/autoload.php");
|
||||
} else {
|
||||
throw new Exception("Impossible to load Daux, missing vendor/ or daux.phar");
|
||||
}
|
||||
require_once(__DIR__ . '/libs/bootstrap.php');
|
||||
|
||||
$application = new \Todaymade\Daux\Console\Application();
|
||||
$application->run();
|
||||
|
11
index.php
11
index.php
@ -75,13 +75,6 @@ if (php_sapi_name() === 'cli-server') {
|
||||
$_SERVER['SCRIPT_NAME'] = '/index.php';
|
||||
}
|
||||
|
||||
if (file_exists('vendor/autoload.php')) {
|
||||
require_once 'vendor/autoload.php';
|
||||
} elseif (file_exists('daux.phar')) {
|
||||
define('PHAR_DIR', __DIR__);
|
||||
require_once 'phar://' . __DIR__ . '/daux.phar/vendor/autoload.php';
|
||||
} else {
|
||||
throw new Exception('Impossible to load Daux, missing vendor/ or daux.phar');
|
||||
}
|
||||
require_once(__DIR__ . '/libs/bootstrap.php');
|
||||
|
||||
\Todaymade\Daux\Server\Server::serve($_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], $_REQUEST);
|
||||
\Todaymade\Daux\Server\Server::serve();
|
||||
|
@ -70,6 +70,14 @@ class Config extends ArrayObject
|
||||
return $this['themes_directory'];
|
||||
}
|
||||
|
||||
public function setFormat($format) {
|
||||
$this['format'] = $format;
|
||||
}
|
||||
|
||||
public function getFormat() {
|
||||
return $this['format'];
|
||||
}
|
||||
|
||||
public function isMultilanguage() {
|
||||
return array_key_exists('languages', $this) && !empty($this['languages']);
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
<?php namespace Todaymade\Daux\Console;
|
||||
|
||||
use Symfony\Component\Console\Command\Command as SymfonyCommand;
|
||||
use Symfony\Component\Console\Exception\InvalidOptionException;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Todaymade\Daux\Daux;
|
||||
use Todaymade\Daux\Server\Server;
|
||||
|
||||
class Generate extends SymfonyCommand
|
||||
{
|
||||
@ -15,19 +17,36 @@ class Generate extends SymfonyCommand
|
||||
$this
|
||||
->setName('generate')
|
||||
->setDescription('Generate documentation')
|
||||
|
||||
->addOption('configuration', 'c', InputOption::VALUE_REQUIRED, 'Configuration file')
|
||||
->addOption('source', 's', InputOption::VALUE_REQUIRED, 'Where to take the documentation from')
|
||||
->addOption('format', 'f', InputOption::VALUE_REQUIRED, 'Output format, html or confluence', 'html')
|
||||
->addOption('processor', 'p', InputOption::VALUE_REQUIRED, 'Manipulations on the tree')
|
||||
->addOption('source', 's', InputOption::VALUE_REQUIRED, 'Where to take the documentation from')
|
||||
|
||||
// Serve the current documentation
|
||||
->addOption('serve', null, InputOption::VALUE_NONE, 'Serve the current directory')
|
||||
->addOption('host', null, InputOption::VALUE_REQUIRED, 'The host to serve on', 'localhost')
|
||||
->addOption('port', null, InputOption::VALUE_REQUIRED, 'The port to serve on', 8085)
|
||||
|
||||
|
||||
// Confluence format only
|
||||
->addOption('delete', null, InputOption::VALUE_NONE, 'Delete pages not linked to a documentation page (confluence)')
|
||||
|
||||
// HTML Format only
|
||||
->addOption('destination', 'd', InputOption::VALUE_REQUIRED, $description, 'static')
|
||||
->addOption('search', null, InputOption::VALUE_NONE, 'Generate full text search');
|
||||
->addOption('search', null, InputOption::VALUE_NONE, 'Generate full text search')
|
||||
;
|
||||
}
|
||||
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$daux = $this->prepareDaux($input);
|
||||
|
||||
if ($input->getOption('serve')) {
|
||||
$this->serve($daux, $input);
|
||||
return;
|
||||
}
|
||||
|
||||
$width = $this->getApplication()->getTerminalDimensions()[0];
|
||||
|
||||
// Instiantiate the processor if one is defined
|
||||
@ -40,13 +59,23 @@ class Generate extends SymfonyCommand
|
||||
$daux->getGenerator()->generateAll($input, $output, $width);
|
||||
}
|
||||
|
||||
protected function serve(Daux $daux, InputInterface $input)
|
||||
{
|
||||
// Daux can only serve HTML
|
||||
$daux->getParams()->setFormat('html');
|
||||
|
||||
//TODO :: support configuration and processor
|
||||
|
||||
Server::runServer($daux->getParams(), $input->getOption('host'), $input->getOption('port'));
|
||||
}
|
||||
|
||||
protected function prepareDaux(InputInterface $input)
|
||||
{
|
||||
$daux = new Daux(Daux::STATIC_MODE);
|
||||
|
||||
// Set the format if requested
|
||||
if ($input->getOption('format')) {
|
||||
$daux->getParams()['format'] = $input->getOption('format');
|
||||
$daux->getParams()->setFormat($input->getOption('format'));
|
||||
}
|
||||
|
||||
// Set the source directory
|
||||
|
@ -41,9 +41,6 @@ class Daux
|
||||
/** @var string */
|
||||
private $mode;
|
||||
|
||||
/** @var bool */
|
||||
private $merged_defaults = false;
|
||||
|
||||
/** @var bool */
|
||||
private $merged_tree = false;
|
||||
|
||||
@ -110,9 +107,15 @@ class Daux
|
||||
|
||||
public function normalizeDocumentationPath()
|
||||
{
|
||||
// When running through `daux --serve` we set an environment variable to know where we started from
|
||||
$env = getenv('DAUX_SOURCE');
|
||||
if ($env && is_dir($env)) {
|
||||
return $env;
|
||||
}
|
||||
|
||||
$path = $this->getParams()->getDocumentationDirectory();
|
||||
if (is_dir($path)) {
|
||||
return $path;
|
||||
return getcwd() . '/' . $path;
|
||||
}
|
||||
|
||||
throw new Exception('The Docs directory does not exist. Check the path again : ' . $path);
|
||||
@ -312,7 +315,7 @@ class Daux
|
||||
|
||||
$generators = $this->getGenerators();
|
||||
|
||||
$format = $this->getParams()['format'];
|
||||
$format = $this->getParams()->getFormat();
|
||||
|
||||
if (!array_key_exists($format, $generators)) {
|
||||
throw new \RuntimeException("The format '$format' doesn't exist, did you forget to set your processor ?");
|
||||
|
@ -1,6 +1,9 @@
|
||||
<?php namespace Todaymade\Daux\Server;
|
||||
|
||||
use Symfony\Component\Console\Output\NullOutput;
|
||||
use Symfony\Component\Process\ProcessUtils;
|
||||
use Symfony\Component\Process\PhpExecutableFinder;
|
||||
use Todaymade\Daux\Config;
|
||||
use Todaymade\Daux\Daux;
|
||||
use Todaymade\Daux\DauxHelper;
|
||||
use Todaymade\Daux\Exception;
|
||||
@ -63,6 +66,27 @@ class Server
|
||||
echo $page->getContent();
|
||||
}
|
||||
|
||||
public static function runServer(Config $config, $host, $port) {
|
||||
chdir(__DIR__ . '/../../');
|
||||
|
||||
putenv("DAUX_SOURCE=" . $config->getDocumentationDirectory());
|
||||
|
||||
$base = ProcessUtils::escapeArgument(__DIR__ . '/../../');
|
||||
$binary = ProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false));
|
||||
|
||||
echo "Daux development server started on http://{$host}:{$port}/\n";
|
||||
|
||||
if (defined('HHVM_VERSION')) {
|
||||
if (version_compare(HHVM_VERSION, '3.8.0') >= 0) {
|
||||
passthru("{$binary} -m server -v Server.Type=proxygen -v Server.SourceRoot={$base}/ -v Server.IP={$host} -v Server.Port={$port} -v Server.DefaultDocument=server.php -v Server.ErrorDocument404=server.php");
|
||||
} else {
|
||||
throw new Exception("HHVM's built-in server requires HHVM >= 3.8.0.");
|
||||
}
|
||||
} else {
|
||||
passthru("{$binary} -S {$host}:{$port} {$base}/index.php");
|
||||
}
|
||||
}
|
||||
|
||||
public function __construct(Daux $daux)
|
||||
{
|
||||
$this->daux = $daux;
|
||||
|
19
libs/bootstrap.php
Normal file
19
libs/bootstrap.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
// Loaded in the project itself
|
||||
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
|
||||
return require_once(__DIR__ . '/../vendor/autoload.php');
|
||||
}
|
||||
|
||||
// Loaded as a dependency
|
||||
if (file_exists(__DIR__ . '/../../../../autoload.php')) {
|
||||
return require_once(__DIR__ . '/../../../../autoload.php');
|
||||
}
|
||||
|
||||
// Loaded in the project itself, when vendor isn't installed
|
||||
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");
|
Loading…
Reference in New Issue
Block a user