123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- declare(strict_types = 1);
- namespace Fgm\Drupal\Composer;
- use Symfony\Component\Console\Input\InputArgument;
- use Symfony\Component\Console\Input\InputDefinition;
- use Symfony\Component\Console\Input\InputInterface;
- use Symfony\Component\Console\Output\OutputInterface;
- /**
- * Configure the Hugo-based documentation site for the project.
- *
- * @package Fgm\Drupal\Composer
- */
- class HugoConfigCommand extends BaseBuilderCommand {
- /**
- * The event triggering this command.
- *
- * @var string
- */
- protected $eventName;
- /**
- * Configures the current command.
- */
- public function configure() {
- parent::configure();
- $this->eventName = $this->getName();
- $this
- ->setName('build:config_doc')
- ->setDescription('Step 2 (Optional): configure the documentation site for the current environment.')
- ->setDefinition(
- new InputDefinition([
- new InputArgument(static::ARG_FILE, InputArgument::OPTIONAL),
- ])
- )
- ->setHelp(
- <<<EOT
- The build:config_doc modifies the doc/config.toml file and rebuilds the documentation
- site to account for the changes.
- EOT
- );
- }
- /**
- * Executes the current command.
- *
- * {@inheritDoc}
- */
- public function execute(InputInterface $input, OutputInterface $output): int {
- [$wrapper, $params, $msg, $err] = $this->prepare($input, $output);
- if ($err != 0) {
- $output->writeln($msg);
- return $err;
- }
- $context = [
- 'base_url' => $params['instance']['doc']['base_url'],
- ];
- $destination = "doc/config.toml";
- [$msg, $error] = $this->render($wrapper, $context, $destination);
- if ($error) {
- $output->writeln(sprintf("Failed rendering doc configuration: %s", $msg));
- return 5;
- }
- $cwd = getcwd();
- chdir('doc');
- $err = system("hugo -D", $exit);
- if ($exit != 0) {
- $output->writeln(sprintf("Failed running hugo to rebuild documentation site: %s\n", $err));
- return 6;
- }
- chdir($cwd);
- return 0;
- }
- }
|