Skip to content
35 changes: 35 additions & 0 deletions src/Robo/Plugin/Commands/DevelopmentModeCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,4 +506,39 @@ public function frontendDevDisable($siteDir = 'default', array $opts = ['yes|y'
->remove($this->devServicesPath)
->run();
}

/**
* Setup a site in GitHub Codespaces.
*
* @throws \Robo\Exception\TaskException
*/
public function setupCodespaces()
{
$codespaces_directory = getenv('PWD') . '/web';
Comment thread
walangitan marked this conversation as resolved.
Outdated
if (empty($codespaces_directory)) {
throw new TaskException($this, 'Codespaces directory is unavailable.');
}
$result = $this->taskExec('rm /var/www/html')->run();
Comment thread
walangitan marked this conversation as resolved.
Outdated
$result = $this->taskExec("ln -s $codespaces_directory /var/www/html")->run();

$this->io()->title('Start apache, forwarding port 80.');
$result = $this->taskExec('service apache2 start')->run();

$this->io()->title('Download database.');
$dbPath = $this->databaseDownload();
if (empty($dbPath)) {
throw new TaskException($this, 'Database download failed.');
}

$this->io()->section('Importing database.');
$result = $this->taskExec("zcat $dbPath | mysql -h db -u mariadb -pmariadb mariadb")->run();
$result = $this->taskExec('rm')->args($dbPath)->run();

$this->io()->section('Building theme.');
$result = $this->taskExec('composer robo theme:build')->run();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and the db download line above will work for simple sites, but multi-sites will require some special cases. I am OK with merging this assuming we want to address that in a future update.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can log a ticket about updating this to support multi-sites, as well as some other caveats that may need to be created to support running a multi-site in codespaces.


$this->io()->section('Clearing Drupal cache.');
$result = $this->taskExec('vendor/bin/drush cr')->run();
Comment thread
walangitan marked this conversation as resolved.
Outdated
return $result;
}
}