1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?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 {
- /**
- * Machine name of current building process.
- */
- const BUILD_NAME = 'config_doc';
- /**
- * 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, '', static::BUILD_NAME),
- ])
- )
- ->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, static::BUILD_NAME);
- 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;
- }
- }
|