Commit ea81702e authored by totten's avatar totten

Add `bin/console docs:publish` command

parent af575845
......@@ -59,13 +59,14 @@ class BookLoader
foreach ($this->find() as $bookName => $book) {
foreach ($book['langs'] as $lang => $langSpec) {
foreach ($this->getBranches($book, $lang) as $branch) {
$key = "$bookName/$lang/$branch";
$row = array(
'book' => $bookName,
'lang' => $lang,
'repo' => $langSpec['repo'],
'branch' => $branch,
);
$rows[] = $row;
$rows[$key] = $row;
}
}
}
......
<?php
namespace AppBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class DocsPublishCommand extends ContainerAwareCommand
{
protected function configure()
{
$this
->setName('docs:publish')
->setDescription('...')
->addArgument('paths', InputArgument::IS_ARRAY,
'One or more book expressions ("book/lang/branch"). (Default: all)');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var \AppBundle\BookLoader $books */
$books = $this->getContainer()->get('book.loader');
/** @var \AppBundle\Utils\Publisher $publisher */
$publisher = $this->getContainer()->get('publisher');
$rows = $books->findAsList();
if (empty($rows)) {
$output->writeln("<error>No books found</error>");
}
$rowKeys = $input->getArgument('paths') ? $input->getArgument('paths') : array_keys($rows);
foreach ($rowKeys as $rowKey) {
$row = $rows[$rowKey];
$output->writeln("");
$output->writeln(sprintf("Publish [%s/%s/%s] (from %s)",
$row['book'], $row['lang'], $row['branch'], $row['repo']));
$publisher->publish($row['book'], $row['lang'], $row['branch']);
foreach ($publisher->getMessages() as $message) {
$output->writeln($message['label'] . ': ' . $message['content']);
}
$publisher->clearMessages();
}
}
}
......@@ -11,12 +11,14 @@ use Symfony\Component\HttpFoundation\RequestStack;
class Publisher{
public $bookConfigFile;
public $messages;
public function __construct(RequestStack $requestStack, $logger, $fs, $configDir, $reposRoot, $publishRoot){
$this->configDir = $configDir;
$this->reposRoot = $reposRoot;
$this->publishRoot = $publishRoot;
$this->baseUrl = $requestStack->getCurrentRequest()->getUriForPath('');
$this->baseUrl = $requestStack->getCurrentRequest() ? $requestStack->getCurrentRequest()->getUriForPath('') : '/';
//$this->baseUrl = $requestStack->getCurrentRequest()->$getBaseUrl();
$this->logger = $logger;
$this->fs = $fs;
......@@ -112,7 +114,7 @@ class Publisher{
$publishDir = $this->publishRoot."/{$book}/{$lang}/{$branch}";
$buildCommand = "mkdocs build -c -f {$buildConfigFile} -d {$publishDir}";
$this->addMessage('NOTICE', "Running '{$buildCommand}'");
$mkdocs = new Process($buildCommand, $bookRepo);
$mkdocsErrors = false;
$mkdocs->run();
......@@ -164,9 +166,30 @@ class Publisher{
$this->messages[] = array('label' => $label, 'content' => $content);
$this->logger->addRecord($this->logger->toMonologLevel($label), $content);
}
public function getMessages()
{
return $this->messages;
}
public function clearMessages() {
$this->messages = array();
}
/**
* @return string
*/
public function getBaseUrl()
{
return $this->baseUrl;
}
/**
* @param string $baseUrl
*/
public function setBaseUrl($baseUrl)
{
$this->baseUrl = $baseUrl;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment